001: package com.xoetrope.editor.eclipse;
002:
003: import net.xoetrope.editor.project.XEditorProjectManager;
004:
005: import org.eclipse.core.resources.IStorage;
006: import org.eclipse.jface.action.IAction;
007: import org.eclipse.jface.viewers.ISelection;
008: import org.eclipse.ui.IEditorPart;
009: import org.eclipse.ui.IStorageEditorInput;
010: import org.eclipse.ui.IWorkbenchPage;
011: import org.eclipse.ui.IWorkbenchWindow;
012: import org.eclipse.ui.IWorkbenchWindowActionDelegate;
013: import org.eclipse.ui.PlatformUI;
014:
015: import com.xoetrope.editor.eclipse.langed.LanguageEditor;
016:
017: /**
018: * Our sample action implements workbench action delegate. The action proxy will
019: * be created by the workbench and shown in the UI. When the user tries to use
020: * the action, this delegate will be created and execution will be delegated to
021: * it.
022: *
023: * @see IWorkbenchWindowActionDelegate
024: */
025: public class XuiProShowLanguageEditorAction implements
026: IWorkbenchWindowActionDelegate {
027: /**
028: * The constructor.
029: */
030: public XuiProShowLanguageEditorAction() {
031: }
032:
033: /**
034: * The action has been activated. The argument of the method represents the
035: * 'real' action sitting in the workbench UI.
036: *
037: * @see IWorkbenchWindowActionDelegate#run
038: */
039:
040: public void run(IAction action) {
041: showEditor();
042: }
043:
044: protected LanguageEditor showEditor() {
045: LanguageEditor editor = null;
046: try {
047: IWorkbenchWindow window = PlatformUI.getWorkbench()
048: .getActiveWorkbenchWindow();
049: IStorage storage = new XStringStorage("");
050: IStorageEditorInput input = new XStringInput(storage);
051: IWorkbenchPage page = window.getActivePage();
052: if (page != null)
053: editor = (LanguageEditor) page
054: .openEditor(input,
055: "com.xoetrope.editor.eclipse.langed.LanguageEditor");
056: } catch (Exception ex) {
057: editor = null;
058: ex.printStackTrace();
059: }
060: return editor;
061: }
062:
063: protected LanguageEditor getLanguageEditor() {
064: IWorkbenchWindow window = PlatformUI.getWorkbench()
065: .getActiveWorkbenchWindow();
066: IWorkbenchPage page = window.getActivePage();
067: IEditorPart editorPart = page.getActiveEditor();
068: return (editorPart instanceof LanguageEditor ? (LanguageEditor) editorPart
069: : null);
070: }
071:
072: /**
073: * Selection in the workbench has been changed. We can change the state of the
074: * 'real' action here if we want, but this can only happen after the delegate
075: * has been created.
076: *
077: * @see IWorkbenchWindowActionDelegate#selectionChanged
078: */
079: public void selectionChanged(IAction action, ISelection selection) {
080: action.setEnabled(XEditorProjectManager
081: .isUserRegistered("XUI Pro")
082: && (XEditorProjectManager.getNumProjects() > 0));
083: }
084:
085: /**
086: * We can use this method to dispose of any system resources we previously
087: * allocated.
088: *
089: * @see IWorkbenchWindowActionDelegate#dispose
090: */
091: public void dispose() {
092: }
093:
094: /**
095: * We will cache window object in order to be able to provide parent shell for
096: * the message dialog.
097: *
098: * @see IWorkbenchWindowActionDelegate#init
099: */
100: public void init(IWorkbenchWindow window) {
101:
102: }
103: }
|