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