Search in sources :

Example 1 with IEditorReference

use of org.eclipse.ui.IEditorReference in project tdi-studio-se by Talend.

the class MavenVersionManagementProjectSettingPage method updateItemsVersion.

protected void updateItemsVersion() {
    List<ItemVersionObject> JobsOpenedInEditor = new ArrayList<ItemVersionObject>();
    List<ItemVersionObject> closedJobs = new ArrayList<ItemVersionObject>();
    boolean hasJobOpenedInEditor = false;
    StringBuilder builder = new StringBuilder();
    for (ItemVersionObject object : checkedObjects) {
        if (RepositoryManager.isOpenedItemInEditor(object.getRepositoryNode().getObject())) {
            hasJobOpenedInEditor = true;
            JobsOpenedInEditor.add(object);
            //$NON-NLS-1$
            builder.append(object.getRepositoryNode().getObject().getLabel() + ", ");
        } else {
            closedJobs.add(object);
        }
    }
    if (builder.length() > 0) {
        builder.delete(builder.length() - 2, builder.length());
    }
    if (hasJobOpenedInEditor) {
        MessageDialog.openWarning(Display.getCurrent().getActiveShell(), //$NON-NLS-1$
        Messages.getString("VersionManagementDialog.WarningTitle2"), //$NON-NLS-1$
        Messages.getString("VersionManagementDialog.openedInEditorMessage", builder.toString()));
        IWorkbenchWindow workBench = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (workBench != null) {
            IWorkbenchPage page = workBench.getActivePage();
            IEditorReference[] editorRefs = page.getEditorReferences();
            if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreUIService.class)) {
                IDesignerCoreUIService service = (IDesignerCoreUIService) GlobalServiceRegister.getDefault().getService(IDesignerCoreUIService.class);
                if (service != null) {
                    for (IEditorReference editorRef : editorRefs) {
                        IEditorPart editor = editorRef.getEditor(false);
                        if (editor instanceof IMultiPageTalendEditor) {
                            IProcess2 process = ((IMultiPageTalendEditor) editor).getProcess();
                            String version = null;
                            for (ItemVersionObject object : JobsOpenedInEditor) {
                                if (object.getItem().getProperty().getId().equals(process.getId())) {
                                    version = object.getNewVersion();
                                    break;
                                }
                            }
                            if (version != null) {
                                String jobDefaultVersion = MavenVersionUtils.getDefaultVersion(process.getProperty().getVersion());
                                if (version.equals(jobDefaultVersion)) {
                                    // if default, set null to remove key from property.
                                    version = null;
                                }
                                Command command = service.crateMavenDeploymentValueChangeCommand(process, MavenConstants.NAME_USER_VERSION, version);
                                if (process instanceof IGEFProcess) {
                                    service.executeCommand((IGEFProcess) process, command);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    final IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        @Override
        public void run(final IProgressMonitor monitor) throws CoreException {
            RepositoryWorkUnit<Object> rwu = new //$NON-NLS-1$
            RepositoryWorkUnit<Object>(//$NON-NLS-1$
            project, //$NON-NLS-1$
            "Update items Maven version") {

                @Override
                protected void run() throws LoginException, PersistenceException {
                    //$NON-NLS-1$
                    monitor.beginTask("Update items Maven version", closedJobs.size());
                    for (ItemVersionObject object : closedJobs) {
                        final Item item = object.getItem();
                        Property itemProperty = item.getProperty();
                        MavenVersionUtils.setItemMavenVersion(itemProperty, object.getNewVersion());
                        monitor.subTask(itemProperty.getLabel());
                        FACTORY.save(project, itemProperty);
                        monitor.worked(1);
                    }
                    try {
                        FACTORY.saveProject(project);
                    } catch (PersistenceException e) {
                        ExceptionHandler.process(e);
                    }
                }
            };
            rwu.setAvoidUnloadResources(true);
            rwu.executeRun();
            monitor.done();
        }
    };
    IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            try {
                ISchedulingRule schedulingRule = workspace.getRoot();
                // the update the project files need to be done in the workspace runnable to avoid all notification
                // of changes before the end of the modifications.
                workspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
            } catch (CoreException e) {
                ExceptionHandler.process(e);
            }
        }
    };
    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
    try {
        dialog.run(false, false, iRunnableWithProgress);
    } catch (InvocationTargetException | InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : ArrayList(java.util.ArrayList) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IMultiPageTalendEditor(org.talend.designer.core.IMultiPageTalendEditor) Item(org.talend.core.model.properties.Item) TableItem(org.eclipse.swt.widgets.TableItem) IEditorReference(org.eclipse.ui.IEditorReference) Property(org.talend.core.model.properties.Property) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IDesignerCoreUIService(org.talend.core.ui.services.IDesignerCoreUIService) IEditorPart(org.eclipse.ui.IEditorPart) InvocationTargetException(java.lang.reflect.InvocationTargetException) IGEFProcess(org.talend.core.ui.process.IGEFProcess) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) Command(org.eclipse.gef.commands.Command) IWorkspace(org.eclipse.core.resources.IWorkspace) IProcess2(org.talend.core.model.process.IProcess2) PersistenceException(org.talend.commons.exception.PersistenceException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ItemVersionObject(org.talend.repository.model.ItemVersionObject) ItemVersionObject(org.talend.repository.model.ItemVersionObject)

Example 2 with IEditorReference

use of org.eclipse.ui.IEditorReference in project tdi-studio-se by Talend.

the class SaveJobBeforeRunAction method run.

public void run() {
    boolean saveMyself = false;
    List<? extends INode> nodes = filterTRunJobNode();
    if (nodes.isEmpty()) {
        return;
    }
    IEditorReference[] references = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
    for (int i = 0; i < references.length; i++) {
        IEditorPart part = references[i].getEditor(false);
        if (!(part instanceof MultiPageTalendEditor)) {
            continue;
        }
        MultiPageTalendEditor editor = (MultiPageTalendEditor) part;
        saveJob(nodes, editor);
    }
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) MultiPageTalendEditor(org.talend.designer.core.ui.MultiPageTalendEditor) IEditorPart(org.eclipse.ui.IEditorPart)

Example 3 with IEditorReference

use of org.eclipse.ui.IEditorReference in project tdi-studio-se by Talend.

the class OpenExistVersionProcessAction method getCorrespondingEditor.

@Override
protected IEditorPart getCorrespondingEditor(IRepositoryNode node) {
    IEditorReference[] eidtors = getActivePage().getEditorReferences();
    for (IEditorReference eidtor : eidtors) {
        try {
            IEditorInput input = eidtor.getEditorInput();
            if (!(input instanceof JobEditorInput)) {
                continue;
            }
            JobEditorInput repositoryInput = (JobEditorInput) input;
            checkUnLoadedNodeForProcess(repositoryInput);
            if (repositoryInput.getItem().equals(node.getObject().getProperty().getItem())) {
                IPath path = repositoryInput.getFile().getLocation();
                return eidtor.getEditor(false);
            }
        } catch (PartInitException e) {
            continue;
        }
    }
    return null;
}
Also used : JobEditorInput(org.talend.core.ui.editor.JobEditorInput) IEditorReference(org.eclipse.ui.IEditorReference) IPath(org.eclipse.core.runtime.IPath) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Example 4 with IEditorReference

use of org.eclipse.ui.IEditorReference in project tesb-studio-se by Talend.

the class RunContainerPreferencePage method performOk.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.designer.esb.runcontainer.preferences.FieldLayoutPreferencePage#performOk()
     */
@Override
public boolean performOk() {
    boolean performOk = super.performOk();
    if (runtimeEnable != getPreferenceStore().getBoolean(RunContainerPreferenceInitializer.P_ESB_IN_OSGI)) {
        IRunProcessService service = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
        if (service != null) {
            service.refreshView();
        }
        List<IEditorReference> editorRefs = new ArrayList();
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IEditorReference[] reference = page.getEditorReferences();
        for (IEditorReference editorRef : reference) {
            IEditorPart part = editorRef.getEditor(false);
            if (part.getEditorInput() instanceof JobEditorInput) {
                editorRefs.add(editorRef);
            }
        }
        if (editorRefs.size() > 0 && MessageDialog.openConfirm(getShell(), "Running Container Changed", "All editors need to be closed to apply the changes, do you want to close all opening editors now?")) {
            page.closeEditors(editorRefs.toArray(new IEditorReference[editorRefs.size()]), true);
        }
    }
    return performOk;
}
Also used : JobEditorInput(org.talend.core.ui.editor.JobEditorInput) IEditorReference(org.eclipse.ui.IEditorReference) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) ArrayList(java.util.ArrayList) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart)

Example 5 with IEditorReference

use of org.eclipse.ui.IEditorReference in project tdi-studio-se by Talend.

the class SQLPatternComposite method resourceChanged.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent
     * )
     */
@Override
public void resourceChanged(IResourceChangeEvent event) {
    boolean needRefresh = false;
    boolean modifySQL = true;
    if (event.getSource() instanceof SQLPatternItem && event.getType() == IResourceChangeEvent.PRE_CLOSE) {
        needRefresh = true;
        modifySQL = false;
        // if still have sql template editor to be opened.
        if (getCurrentOpenedEditors() != null) {
            for (IEditorReference editor : getCurrentOpenedEditors()) {
                ERepositoryObjectType type = null;
                try {
                    type = getCurrentOpenEditorType(editor);
                } catch (PartInitException e) {
                    e.printStackTrace();
                }
                if (type != null && ERepositoryObjectType.SQLPATTERNS.equals(type)) {
                    modifySQL = true;
                }
            }
        }
    }
    if (event.getSource() instanceof SQLPatternItem && event.getType() == IResourceChangeEvent.POST_CHANGE) {
        needRefresh = true;
    }
    if (needRefresh) {
        refreshComboContent(this.tableViewer, modifySQL);
        refresh();
    }
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) PartInitException(org.eclipse.ui.PartInitException) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Aggregations

IEditorReference (org.eclipse.ui.IEditorReference)174 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)83 IEditorPart (org.eclipse.ui.IEditorPart)78 PartInitException (org.eclipse.ui.PartInitException)59 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)55 IFile (org.eclipse.core.resources.IFile)50 IEditorInput (org.eclipse.ui.IEditorInput)49 ArrayList (java.util.ArrayList)34 FileEditorInput (org.eclipse.ui.part.FileEditorInput)28 Item (org.talend.core.model.properties.Item)17 IWorkbench (org.eclipse.ui.IWorkbench)14 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14 PersistenceException (org.talend.commons.exception.PersistenceException)13 IOException (java.io.IOException)12 CoreException (org.eclipse.core.runtime.CoreException)12 ProcessItem (org.talend.core.model.properties.ProcessItem)11 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)10 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)10 Path (org.eclipse.core.runtime.Path)10 IProcess2 (org.talend.core.model.process.IProcess2)10