Search in sources :

Example 21 with IPageChangedListener

use of org.eclipse.jface.dialogs.IPageChangedListener 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)

Example 22 with IPageChangedListener

use of org.eclipse.jface.dialogs.IPageChangedListener in project reddeer by eclipse.

the class CodeGenHandler method openCodeGen.

/**
 * Method for open RedDeer CodeGen wizard and runs all necessary listeners
 *
 * @param window
 */
private void openCodeGen(IWorkbenchWindow window) {
    log.info("Trying to open CodeGen wizard.");
    Shell[] shell = ShellLookup.getInstance().getShells();
    for (Shell sh : shell) {
        if (sh.getText() == CodeGenWizard.WIZZARD_NAME)
            return;
    }
    INewWizard wizard = new CodeGenWizard();
    WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
    dialog.setMinimumPageSize(150, 350);
    dialog.addPageChangedListener(new IPageChangedListener() {

        @Override
        public void pageChanged(PageChangedEvent event) {
            log.info("Page changed listener was started.");
            Object selected = event.getSelectedPage();
            if (selected instanceof PreviewPage) {
                PreviewPage prev = ((PreviewPage) selected);
                log.debug("Active page -> 'PreviewPage'.");
                dialog.updateButtons();
            } else if (selected instanceof MethodsPage) {
                log.debug("Active page -> 'MethodsPage'.");
            } else if (selected instanceof FirstPage) {
                log.debug("Active page -> 'FirstPage'.");
                ((FirstPage) selected).dialogChanged();
                dialog.updateButtons();
            }
        }
    });
    dialog.addPageChangingListener(new IPageChangingListener() {

        @Override
        public void handlePageChanging(PageChangingEvent event) {
            log.info("Page changing listener was started.");
            Object current = event.getCurrentPage();
            Object target = event.getTargetPage();
            if (current instanceof MethodsPage && target instanceof PreviewPage) {
                log.debug("Switching between 'MethodsPage' -> 'PreviewPage'.");
                MethodsPage meth = ((MethodsPage) current);
                PreviewPage prev = ((PreviewPage) target);
                log.info("Trying to generate code.");
                CodeGenerator g = new CodeGenerator(meth.getClassBuilder().getClassName(), meth.getClassBuilder().getPackageName(), meth.getSelectedOptional());
                log.info("Trying to update text area in 'PreviewPage'.");
                g.setLastActiveShell(lastActiveShell);
                prev.updateAreaContent(g.generateCode());
            }
        }
    });
    log.info("Opening WizardDialog -> " + wizard.getWindowTitle() + "...");
    dialog.open();
}
Also used : FirstPage(org.eclipse.reddeer.codegen.wizards.FirstPage) PreviewPage(org.eclipse.reddeer.codegen.wizards.PreviewPage) PageChangedEvent(org.eclipse.jface.dialogs.PageChangedEvent) IPageChangingListener(org.eclipse.jface.dialogs.IPageChangingListener) CodeGenerator(org.eclipse.reddeer.codegen.CodeGenerator) IPageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener) Shell(org.eclipse.swt.widgets.Shell) MethodsPage(org.eclipse.reddeer.codegen.wizards.MethodsPage) CodeGenWizard(org.eclipse.reddeer.codegen.wizards.CodeGenWizard) PageChangingEvent(org.eclipse.jface.dialogs.PageChangingEvent) WizardDialog(org.eclipse.jface.wizard.WizardDialog) INewWizard(org.eclipse.ui.INewWizard)

Example 23 with IPageChangedListener

use of org.eclipse.jface.dialogs.IPageChangedListener in project org.eclipse.rap by eclipse-rap.

the class PreferenceDialog method firePageChanged.

/**
 * Notifies any selection changed listeners that the selected page
 * has changed.
 * Only listeners registered at the time this method is called are notified.
 *
 * @param event a selection changed event
 *
 * @see IPageChangedListener#pageChanged
 *
 * @since 1.0
 */
protected void firePageChanged(final PageChangedEvent event) {
    Object[] listeners = pageChangedListeners.getListeners();
    for (int i = 0; i < listeners.length; i++) {
        final IPageChangedListener l = (IPageChangedListener) listeners[i];
        SafeRunnable.run(new SafeRunnable() {

            public void run() {
                l.pageChanged(event);
            }
        });
    }
}
Also used : IPageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener) SafeRunnable(org.eclipse.jface.util.SafeRunnable) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) Point(org.eclipse.swt.graphics.Point)

Example 24 with IPageChangedListener

use of org.eclipse.jface.dialogs.IPageChangedListener in project org.eclipse.rap by eclipse-rap.

the class PartListenerList2 method firePageChanged.

public void firePageChanged(final PageChangedEvent event) {
    Object[] array = getListeners();
    for (int i = 0; i < array.length; i++) {
        final IPageChangedListener l;
        if (array[i] instanceof IPageChangedListener) {
            l = (IPageChangedListener) array[i];
        } else {
            continue;
        }
        SafeRunnable.run(new SafeRunnable() {

            public void run() {
                l.pageChanged(event);
            }
        });
    }
}
Also used : IPageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener) SafeRunnable(org.eclipse.jface.util.SafeRunnable)

Example 25 with IPageChangedListener

use of org.eclipse.jface.dialogs.IPageChangedListener in project org.eclipse.rap by eclipse-rap.

the class FormEditor method firePageChanged.

private void firePageChanged(final PageChangedEvent event) {
    Object[] listeners = pageListeners.getListeners();
    for (int i = 0; i < listeners.length; ++i) {
        final IPageChangedListener l = (IPageChangedListener) listeners[i];
        SafeRunnable.run(new SafeRunnable() {

            public void run() {
                l.pageChanged(event);
            }
        });
    }
}
Also used : IPageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener) SafeRunnable(org.eclipse.jface.util.SafeRunnable)

Aggregations

IPageChangedListener (org.eclipse.jface.dialogs.IPageChangedListener)27 PageChangedEvent (org.eclipse.jface.dialogs.PageChangedEvent)15 IPageChangingListener (org.eclipse.jface.dialogs.IPageChangingListener)6 SafeRunnable (org.eclipse.jface.util.SafeRunnable)6 IPageChangeProvider (org.eclipse.jface.dialogs.IPageChangeProvider)5 IWizardContainer (org.eclipse.jface.wizard.IWizardContainer)5 IWizardPage (org.eclipse.jface.wizard.IWizardPage)4 Composite (org.eclipse.swt.widgets.Composite)3 Control (org.eclipse.swt.widgets.Control)3 TreeSet (java.util.TreeSet)2 PageChangingEvent (org.eclipse.jface.dialogs.PageChangingEvent)2 WizardDialog (org.eclipse.jface.wizard.WizardDialog)2 Point (org.eclipse.swt.graphics.Point)2 IWorkbench (org.eclipse.ui.IWorkbench)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 CMWizardDialog (com.cubrid.common.ui.spi.dialog.CMWizardDialog)1