Search in sources :

Example 61 with IEditorPart

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

the class OpenAnotherVersionResourceAction method doRun.

@Override
protected void doRun() {
    final IRepositoryNode node = (RepositoryNode) ((IStructuredSelection) getSelection()).getFirstElement();
    IPath path = RepositoryNodeUtilities.getPath(node);
    String originalName = node.getObject().getLabel();
    RepositoryObject repositoryObj = new RepositoryObject(node.getObject().getProperty());
    repositoryObj.setRepositoryNode(node.getObject().getRepositoryNode());
    OpenAnotherVersionResrouceWizard wizard = new OpenAnotherVersionResrouceWizard(repositoryObj);
    WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);
    dialog.setPageSize(300, 250);
    //$NON-NLS-1$
    dialog.setTitle("Open another version");
    if (dialog.open() == Dialog.OK) {
        refresh(node);
        // refresh the corresponding editor's name
        IEditorPart part = getCorrespondingEditor(node);
        if (part != null && part instanceof IUIRefresher) {
            ((IUIRefresher) part).refreshName();
        } else {
            processRoutineRenameOperation(originalName, node, path);
        }
    }
}
Also used : IRepositoryNode(org.talend.repository.model.IRepositoryNode) IPath(org.eclipse.core.runtime.IPath) RepositoryObject(org.talend.core.model.repository.RepositoryObject) OpenAnotherVersionResrouceWizard(org.talend.designer.camel.resource.ui.wizards.OpenAnotherVersionResrouceWizard) IEditorPart(org.eclipse.ui.IEditorPart) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IUIRefresher(org.talend.core.services.IUIRefresher)

Example 62 with IEditorPart

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

the class CreateNewJobAction method createNewProcess.

private boolean createNewProcess(RepositoryNode nodeOperation, final ProcessItem process) {
    if (process == null) {
        return false;
    }
    try {
        // Set readonly to false since created job will always be editable.
        ProcessEditorInput fileEditorInput = new ProcessEditorInput(process, false, true, false);
        IRepositoryNode repositoryNode = RepositorySeekerManager.getInstance().searchRepoViewNode(fileEditorInput.getItem().getProperty().getId());
        fileEditorInput.setRepositoryNode(repositoryNode);
        IEditorPart openEditor = getActivePage().openEditor(fileEditorInput, MultiPageTalendEditor.ID, true);
        CommandStack commandStack = (CommandStack) openEditor.getAdapter(CommandStack.class);
        final Node nodeProviderRequest = new Node(ComponentsFactoryProvider.getInstance().get(T_ESB_PROVIDER_REQUEST, ComponentCategory.CATEGORY_4_DI.getName()), fileEditorInput.getLoadedProcess());
        final RepositoryNode portNode = nodeOperation.getParent();
        ServiceItem serviceItem = (ServiceItem) portNode.getParent().getObject().getProperty().getItem();
        IFile wsdlPath = WSDLUtils.getWsdlFile(serviceItem);
        Map<String, String> serviceParameters = WSDLUtils.getServiceOperationParameters(wsdlPath, ((OperationRepositoryObject) nodeOperation.getObject()).getName(), portNode.getObject().getLabel());
        setProviderRequestComponentConfiguration(nodeProviderRequest, serviceParameters);
        CreateNodeContainerCommand cNcc = new CreateNodeContainerCommand(fileEditorInput.getLoadedProcess(), new NodeContainer(nodeProviderRequest), new Point(3 * Node.DEFAULT_SIZE, 4 * Node.DEFAULT_SIZE));
        commandStack.execute(cNcc);
        if (!WSDLUtils.ONE_WAY.equals(serviceParameters.get(WSDLUtils.COMMUNICATION_STYLE))) {
            Node node = new Node(ComponentsFactoryProvider.getInstance().get(T_ESB_PROVIDER_RESPONSE, ComponentCategory.CATEGORY_4_DI.getName()), fileEditorInput.getLoadedProcess());
            cNcc = new CreateNodeContainerCommand(fileEditorInput.getLoadedProcess(), new NodeContainer(node), new Point(9 * Node.DEFAULT_SIZE, 4 * Node.DEFAULT_SIZE));
            commandStack.execute(cNcc);
        }
        String faults = serviceParameters.get(WSDLUtils.FAULTS);
        if (null != faults) {
            int horMultiplier = 15;
            for (String fault : faults.split(",")) {
                Node node = new Node(ComponentsFactoryProvider.getInstance().get(T_ESB_PROVIDER_FAULT, ComponentCategory.CATEGORY_4_DI.getName()), fileEditorInput.getLoadedProcess());
                cNcc = new CreateNodeContainerCommand(fileEditorInput.getLoadedProcess(), new NodeContainer(node), new Point(horMultiplier * Node.DEFAULT_SIZE, 4 * Node.DEFAULT_SIZE));
                commandStack.execute(cNcc);
                //$NON-NLS-1$
                node.getElementParameter("ESB_FAULT_TITLE").setValue('\"' + fault + '\"');
                horMultiplier += 6;
            }
        }
        ServiceConnection serviceConnection = (ServiceConnection) serviceItem.getConnection();
        final String parentPortName = portNode.getObject().getLabel();
        for (ServicePort port : serviceConnection.getServicePort()) {
            if (port.getName().equals(parentPortName)) {
                for (ServiceOperation operation : port.getServiceOperation()) {
                    if (operation.getLabel().equals(nodeOperation.getObject().getLabel())) {
                        String jobName = process.getProperty().getLabel();
                        String jobID = process.getProperty().getId();
                        operation.setReferenceJobId(jobID);
                        operation.setLabel(operation.getName() + "-" + jobName);
                        break;
                    }
                }
                break;
            }
        }
        repositoryChange(nodeOperation, nodeProviderRequest);
        ProxyRepositoryFactory.getInstance().save(serviceItem);
        return true;
    } catch (PartInitException e) {
        ExceptionHandler.process(e);
    } catch (PersistenceException e) {
        MessageBoxExceptionHandler.process(e);
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return false;
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ServicePort(org.talend.repository.services.model.services.ServicePort) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) IFile(org.eclipse.core.resources.IFile) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) IEditorPart(org.eclipse.ui.IEditorPart) Point(org.eclipse.draw2d.geometry.Point) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Point(org.eclipse.draw2d.geometry.Point) PartInitException(org.eclipse.ui.PartInitException) PersistenceException(org.talend.commons.exception.PersistenceException) ProcessEditorInput(org.talend.designer.core.ui.editor.ProcessEditorInput) CreateNodeContainerCommand(org.talend.designer.core.ui.editor.cmd.CreateNodeContainerCommand) PersistenceException(org.talend.commons.exception.PersistenceException) ServiceItem(org.talend.repository.services.model.services.ServiceItem) PartInitException(org.eclipse.ui.PartInitException)

