Java Reference
In-Depth Information
Refactoring the Editor
Back to our EMF-generated
RequirementsEditor
, we see that each page is
created as an anonymous subclass of
ViewerPane
. This causes problems when
trying to integrate our diagram into a page, so we can create an
abstract
RequirementsEditorPart
class to use as a superclass for converting each
page into its own
EditorPart
. Create the new class in the
org.eclipse.
requirements.presentation
package that extends
EditorPart
and imple-
ments
IMenuListener
and
IEditingDomainProvider
as follows:
public abstract class
RequirementsEditorPart
extends
EditorPart
implements
IMenuListener, IEditingDomainProvider {
protected
RequirementsEditor parentEditor;
public
RequirementsEditorPart(RequirementsEditor parent) {
super
();
this
.parentEditor = parent;
}
protected static
String getString(String key) {
return
RequirementsEditorPlugin.INSTANCE.getString(key);
}
public
EditingDomain getEditingDomain() {
return
parentEditor.getEditingDomain();
}
protected
BasicCommandStack getCommandStack() {
return
((BasicCommandStack) getEditingDomain().getCommandStack());
}
protected
AdapterFactory getAdapterFactory() {
return
((AdapterFactoryEditingDomain) ((FileEditorInputProxy)
getEditorInput()).getEditingDomain()).getAdapterFactory();
}
protected void
createContextMenuFor(StructuredViewer viewer) {
MenuManager contextMenu =
new
MenuManager("#PopUp");
contextMenu.add(
new
Separator("additions"));
contextMenu.setRemoveAllWhenShown(
true
);
contextMenu.addMenuListener(
this
);
Menu menu = contextMenu.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
getSite().registerContextMenu(contextMenu,
new
UnwrappingSelectionProvider(viewer));
int
dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
Transfer[] transfers =
new
Transfer[] {
LocalTransfer.getInstance() };
viewer.addDragSupport(dndOperations, transfers,
new
ViewerDragAdapter(viewer));
Search WWH ::
Custom Search