How to handle a property sheet from a custom editor in eclipse plugin development?

I need to bind editor widget objects in a property sheet. So that I can use the property of my widget in the property view. Please help me with this, if possible, will provide me with some code snippets.

+3
source share
1 answer

You have a good example in Getting Started with Properties

Using the Properties view is quite simple.
Since it shows the properties for the selected object, the first step to using it is to make sure that the workplace selection service is aware of the object selected in your view . Theres a full Eclipse Corner article written on the topic of picking services

public void createPartControl(Composite parent) {
    viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    viewer.setContentProvider(new ViewContentProvider());
    viewer.setLabelProvider(new ViewLabelProvider());

    getSite().setSelectionProvider(viewer);

    viewer.setInput(getViewSite());
}

After your view is useful for selecting a workspace, you need to make sure that the objects selected by your view contribute to the properties

(extract)

public class Person implements IPropertySource {
    private String name;
    private Object street;
    private Object city;

    public Person(String name) {
        this.name = name;
        this.street = "";
        this.city = "";
    }

    public Object getEditableValue() {
        return this;
    }

    public IPropertyDescriptor[] getPropertyDescriptors() {
        return new IPropertyDescriptor[] {
                new TextPropertyDescriptor("name", "Name"),
                new TextPropertyDescriptor("street", "Street"),
                new TextPropertyDescriptor("city", "City")
        };
    }

, " [ " ]. , , , ( Eclipse-) ; , , .

- , :
IAdaptable.


. ,

http://3.bp.blogspot.com/_hsp14iFkRLs/Sg28gW12WnI/AAAAAAAADk4/Y_bxy5lHIvI/s320/PinActionRemoved.png

.

isImportant() - , , IPage IWorkbenchPart .
, false workbenchPart, . :

<view
            class="com.eclipse_tips.views.CustomPropertiesView"
            icon="icons/sample.gif"
            id="com.eclipse-tips.views.customePropertiesView"
            name="My Properties View">
</view>

CustomPropertiesView PropertySheet isImportant():

public class CustomPropertiesView extends PropertySheet {

 @Override
 protected boolean isImportant(IWorkbenchPart part) {
  if (part.getSite().getId().equals(IPageLayout.ID_PROJECT_EXPLORER))
   return true;
  return false;
 }
}

Project Explorer

http://2.bp.blogspot.com/_hsp14iFkRLs/Sg28Nwe3QSI/AAAAAAAADko/DqnVd7obB1Y/s320/CustomPropertiesProjectExplore.png


, .

.
, / .
/ , / .
, , , .
, .
, Navigator IResource, IResource, Navigator .

Workbench

ISelectionListener - .
:

private ISelectionListener mylistener = new ISelectionListener() {
    public void selectionChanged(IWorkbenchPart sourcepart, ISelection selection) {
    if (sourcepart != MyView.this &&                               // 1
        selection instanceof IStructuredSelection) {               // 2
        doSomething(((IStructuredSelection) selection).toList());  // 3
        }
    }
};

, -, , , :

  • (, ), . , (1).
  • , (2).
  • (3).

http://www.eclipse.org/articles/Article-WorkbenchSelections/images/diagram1.gif

+10

Source: https://habr.com/ru/post/1723308/


All Articles