📄 abstractgraphicaleditor.java
字号:
(ScalableFreeformRootEditPart)viewer.getRootEditPart();
ConnectionLayer connLayer =
(ConnectionLayer)root.getLayer(LayerConstants.CONNECTION_LAYER);
GraphicalEditPart contentEditPart = (GraphicalEditPart)root.getContents();
viewer.addDropTargetListener(createTransferDropTargetListener());
// ISelectionChangedListener action=(ISelectionChangedListener) getActionRegistry().getAction(ActionFactory.UNDO.getId());
// viewer.addSelectionChangedListener(action);
////////////////////////////////////////////////////////
ISelectionChangedListener action = (ISelectionChangedListener) getActionRegistry().getAction(ActionFactory.COPY.getId());
viewer.addSelectionChangedListener(action);
action=(ISelectionChangedListener) getActionRegistry().getAction(ActionFactory.CUT.getId());
viewer.addSelectionChangedListener(action);
action=(ISelectionChangedListener) getActionRegistry().getAction(ActionFactory.PASTE.getId());
viewer.addSelectionChangedListener(action);
action=(ISelectionChangedListener) getActionRegistry().getAction(Constants.ATTRIBUTE);
viewer.addSelectionChangedListener(action);
action=(ISelectionChangedListener) getActionRegistry().getAction(Constants.OPERAND);
viewer.addSelectionChangedListener(action);
action=(ISelectionChangedListener) getActionRegistry().getAction(Constants.ENTER);
viewer.addSelectionChangedListener(action);
}
/* (non-Javadoc)
* @see org.eclipse.ui.part.EditorPart#setInput(org.eclipse.ui.IEditorInput)
*/
protected void setInput(IEditorInput input) {
super.setInput(input);
IFile file = ((IFileEditorInput) input).getFile();
try{
fModel = create(file);
setPartName(file.getName());
}
catch(CoreException e)
{
e.printStackTrace();
}
}
/**
* 命令栈改变
*/
public void commandStackChanged(EventObject event) {
firePropertyChange(IEditorPart.PROP_DIRTY);
super.commandStackChanged(event);
}
/* (non-Javadoc)
* @see org.eclipse.gef.ui.parts.GraphicalEditorWithFlyoutPalette#createPaletteViewerProvider()
*/
protected PaletteViewerProvider createPaletteViewerProvider() {
paletteViewerProvider = new PaletteViewerProvider(getEditDomain()) {
protected void configurePaletteViewer(PaletteViewer viewer) {
super.configurePaletteViewer(viewer);
// create a drag source listener for this palette viewer
// together with an appropriate transfer drop target listener, this will enable
// model element creation by dragging a CombinatedTemplateCreationEntries
// from the palette into the editor
transferDragSourceListener = new TemplateTransferDragSourceListener(viewer);
viewer.addDragSourceListener(transferDragSourceListener);
}
};
return paletteViewerProvider;
}
/**
* 创建一个接受拖动作的监听器
*/
protected TransferDropTargetListener createTransferDropTargetListener() {
// TODO Auto-generated method stub
return new TemplateTransferDropTargetListener(getGraphicalViewer()) {
protected CreationFactory getFactory(Object template) {
Diagram diagram = (Diagram)getModel();
EClass eClass = diagram.eClass();
String editorType = eClass.getEPackage().getNsPrefix();
return ExtenderReader.getInstance().createModelCreationFactory(getPluginId(),template);
}
};
}
public boolean isDirty() {
return getCommandStack().isDirty();
}
/**
* 创建编辑器action
*/
protected void createActions() {
super.createActions();
IAction action=new AlignmentAction((IWorkbenchPart)this,PositionConstants.LEFT);
getActionRegistry().registerAction(action);
getSelectionActions().add(action.getId());
action=new AlignmentAction((IWorkbenchPart)this,PositionConstants.CENTER);
getActionRegistry().registerAction(action);
getSelectionActions().add(action.getId());
action=new AlignmentAction((IWorkbenchPart)this,PositionConstants.RIGHT);
getActionRegistry().registerAction(action);
getSelectionActions().add(action.getId());
action=new AlignmentAction((IWorkbenchPart)this,PositionConstants.TOP);
getActionRegistry().registerAction(action);
getSelectionActions().add(action.getId());
action=new AlignmentAction((IWorkbenchPart)this,PositionConstants.MIDDLE);
getActionRegistry().registerAction(action);
getSelectionActions().add(action.getId());
action=new AlignmentAction((IWorkbenchPart)this,PositionConstants.BOTTOM);
getActionRegistry().registerAction(action);
getSelectionActions().add(action.getId());
action=new MatchWidthAction((IWorkbenchPart)this);
getActionRegistry().registerAction(action);
getSelectionActions().add(action.getId());
action=new MatchHeightAction((IWorkbenchPart)this);
getActionRegistry().registerAction(action);
getSelectionActions().add(action.getId());
action=new DirectEditAction((IWorkbenchPart)this);
getActionRegistry().registerAction(action);
getSelectionActions().add(action.getId());
action = new DeleteAction((IWorkbenchPart)this);
getActionRegistry().registerAction(action);
getSelectionActions().add(action.getId());
action = new SelectAllAction(this);
getActionRegistry().registerAction(action);
getSelectionActions().add(action.getId());
action = new ShowPropertiesAction(this);
getActionRegistry().registerAction(action);
getSelectionActions().add(action.getId());
action = new UndoAction(this);
getActionRegistry().registerAction(action);
getStackActions().add(action.getId());
action = new RedoAction(this);
getActionRegistry().registerAction(action);
getStackActions().add(action.getId());
////////////////////////////////////////////
action = new CopyNodeAction(this);
getActionRegistry().registerAction(action);
getSelectionActions().add(action.getId());
action = new CutNodeAction(this);
getActionRegistry().registerAction(action);
getSelectionActions().add(action.getId());
action = new PasteNodeAction(this);
getActionRegistry().registerAction(action);
getSelectionActions().add(action.getId());
action = new AttributeAction(this,getAttributeTitle());
getActionRegistry().registerAction(action);
getSelectionActions().add(action.getId());
action = new OperandAction(this,getOperandTitle());
getActionRegistry().registerAction(action);
getSelectionActions().add(action.getId());
action = new EnterAction(this,"");
getActionRegistry().registerAction(action);
getSelectionActions().add(action.getId());
action = new GroupNodeAction(this);
getActionRegistry().registerAction(action);
getSelectionActions().add(action.getId());
action = new UnGroupNodeAction(this);
getActionRegistry().registerAction(action);
getSelectionActions().add(action.getId());
}
protected String getAttributeTitle(){
return "New Attribute";
}
protected String getOperandTitle(){
return "New Operand";
}
/* (non-Javadoc)
* @see org.eclipse.gef.ui.parts.GraphicalEditorWithFlyoutPalette#getPalettePreferences()
*/
protected FlyoutPreferences getPalettePreferences() {
// return DataFlowEditorPaletteFactory.createPalettePreferences();
return createPalettePreferences();
}
private FlyoutPreferences createPalettePreferences() {
flyoutPreferences = new FlyoutPreferences() {
private IPreferenceStore getPreferenceStore() {
return GefUiPlugin.getDefault().getPreferenceStore();
}
public int getDockLocation() {
return getPreferenceStore().getInt(PALETTE_DOCK_LOCATION);
}
public int getPaletteState() {
return getPreferenceStore().getInt(PALETTE_STATE);
}
public int getPaletteWidth() {
return getPreferenceStore().getInt(PALETTE_SIZE);
}
public void setDockLocation(int location) {
getPreferenceStore().setValue(PALETTE_DOCK_LOCATION, location);
}
public void setPaletteState(int state) {
getPreferenceStore().setValue(PALETTE_STATE, state);
}
public void setPaletteWidth(int width) {
getPreferenceStore().setValue(PALETTE_SIZE, width);
}
};
return flyoutPreferences;
}
public void dispose() {
super.dispose();
if(fCommandStack != null){
fCommandStack.dispose();
fCommandStack = null;
}
getGraphicalViewer().removeDragSourceListener(transferDragSourceListener);
transferDragSourceListener = null;
flyoutPreferences = null;
paletteViewerProvider = null;
}
public Object getAdapter(Class type) {
if(type == ActionRegistry.class)
GefUiPlugin.getDefault().setErrorStatusMessage(null);
if (type == IContentOutlinePage.class){
outLinePage = new OutlinePage(this,fEditPartFactory,fContextMenuProvider,fModel);
return outLinePage;
}
// if (type == IContentOverviewPage.class)
// return new ContentOverviewPage(getGraphicalViewer());
if (type == ZoomManager.class)
return getGraphicalViewer().getProperty(ZoomManager.class.toString());
if (type == IPropertySheetPage.class) {
PropertySheetPageEx page = new PropertySheetPageEx();
page.setRootEntry(new PropertySheetEntryEx());
page.setPropertyMenuManager(fPropertyMenuManager);
page.setCommandStack(this.fCommandStack);;
return page;
}
return super.getAdapter(type);
}
/* (non-Javadoc)
* @see org.eclipse.gef.ui.parts.GraphicalEditor#getEditDomain()
*/
public DefaultEditDomain getEditDomain() {
// TODO Auto-generated method stub
return super.getEditDomain();
}
/* (non-Javadoc)
* @see org.eclipse.gef.ui.parts.GraphicalEditor#getSelectionSynchronizer()
*/
public SelectionSynchronizer getSelectionSynchronizer() {
// TODO Auto-generated method stub
return super.getSelectionSynchronizer();
}
public RootEditPart getRootEditPart() {
return getGraphicalViewer().getRootEditPart();
}
/* (non-Javadoc)
* @see org.eclipse.gef.ui.parts.GraphicalEditor#getActionRegistry()
*/
public ActionRegistry getActionRegistry() {
// TODO Auto-generated method stub
return super.getActionRegistry();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -