Search in sources :

Example 1 with IPartListener2

use of org.eclipse.ui.IPartListener2 in project org.csstudio.display.builder by kasemir.

the class DataBrowserEditor method createPartControl.

/**
 * Create Plot GUI, connect to model via Controller
 *  {@inheritDoc}
 */
@Override
public void createPartControl(final Composite parent) {
    // Create GUI elements (Plot)
    parent.setLayout(new FillLayout());
    final JFX_SWT_Wrapper wrapper = new JFX_SWT_Wrapper(parent, () -> {
        try {
            plot = new ModelBasedPlot(true);
        } catch (Exception ex) {
            logger.log(Level.WARNING, "Cannot create plot", ex);
        }
        return new Scene(plot.getPlot());
    });
    final Control plot_canvas = wrapper.getFXCanvas();
    final Scene scene = wrapper.getScene();
    JFXCursorFix.apply(scene, parent.getDisplay());
    try {
        hookDragAndDrop(plot_canvas);
    } catch (Throwable ex) {
        // Adding D&D to FXCanvas involves some hacking
        // that might break as SWT internals get updated.
        logger.log(Level.WARNING, "Cannot initialize Drag&Drop", ex);
    }
    // Create and start controller
    controller = new ControllerSWT(parent.getShell(), model, plot);
    try {
        controller.start();
    } catch (Exception ex) {
        ExceptionDetailsErrorDialog.openError(parent.getShell(), Messages.Error, ex);
    }
    // Only the 'page' seems to know if a part is visible or not,
    // so use PartListener to update controller's redraw handling
    getSite().getPage().addPartListener(new IPartListener2() {

        private boolean isThisEditor(final IWorkbenchPartReference part) {
            return part.getPart(false) == DataBrowserEditor.this;
        }

        // Enable redraws...
        @Override
        public void partOpened(final IWorkbenchPartReference part) {
            if (isThisEditor(part))
                controller.suppressRedraws(false);
        }

        @Override
        public void partVisible(final IWorkbenchPartReference part) {
            if (isThisEditor(part))
                controller.suppressRedraws(false);
        }

        // Suppress redraws...
        @Override
        public void partHidden(final IWorkbenchPartReference part) {
            if (isThisEditor(part))
                controller.suppressRedraws(true);
        }

        @Override
        public void partClosed(final IWorkbenchPartReference part) {
            if (isThisEditor(part))
                controller.suppressRedraws(true);
        }

        // Ignore
        @Override
        public void partInputChanged(final IWorkbenchPartReference part) {
        /* NOP */
        }

        @Override
        public void partDeactivated(final IWorkbenchPartReference part) {
        /* NOP */
        }

        @Override
        public void partBroughtToTop(final IWorkbenchPartReference part) {
        /* NOP */
        }

        @Override
        public void partActivated(final IWorkbenchPartReference part) {
        /* NOP */
        }
    });
    toggle_legend = new ToggleLegendAction(plot.getPlot(), true);
    toggle_toolbar = new ToggleToolbarAction(plot.getPlot(), true);
    snapshot = new SnapshotAction(plot.getPlot(), parent.getShell());
    createContextMenu(plot_canvas);
}
Also used : FillLayout(org.eclipse.swt.layout.FillLayout) Scene(javafx.scene.Scene) PartInitException(org.eclipse.ui.PartInitException) IPartListener2(org.eclipse.ui.IPartListener2) ModelBasedPlot(org.csstudio.trends.databrowser3.ui.ModelBasedPlot) Control(org.eclipse.swt.widgets.Control) JFX_SWT_Wrapper(org.csstudio.javafx.swt.JFX_SWT_Wrapper) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference) ControllerSWT(org.csstudio.trends.databrowser3.ui.ControllerSWT)

Example 2 with IPartListener2

use of org.eclipse.ui.IPartListener2 in project mdw-designer by CenturyLinkCloud.

the class ProcessEditor method addActiveScriptEditor.

public void addActiveScriptEditor(final IEditorPart editor) {
    if (!activeScriptEditors.contains(editor)) {
        activeScriptEditors.add(editor);
        editor.getSite().getPage().addPartListener(new IPartListener2() {

            public void partClosed(IWorkbenchPartReference partRef) {
                removeActiveScriptEditor(editor);
            }

            public void partActivated(IWorkbenchPartReference partRef) {
            }

            public void partBroughtToTop(IWorkbenchPartReference partRef) {
            }

            public void partDeactivated(IWorkbenchPartReference partRef) {
            }

            public void partOpened(IWorkbenchPartReference partRef) {
            }

            public void partHidden(IWorkbenchPartReference partRef) {
            }

            public void partVisible(IWorkbenchPartReference partRef) {
            }

            public void partInputChanged(IWorkbenchPartReference partRef) {
            }
        });
    }
}
Also used : IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference) IPartListener2(org.eclipse.ui.IPartListener2)

Example 3 with IPartListener2

use of org.eclipse.ui.IPartListener2 in project org.csstudio.display.builder by kasemir.

the class DataBrowserAwareView method createPartControl.

/**
 * Derived classes use doCreatePartControl,
 *  called by this method, which then hooks into the
 *  part listener which then tracks the current plot editor.
 */
@Override
public final void createPartControl(final Composite parent) {
    doCreatePartControl(parent);
    // Listen to the current 'part', react if it's a PlotEditor
    part_listener = new IPartListener2() {

        // Remember the editor when activated...
        @Override
        public void partActivated(IWorkbenchPartReference ref) {
            if (ref.getId().equals(DataBrowserEditor.ID)) {
                final IWorkbenchPart part = ref.getPart(false);
                if (part instanceof DataBrowserEditor)
                    updateEditor((DataBrowserEditor) part);
            // else: Some other editor of no concern
            }
        }

        // ... until another one gets activated, or the current one closes.
        @Override
        public void partClosed(IWorkbenchPartReference ref) {
            if (ref.getPart(false) == editor) {
                updateEditor(null);
            }
        }

        // All ignored
        @Override
        public void partDeactivated(IWorkbenchPartReference ref) {
        /* NOP */
        }

        @Override
        public void partBroughtToTop(IWorkbenchPartReference ref) {
        /* NOP */
        }

        @Override
        public void partHidden(IWorkbenchPartReference ref) {
        /* NOP */
        }

        @Override
        public void partInputChanged(IWorkbenchPartReference ref) {
        /* NOP */
        }

        @Override
        public void partOpened(IWorkbenchPartReference ref) {
        /* NOP */
        }

        @Override
        public void partVisible(IWorkbenchPartReference ref) {
        /* NOP */
        }
    };
    getSite().getPage().addPartListener(part_listener);
    // If the active editor is already a plot editor,
    // we will never get the 'activate' signal because
    // it already happened.
    // So check once, then use the PartListener
    final IEditorPart current = getSite().getPage().getActiveEditor();
    if (current instanceof DataBrowserEditor)
        updateEditor((DataBrowserEditor) current);
    else
        updateEditor(null);
    // When view is destroyed, we fake a null editor update.
    // Since derived views already handle <code>updateModel</code>
    // with a new <code>null</code> model, this will cause
    // them to unsubscribe etc.
    // Of course they can still add their own dispose listener.
    // 
    // Note:
    // Eclipse performs its own view lifecycle optimization.
    // A view that's "closed" might actually just get hidden,
    // and thus this dispose listener only takes effect when
    // the application closes and really disposes the view.
    // 
    // Unclear why the "Waveform" view gets disposed on close,
    // while the "Config" view is kept around.
    parent.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            getSite().getPage().removePartListener(part_listener);
            updateEditor(null);
        }
    });
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IEditorPart(org.eclipse.ui.IEditorPart) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference) DisposeEvent(org.eclipse.swt.events.DisposeEvent) IPartListener2(org.eclipse.ui.IPartListener2)

Example 4 with IPartListener2

use of org.eclipse.ui.IPartListener2 in project mdw-designer by CenturyLinkCloud.

the class TaskTemplateEditor method init.

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    setSite(site);
    textEditor = new StructuredTextEditor() {

        @Override
        public boolean isEditable() {
            return false;
        }

        @Override
        public boolean isEditorInputModifiable() {
            return false;
        }

        @Override
        public boolean isEditorInputReadOnly() {
            return true;
        }

        @Override
        public boolean isDirty() {
            return false;
        }
    };
    textEditor.setEditorPart(this);
    if (input instanceof FileEditorInput) {
        setInput(input);
        IFile file = ((FileEditorInput) input).getFile();
        WorkflowProject project = WorkflowProjectManager.getInstance().getWorkflowProject(file.getProject());
        // force initialization
        project.getDesignerProxy();
        WorkflowPackage pkg = project.getPackage((IFolder) file.getParent());
        taskTemplate = (TaskTemplate) pkg.getTaskTemplate(file);
        // refresh from file system to make sure we're in sync
        try {
            Long taskId = taskTemplate.getId();
            int version = taskTemplate.getVersion();
            file.refreshLocal(IResource.DEPTH_ZERO, null);
            String content = new String(PluginUtil.readFile(file));
            TaskVO taskVO;
            if (content.trim().startsWith("{")) {
                taskVO = new TaskVO(new JSONObject(content));
            } else {
                TaskTemplateDocument doc = TaskTemplateDocument.Factory.parse(content);
                com.centurylink.mdw.task.TaskTemplate fileTemplate = doc.getTaskTemplate();
                taskVO = new TaskVO(fileTemplate);
            }
            taskTemplate.setTaskVO(taskVO);
            taskVO.setName(file.getName());
            taskVO.setTaskId(taskId);
            taskTemplate.setId(taskId);
            taskTemplate.setVersion(version);
            taskVO.setPackageName(pkg.getName());
        } catch (Exception ex) {
            throw new PartInitException(ex.getMessage(), ex);
        }
    } else {
        throw new PartInitException("Invalid input: " + input);
    }
    selectionProvider = new WorkflowSelectionProvider(taskTemplate);
    site.setSelectionProvider(selectionProvider);
    setPartName(taskTemplate.getName());
    addPageChangedListener(new IPageChangedListener() {

        public void pageChanged(PageChangedEvent event) {
            if (getSelectedPage() == pages.get("Variables")) {
                reconcileVariables();
            }
        }
    });
    partListener = new IPartListener2() {

        public void partOpened(IWorkbenchPartReference partRef) {
        // do nothing
        }

        public void partActivated(IWorkbenchPartReference partRef) {
            IWorkbenchPart part = partRef.getPart(false);
            if (part == TaskTemplateEditor.this && getSelectedPage() == pages.get("Variables"))
                reconcileVariables();
        }

        public void partBroughtToTop(IWorkbenchPartReference partRef) {
        // do nothing
        }

        public void partDeactivated(IWorkbenchPartReference partRef) {
        // do nothing
        }

        public void partClosed(IWorkbenchPartReference partRef) {
        // do nothing
        }

        public void partVisible(IWorkbenchPartReference partRef) {
        // do nothing
        }

        public void partHidden(IWorkbenchPartReference partRef) {
        // do nothing
        }

        public void partInputChanged(IWorkbenchPartReference partRef) {
        // do nothing
        }
    };
    getSite().getPage().addPartListener(partListener);
    workbenchListener = new IWorkbenchListener() {

        public boolean preShutdown(IWorkbench workbench, boolean forced) {
            return MdwPlugin.getActivePage().closeEditor(TaskTemplateEditor.this, true);
        }

        public void postShutdown(IWorkbench workbench) {
        // do nothing
        }
    };
    PlatformUI.getWorkbench().addWorkbenchListener(workbenchListener);
}
Also used : IWorkbenchListener(org.eclipse.ui.IWorkbenchListener) WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) TaskTemplateDocument(com.centurylink.mdw.task.TaskTemplateDocument) IFile(org.eclipse.core.resources.IFile) PageChangedEvent(org.eclipse.jface.dialogs.PageChangedEvent) IPageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) PartInitException(org.eclipse.ui.PartInitException) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference) WorkflowSelectionProvider(com.centurylink.mdw.plugin.designer.WorkflowSelectionProvider) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) JSONException(org.json.JSONException) PartInitException(org.eclipse.ui.PartInitException) IPartListener2(org.eclipse.ui.IPartListener2) IWorkbench(org.eclipse.ui.IWorkbench) JSONObject(org.json.JSONObject) FileEditorInput(org.eclipse.ui.part.FileEditorInput) TaskVO(com.centurylink.mdw.model.value.task.TaskVO)

Aggregations

IPartListener2 (org.eclipse.ui.IPartListener2)4 IWorkbenchPartReference (org.eclipse.ui.IWorkbenchPartReference)4 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)2 PartInitException (org.eclipse.ui.PartInitException)2 TaskVO (com.centurylink.mdw.model.value.task.TaskVO)1 WorkflowSelectionProvider (com.centurylink.mdw.plugin.designer.WorkflowSelectionProvider)1 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)1 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)1 TaskTemplateDocument (com.centurylink.mdw.task.TaskTemplateDocument)1 Scene (javafx.scene.Scene)1 JFX_SWT_Wrapper (org.csstudio.javafx.swt.JFX_SWT_Wrapper)1 ControllerSWT (org.csstudio.trends.databrowser3.ui.ControllerSWT)1 ModelBasedPlot (org.csstudio.trends.databrowser3.ui.ModelBasedPlot)1 IFile (org.eclipse.core.resources.IFile)1 IPageChangedListener (org.eclipse.jface.dialogs.IPageChangedListener)1 PageChangedEvent (org.eclipse.jface.dialogs.PageChangedEvent)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 Control (org.eclipse.swt.widgets.Control)1