Visual View for Schema Based Editor

Starting from yesterday's blog entry, make the following change in the DataObject's constructor:

registerEditor("text/x-sample+xml", true);

I.e., the MultiDataObject.registerEditor method turns the editor into a multiview component.

Now, again, within the DataObject, add the following, to register a source editor in the multiview component:

@MultiViewElement.Registration(
        displayName = "#LBL_Sample_Source",
        mimeType = "text/x-sample+xml",
        persistenceType = TopComponent.PERSISTENCE_NEVER,
        preferredID = "ShipOrderSourceView",
        position = 1000)
@NbBundle.Messages({
    "LBL_Sample_Source=Source"
})
public static MultiViewElement createEditor(Lookup lkp){
    return new MultiViewEditorElement(lkp);
}

Result:


Next, let's create a visual editor in the multiview component. This could be within the same module as the above or within a completely separate module. That makes it possible for external contributors to provide modules with new editors in an existing multiview component:

@MultiViewElement.Registration(displayName = "#LBL_Sample_Visual",
    mimeType = "text/x-sample+xml",
    persistenceType = TopComponent.PERSISTENCE_NEVER,
    preferredID = "VisualEditorComponent",
    position = 500)
@NbBundle.Messages({
    "LBL_Sample_Visual=Visual"
})
public class VisualEditorComponent extends JPanel implements MultiViewElement {

    public VisualEditorComponent() {
        initComponents();
    }
 
    @Override
    public String getName() {
        return "VisualEditorComponent";
    }
 
    @Override
    public JComponent getVisualRepresentation() {
        return this;
    }

    @Override
    public JComponent getToolbarRepresentation() {
        return new JToolBar();
    }

    @Override
    public Action[] getActions() {
        return new Action[0];
    }

    @Override
    public Lookup getLookup() {
        return Lookup.EMPTY;
    }

    @Override
    public void componentOpened() {
    }

    @Override
    public void componentClosed() {
    }

    @Override
    public void componentShowing() {
    }

    @Override
    public void componentHidden() {
    }

    @Override
    public void componentActivated() {
    }

    @Override
    public void componentDeactivated() {
    }

    @Override
    public UndoRedo getUndoRedo() {
        return UndoRedo.NONE;
    }

    @Override
    public void setMultiViewCallback(MultiViewElementCallback callback) {
    }

    @Override
    public CloseOperationState canCloseElement() {
        return CloseOperationState.STATE_OK;
    }

} 

Result:


Next, the DataObject is automatically returned from the Lookup of DataObject. Therefore, you can go back to your visual editor, add a LookupListener, listen for DataObjects, parse the underlying XML file, and display values in GUI components within the visual editor.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today