下面列出了怎么用org.eclipse.ui.part.EditorPart的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* if the active editor is the DOT Editor, update the graph, otherwise
* do nothing
*/
private void checkActiveEditorAndUpdateGraph(IWorkbenchPart part) {
if (DotEditorUtils.isDotEditor(part)) {
IEditorInput editorInput = ((EditorPart) part).getEditorInput();
if (editorInput instanceof FileEditorInput) {
IFile file = ((FileEditorInput) editorInput).getFile();
try {
File resolvedFile = DotFileUtils
.resolve(file.getLocationURI().toURL());
if (!resolvedFile.equals(currentFile)) {
updateGraph(resolvedFile);
}
} catch (MalformedURLException e) {
DotActivatorEx.logError(e);
}
}
}
}
/**
* This method will get the DesignerProject for the current XPage and return it.
* @param compEditor
* @return
*/
private DesignerProject getDesignerProjectForEditor(CompositeEditor compEditor){
IWorkbenchPart part = super.getWorkBenchPart();
if(part instanceof EditorPart){
EditorPart editor = (EditorPart)part;
IEditorInput input = editor.getEditorInput();
if(input instanceof IFileEditorInput){
IFileEditorInput fileInput = (IFileEditorInput)input;
IFile xpageFile = fileInput.getFile();
if(null != xpageFile){
IProject project = xpageFile.getProject();
if(null != project){
DesignerProject designerProj = DesignerResource.getDesignerProject(project);
if(null != designerProj){
return designerProj;
}
}
}
}
}
return null;
}
/**
* if the active editor is the DOT Editor, export the graph, otherwise do
* nothing
*/
private void checkActiveEditorAndExportGraph(IWorkbenchPart part) {
if (DotEditorUtils.isDotEditor(part)) {
IEditorInput editorInput = ((EditorPart) part).getEditorInput();
if (editorInput instanceof FileEditorInput) {
IFile file = ((FileEditorInput) editorInput).getFile();
exportGraph(file);
}
}
}
public void initRetargetActions(final EditorPart newEditor) {
final Iterator iter = getActionRegistry().getActions();
while (iter.hasNext()) {
final IAction action = (IAction) iter.next();
if (action instanceof RetargetAction) {
((RetargetAction) action).partActivated(newEditor);
}
}
}
/**
*
* @see org.eclipse.ui.part.EditorPart#doSaveAs()
*/
public void doSaveAs() {
/* First, check if the tree has no structural errors. */
if (!checkTree()) {
StandardDialogs.errorDialog("Tree not saved",
"Errors were detected while validating the tree");
return;
}
SaveBTAsAction action = new SaveBTAsAction(this.tree, this.getEditorInput().getName());
try {
action.run();
if (action.getSelectedFile() != null) {
BTEditorInput editorInput = (BTEditorInput) getEditorInput();
editorInput.setTreeName(action.getSelectedFile());
this.dirty = false;
setIsFromFile(true);
/*
* If the tree comes from a guard, it must be dissociated from
* its original tree. From then on, this BTEditor will be
* managed as a normal BTEditor.
*/
if (isFromGuard()) {
dissociateFromParentTree();
}
setPartName(editorInput.getName());
firePropertyChange(EditorPart.PROP_DIRTY);
firePropertyChange(PROP_TITLE);
}
} catch (Exception e) {
StandardDialogs.exceptionDialog("Error saving the tree",
"There was an error when saving the tree", e);
}
}
public SaveAsRoutesAction(EditorPart editorPart) {
this.editorPart = editorPart;
}
/**
*
* @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
*/
public void doSave(IProgressMonitor monitor) {
/* First, check if the tree has no structural errors. */
if (!checkTree()) {
StandardDialogs.errorDialog("Tree not saved",
"Errors were detected while validating the tree");
monitor.setCanceled(true);
return;
}
/*
* The save the tree.
*/
try {
if (this.isFromFile()) {
/* If the tree comes from a file, save the tree into a file. */
new SaveBTAction(this.tree, ((BTEditorInput) getEditorInput()).getTreeName()).run();
this.dirty = false;
firePropertyChange(EditorPart.PROP_DIRTY);
} else if (this.isFromGuard()) {
/*
* If the tree comes from a guard, then set the tree as a guard
* of the "this.guardNode". Note that we set a clone of the
* guard, not the original one. By doing so, the guard of the
* original node will not be modified even if this editor's tree
* is modified.
*/
BTNode guard = this.tree.getRoot().getChildren().get(0);
if (guard != null) {
this.guardNode.setGuard(guard.clone());
this.guardTree.fireTreeChanged(this);
BTEditorInput editorInput = (BTEditorInput) this.getEditorInput();
Utilities.getBTEditor(Long.parseLong(editorInput.getTreeName().split(
File.pathSeparator)[0])).viewer.refresh();
}
this.dirty = false;
firePropertyChange(EditorPart.PROP_DIRTY);
} else {
/* Otherwise, do a save as. */
doSaveAs();
}
} catch (Exception e) {
StandardDialogs.exceptionDialog("Tree not saved",
"Errors were detected while saving the tree", e);
monitor.setCanceled(true);
}
}
/**
*
* @see jbt.tools.bteditor.event.ITreeModifierListener#treeModified(jbt.tools.bteditor.event.TreeModifiedEvent)
*/
public void treeModified(TreeModifiedEvent event) {
this.dirty = true;
firePropertyChange(EditorPart.PROP_DIRTY);
}
/**
* Activates an editor.
*
* @param editor
* the editor to activate.
*/
public static void activateEditor(EditorPart editor) {
IWorkbenchPage page = editor.getSite().getPage();
page.activate(editor);
}