L0043 - Interfacing to Eclipse Standard Views


Published on

Eclipse contains a large number of standard views that can be extended to support new languages or data models. This model focus on the interface to the most common Eclipse views: Problems View, Outline View, and the Properties View.

Published in: Education, Technology, Sports
1 Comment
  • Thanks. Pity you couldn't make it to any DemoCamp Copenhagen this time. I would have loved to contribute, but at least current client has a bit too much administration it would have required for that, and generally the company tries to cut costs... If you're in Copenhagen maybe we could still have a chat some time.
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Now it’s time for the lab.\n
  • \n
  • \n
  • \n
  • Now it’s time for the lab.\n
  • \n
  • ColumnLabelProviders – as described in module L0011 “Contributing to the Eclipse User Interface” – can be used. (3.3 edition)\n
  • \n
  • Now it’s time for the lab.\n
  • \n
  • L0043 - Interfacing to Eclipse Standard Views

    1. 1. Interfacing to Eclipse Standard ViewsEclipse contains a large number of standard views that can be extendedto support new languages or data models. This model focus on theinterface to the most common Eclipse views: Problems View, OutlineView, and the Properties View.Redistribution and other use of this material requires written permission from The RCP Company.L0001 - 2010-11-27
    2. 2. Problems ViewThe problems view is used to show resource markers, which can representanything(!), but normally are error conditionsMarkers are installed on resources (IResource)  The file of an editor is found via the editor input (IEditorInput) via adaption IFile res = (IFile)editor.getEditorInput().getAdapter(IFile.class);  This only works for files in the workspace – not files opened via “File”→”Open File…” – for the later the above construct returns null2 L0001 - 2010-11-27
    3. 3. Markers (IMarker)Markers are associated as detail data on resources (IResource)Markers have a type, an unique ID (per resource) and a set of text attributesNew marker types are defined with the org.eclipse.core.resources.markers extension point  Each marker type has a name, a set of super-marker-types, a persistence and a set of attributes  The resulting new marker type will inherit all attributes from super-markertypesOnly persistent markers are saved between invocations  A new marker type is non-persistent unless explicitly setBasic marker types related to problems  org.eclipse.core.resources.problemmarker – with attributes severity, message, and location  org.eclipse.core.resources.textmarker – with attributes charStart, charEnd, lineNumberAll relevant marker related constants are defined in IMarkerMakers can be grouped in the Problems View via support in theorg.eclipse.ui.ide.markerSupport extension point3 L0001 - 2010-11-27
    4. 4. Creating a new Marker TypeThe extension for a new marker type is special  The id of the new marker type is specified directly in the extension and not in a sub-element (like for views and perspectives)  If no id is specified, the target Eclipse cannot start!!! <extension id="problem" name=“My Personal Problem" point="org.eclipse.core.resources.markers"> <super type="org.eclipse.core.resources.problemmarker" /> </extension>4 L0001 - 2010-11-27
    5. 5. Markers ManipulationMarkers are accessed using methods of IResource  createMarker(type) – creates and returns a new marker of the specified type  findMarker(id) – find a specific marker  deleteMarkers(type, includeSubtypes, depth) – deletes all markers of the specified type  …and many more…Markers also has a large set of methods  delete() – deletes the marker  getType() – returns the type  getAttribute(name) – returns the value of the attribute  setAttribute(name, value) – sets the value of the attribute  setAttributes(String[] attributeNames, Object[] values) – sets the values of many attributes5 L0001 - 2010-11-27
    6. 6. Working with MarkersTo create a “problem” marker for a complete file, just use the following try { IFile file = myEditor.getFile(); IMarker marker = file.createMarker(IMarker.PROBLEM); marker.setAttribute(IMarker.MESSAGE, "hello"); } catch (CoreException e) { e.printStackTrace(); }6 L0001 - 2010-11-27
    7. 7. Lab ExerciseAdd a new marker type for your problems  Use problemmarker and textmarker as super-typesCreate markers for all errors at the end of each parse  Remember to delete old markersDo they show up in the problems view?Do you see annotations and squibbles in the editor?7 L0001 - 2010-11-27
    8. 8. Outline ViewThe Outline view shows an outline of domain model of the current editor  Requires a domain model has been built  Has dependency on org.eclipse.ui.viewsThe content of the outline view is supplied by the active editor via adaptionto IContentOutlinePage  Result should inherit from ContentOutlinePage  Cache returned object as this method is called often private IContentOutlinePage myContentOutlinePage = null; @Override public Object getAdapter(Class adapter) { if (adapter == IContentOutlinePage.class) { if (myContentOutlinePage == null) { myContentOutlinePage = new NINEditorOutlinePage(this); } return myContentOutlinePage; } return super.getAdapter(adapter); }8 L0001 - 2010-11-27
    9. 9. Outline of Outline Pagepublic class NINEditorOutlinePage extends ContentOutlinePage { @Override public void createControl(Composite parent) { super.createControl(parent); final TreeViewer tree = getTreeViewer(); tree.setLabelProvider(new MyLabelProvider()); tree.setContentProvider(new MyContentProvider()); tree.setInput(new Object()); // Add listener on model, so tree can be refreshed when model is updated } private class MyLabelProvider extends LabelProvider { … } private class MyContentProvider implements ITreeContentProvider { … }}9 L0001 - 2010-11-27
    10. 10. Outline View Extras To get popup menu  Just install it in the tree – remember to register it To synchronize view with editor navigation  Add navigation tracker in the editor and let the view listen To synchronize editor with selection in view  Add selection listener in editor  If current selection is a domain object of the editor, move to that position  Use ITextViewer.revealRange(int offset, int length) To add filtering and sorting to view  Extend ContentOutlinePage.setActionBars(IActionBars)10 L0001 - 2010-11-27
    11. 11. Lab Exercise Extend editor with support for outline view Synchronize the editor with the current selection in the view11 L0001 - 2010-11-27
    12. 12. Properties View The Properties view shows properties of the current selection  Requires a domain model as been built in editor  Has dependency on org.eclipse.ui.views A property source (IPropertySource) describes how the property view should show the properties of an object The content of the property view is supplied by the current selection via inheritance from or adaption to IPropertySource  Inherits from IPropertySource  Implements IAdaptable.getAdapter(IPropertySource.class)  Can be accomplished via adapter factory12 L0001 - 2010-11-27
    13. 13. Implementation of Property Sources (IPropertySource) A property source describes the supported properties using descriptors (IPropertyDescriptor)  A descriptor includes information about  name, description, help  optionally a label provider, how to create a property editor  If it can create a property editor, it is settable  The platform includes a number of standard descriptors  PropertyDescriptor – read-only property  TextPropertyDescriptor – text based property  ColorPropertyDescriptor – color property  ComboBoxPropertyDescriptor – list based property A property source can get and possibly set and reset property values13 L0001 - 2010-11-27
    14. 14. Interesting Parts of Property Sourcepublic class ExPropertySource implements IPropertySource { … myObject; public IPropertyDescriptor[] getPropertyDescriptors() { return IPropertyDescriptor[] = { new TextPropertyDescriptor("name", "name") }; } public Object getPropertyValue(Object id) { if ("name".equals(id)) { return myObject.getName(); } else { return null; } } public void setPropertyValue(Object id, Object value) { if ("name".equals(id)) { myObject.setName((String) value); } }}14 L0001 - 2010-11-27
    15. 15. Lab Exercise Extend editor with support for properties view Add support for setting the name in the domain model  Use IDocument.replace(offset, length, text)15 L0001 - 2010-11-27
    16. 16. More Information “Mark My Words: Using markers to tell users about problems and tasks”  http://www.eclipse.org/resources/resource.php?id=237  Somewhat basic article on markers “Take control of your properties”  http://www.eclipse.org/resources/resource.php?id=214  Good introduction with plenty of code examples “The Eclipse Tabbed Properties View”  http://www.eclipse.org/resources/resource.php?id=138  Introduction to the new tabbed properties view16 L0001 - 2010-11-27