Example 63 with IEditorPart

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

the class ResourceEditorListener method partClosed.

@Override
public void partClosed(IWorkbenchPartReference partRef) {
    IWorkbenchPart part = partRef.getPart(true);
    if (part instanceof IEditorPart) {
        IEditorInput input = ((IEditorPart) part).getEditorInput();
        if (input instanceof RouteResourceInput) {
            Item item = ((RouteResourceInput) input).getItem();
            if (item.getProperty().getId().equals(editorInput.getItem().getProperty().getId())) {
                try {
                    ProxyRepositoryFactory.getInstance().unlock(item);
                    page.getWorkbenchWindow().getPartService().removePartListener(this);
                    IResourceChangeListener l = editorInput.getListener();
                    if (null != l) {
                        ResourcesPlugin.getWorkspace().removeResourceChangeListener(l);
                    }
                } catch (Exception e) {
                    ExceptionHandler.process(e);
                }
            }
        }
    }
}
Also used : RouteResourceInput(org.talend.designer.camel.resource.editors.input.RouteResourceInput) Item(org.talend.core.model.properties.Item) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IEditorPart(org.eclipse.ui.IEditorPart) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) IEditorInput(org.eclipse.ui.IEditorInput)

Example 64 with IEditorPart

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

the class OpenOnSelectionHelper method openEditor.

@Override
protected void openEditor(String resource, String spec) {
    //$NON-NLS-1$
    String pattern = "platform:/resource";
    IWorkbenchPage workbenchPage = WSDLEditorPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorPart editorPart = workbenchPage.getActiveEditor();
    String currentEditorId = editorPart.getEditorSite().getId();
    if (resource != null && resource.startsWith(pattern)) {
        Path path = new Path(resource.substring(pattern.length()));
        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
        if (editorPart.getEditorInput() instanceof IFileEditorInput && ((IFileEditorInput) editorPart.getEditorInput()).getFile().equals(file)) {
            workbenchPage.getNavigationHistory().markLocation(editorPart);
        } else {
            try {
                Item item = ((ServiceEditorInput) editorPart.getEditorInput()).getItem();
                // TODO: Use content type as below
                if (resource.endsWith("xsd")) {
                    //$NON-NLS-1$
                    editorPart = workbenchPage.openEditor(new ServiceEditorInput(file, item), WSDLEditorPlugin.XSD_EDITOR_ID);
                } else {
                    // Since we are already in the wsdleditor
                    editorPart = workbenchPage.openEditor(new ServiceEditorInput(file, item), editorPart.getEditorSite().getId());
                }
            } catch (PartInitException initEx) {
                ExceptionHandler.process(initEx);
            }
        }
        try {
            Class<? extends IEditorPart> theClass = editorPart.getClass();
            Class<?>[] methodArgs = { String.class };
            //$NON-NLS-1$
            Method method = theClass.getMethod("openOnSelection", methodArgs);
            Object[] args = { spec };
            method.invoke(editorPart, args);
            workbenchPage.getNavigationHistory().markLocation(editorPart);
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
    } else if (resource != null && resource.startsWith("http")) {
        IEditorPart newEditorPart = null;
        boolean doOpenWsdlEditor = true;
        if (//$NON-NLS-1$
        resource.endsWith("xsd")) {
            doOpenWsdlEditor = false;
        }
        try {
            IEditorReference[] refs = workbenchPage.getEditorReferences();
            int length = refs.length;
            // Need to find if an editor on that schema has already been opened
            for (int i = 0; i < length; i++) {
                IEditorInput input = refs[i].getEditorInput();
                if (input instanceof ADTReadOnlyFileEditorInput) {
                    ADTReadOnlyFileEditorInput readOnlyEditorInput = (ADTReadOnlyFileEditorInput) input;
                    if (readOnlyEditorInput.getUrlString().equals(resource) && (!doOpenWsdlEditor && readOnlyEditorInput.getEditorID().equals(WSDLEditorPlugin.XSD_EDITOR_ID) || doOpenWsdlEditor && readOnlyEditorInput.getEditorID().equals(WSDLEditorPlugin.WSDL_EDITOR_ID))) {
                        newEditorPart = refs[i].getEditor(true);
                        workbenchPage.activate(refs[i].getPart(true));
                        break;
                    }
                }
            }
            if (newEditorPart == null) {
                ADTReadOnlyFileEditorInput readOnlyStorageEditorInput = new ADTReadOnlyFileEditorInput(resource);
                IContentType contentType = null;
                try (InputStream iStream = readOnlyStorageEditorInput.getStorage().getContents()) {
                    contentType = Platform.getContentTypeManager().findContentTypeFor(iStream, resource);
                }
                // content type more reliable check
                if (//$NON-NLS-1$
                contentType != null && contentType.equals(XSDEditorPlugin.XSD_CONTENT_TYPE_ID) || resource.endsWith("xsd")) {
                    readOnlyStorageEditorInput.setEditorID(WSDLEditorPlugin.XSD_EDITOR_ID);
                    //$NON-NLS-1$
                    workbenchPage.openEditor(readOnlyStorageEditorInput, WSDLEditorPlugin.XSD_EDITOR_ID, true, 0);
                } else {
                    readOnlyStorageEditorInput.setEditorID(currentEditorId);
                    //$NON-NLS-1$
                    workbenchPage.openEditor(readOnlyStorageEditorInput, currentEditorId, true, 0);
                }
            }
        } catch (IOException | CoreException e) {
            ExceptionHandler.process(e);
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ADTReadOnlyFileEditorInput(org.eclipse.wst.xsd.ui.internal.adt.editor.ADTReadOnlyFileEditorInput) InputStream(java.io.InputStream) IContentType(org.eclipse.core.runtime.content.IContentType) IEditorPart(org.eclipse.ui.IEditorPart) Method(java.lang.reflect.Method) ServiceEditorInput(org.talend.repository.services.action.ServiceEditorInput) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) Item(org.talend.core.model.properties.Item) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Example 65 with IEditorPart

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

the class RefactorRenameHandler method isEnabled.

public boolean isEnabled() {
    if (!handler.isEnabled()) {
        return false;
    }
    // disable the command when editor is readonly.
    IWorkbench workbench = PlatformUI.getWorkbench();
    if (workbench == null) {
        return false;
    }
    IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }
    IWorkbenchPage activePage = window.getActivePage();
    if (activePage == null) {
        return false;
    }
    IEditorPart activeEditor = activePage.getActiveEditor();
    if (activeEditor != null && activeEditor instanceof LocalWSDLEditor) {
        LocalWSDLEditor wsdlEditor = (LocalWSDLEditor) activeEditor;
        return !wsdlEditor.isEditorInputReadOnly();
    }
    return false;
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart)

Aggregations

IEditorPart (org.eclipse.ui.IEditorPart)401 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)137 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)127 PartInitException (org.eclipse.ui.PartInitException)73 IFile (org.eclipse.core.resources.IFile)58 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)53 IEditorReference (org.eclipse.ui.IEditorReference)52 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)45 ArrayList (java.util.ArrayList)43 QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)41 IEditorInput (org.eclipse.ui.IEditorInput)37 IViewPart (org.eclipse.ui.IViewPart)34 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)33 Test (org.junit.Test)31 ISelection (org.eclipse.jface.viewers.ISelection)30 FileEditorInput (org.eclipse.ui.part.FileEditorInput)29 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)27 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)26 AbstractMultiPageTalendEditor (org.talend.designer.core.ui.AbstractMultiPageTalendEditor)26 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)24