Search in sources :

Example 16 with AbstractTalendEditor

use of org.talend.designer.core.ui.editor.AbstractTalendEditor in project tdi-studio-se by Talend.

the class JavaCodeProblemsChecker method retrieveDetailedProblems.

/**
     * DOC amaumont Comment method "retrieveDetailedProblems".
     * 
     * @return
     */
private List<DetailedProblem> retrieveDetailedProblems(final IAloneProcessNodeConfigurer nodeConfigurer) {
    final ArrayList<DetailedProblem> iproblems = new ArrayList<DetailedProblem>();
    final IWorkbench workbench = PlatformUI.getWorkbench();
    Display display = workbench.getDisplay();
    if (display != null) {
        display.syncExec(new Runnable() {

            public void run() {
                IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
                IEditorPart editorPart = page.getActiveEditor();
                if (editorPart instanceof AbstractMultiPageTalendEditor) {
                    AbstractMultiPageTalendEditor multiPageTalendEditor = ((AbstractMultiPageTalendEditor) editorPart);
                    AbstractTalendEditor talendEditor = multiPageTalendEditor.getTalendEditor();
                    TalendJavaEditor codeEditor = (TalendJavaEditor) multiPageTalendEditor.getCodeEditor();
                    org.eclipse.jdt.core.ICompilationUnit compilationUnit = (org.eclipse.jdt.core.ICompilationUnit) codeEditor.getUnit();
                    IProcess process = talendEditor.getProcess();
                    if (AbstractProcessProvider.isExtensionProcessForJoblet(process)) {
                        // joblet
                        return;
                    }
                    String selectedNodeName = multiPageTalendEditor.getSelectedNodeName();
                    if (selectedNodeName == null) {
                        return;
                    }
                    String uniqueNodeName = null;
                    boolean found = false;
                    List<? extends INode> generatingNodes = process.getGeneratingNodes();
                    int generatingNodesListSize = generatingNodes.size();
                    for (int i = 0; i < generatingNodesListSize; i++) {
                        INode node = generatingNodes.get(i);
                        /* startsWith method used in case of virtual component such as 'tMap_1_TMAP_OUT' */
                        if (node.getUniqueName().equals(selectedNodeName) || node.getUniqueName().startsWith(selectedNodeName + "_")) {
                            //$NON-NLS-1$
                            uniqueNodeName = node.getUniqueName();
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        // in case the component doesn't exist
                        return;
                    }
                    final String code = retrieveCode(process, uniqueNodeName, nodeConfigurer);
                    // System.out.println(code);
                    // create requestor for accumulating discovered problems
                    MyProblemRequestor problemRequestor = new MyProblemRequestor(code, iproblems, selectedNodeName);
                    // use working copy to hold source with error
                    org.eclipse.jdt.core.ICompilationUnit workingCopy = null;
                    try {
                        JavaProcessorUtilities.computeLibrariesPath(process.getNeededModules(false), process);
                        try {
                            WorkingCopyOwner workingCopyOwner = new WorkingCopyOwner() {
                            };
                            workingCopy = ((org.eclipse.jdt.core.ICompilationUnit) compilationUnit).getWorkingCopy(workingCopyOwner, problemRequestor, null);
                            problemRequestor.setReportProblems(true);
                            ((IOpenable) workingCopy).getBuffer().setContents(code);
                            ((org.eclipse.jdt.core.ICompilationUnit) workingCopy).reconcile(ICompilationUnit.NO_AST, true, null, null);
                            problemRequestor.setReportProblems(false);
                        } finally {
                            if (workingCopy != null) {
                                workingCopy.discardWorkingCopy();
                            }
                        }
                    } catch (JavaModelException e) {
                        ExceptionHandler.process(e);
                    } catch (CoreException e) {
                        ExceptionHandler.process(e);
                    }
                }
            }
        });
    }
    return iproblems;
}
Also used : INode(org.talend.core.model.process.INode) IOpenable(org.eclipse.jdt.core.IOpenable) JavaModelException(org.eclipse.jdt.core.JavaModelException) TalendJavaEditor(org.talend.designer.core.ui.editor.TalendJavaEditor) ArrayList(java.util.ArrayList) DetailedProblem(org.talend.designer.core.ui.editor.DetailedProblem) WorkingCopyOwner(org.eclipse.jdt.core.WorkingCopyOwner) AbstractTalendEditor(org.talend.designer.core.ui.editor.AbstractTalendEditor) ArrayList(java.util.ArrayList) List(java.util.List) IProcess(org.talend.core.model.process.IProcess) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) IEditorPart(org.eclipse.ui.IEditorPart) IWorkbench(org.eclipse.ui.IWorkbench) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) Display(org.eclipse.swt.widgets.Display)

Example 17 with AbstractTalendEditor

use of org.talend.designer.core.ui.editor.AbstractTalendEditor in project tdi-studio-se by Talend.

the class GEFDeleteAction method calculateEnabled.

@Override
protected boolean calculateEnabled() {
    objectsToDelete = new ArrayList();
    List objects = getSelectedObjects();
    objectsToDelete.addAll(objects);
    if (objects.isEmpty() || (objects.size() == 1 && objects.get(0) instanceof ProcessPart)) {
        return false;
    }
    if (!(objects.get(0) instanceof EditPart)) {
        return false;
    }
    AbstractTalendEditor editor = (AbstractTalendEditor) this.getWorkbenchPart();
    AbstractProcessProvider pProvider = AbstractProcessProvider.findProcessProviderFromPID(IComponent.JOBLET_PID);
    if (pProvider != null) {
        Map<JobletContainerPart, List<NodePart>> jobletMap = new HashMap<JobletContainerPart, List<NodePart>>();
        boolean nodeInJoblet = false;
        boolean allJunitnode = true;
        boolean hasNode = false;
        int i = 0;
        for (Object o : objects) {
            if (o instanceof NodePart) {
                hasNode = true;
                NodePart nodePart = (NodePart) o;
                Node no = (Node) ((NodePart) o).getModel();
                if (no.getProcess().isReadOnly()) {
                    return false;
                }
                if (no.isReadOnly()) {
                    i++;
                }
                if (no.getJunitNode() == null) {
                    allJunitnode = false;
                }
                if (!pProvider.canDeleteNode(no)) {
                    return false;
                }
                boolean isCollapsedNode = false;
                if (editor.getProcess().getGraphicalNodes().contains(nodePart.getModel())) {
                    isCollapsedNode = true;
                }
                if (!isCollapsedNode && nodePart.getParent() instanceof JobletContainerPart) {
                    JobletContainerPart jobletContainer = (JobletContainerPart) nodePart.getParent();
                    List<NodePart> jobletNodeParts = jobletMap.get(jobletContainer);
                    if (jobletNodeParts == null) {
                        jobletNodeParts = new ArrayList<NodePart>();
                        jobletMap.put(jobletContainer, jobletNodeParts);
                    }
                    jobletNodeParts.add(nodePart);
                }
            } else if (o instanceof ConnectionPart) {
                Connection conn = (Connection) ((ConnectionPart) o).getModel();
                if (conn.getSource().getProcess().isReadOnly()) {
                    return false;
                }
                if (conn.isReadOnly()) {
                    i++;
                }
            } else if (o instanceof ConnLabelEditPart) {
                ConnectionLabel connLabel = (ConnectionLabel) ((ConnLabelEditPart) o).getModel();
                if (connLabel.getConnection().getSource().getProcess().isReadOnly()) {
                    return false;
                }
                if (connLabel.getConnection().isReadOnly()) {
                    i++;
                }
            } else if (o instanceof NoteEditPart) {
                allJunitnode = false;
                Note note = (Note) ((NoteEditPart) o).getModel();
                if (note.isReadOnly()) {
                    i++;
                }
            } else if (o instanceof SubjobContainerPart) {
                SubjobContainer subjob = (SubjobContainer) ((SubjobContainerPart) o).getModel();
                if (subjob.getProcess().isReadOnly()) {
                    return false;
                }
                if (subjob.isReadOnly()) {
                    i++;
                    continue;
                }
                boolean isAllReadonly = true;
                boolean subjobAllJunit = true;
                for (NodeContainer nc : subjob.getNodeContainers()) {
                    Node node = nc.getNode();
                    if (!node.isReadOnly()) {
                        isAllReadonly = false;
                    }
                    if (node.getJunitNode() == null) {
                        subjobAllJunit = false;
                    }
                }
                if (isAllReadonly || subjobAllJunit) {
                    i++;
                }
            }
        }
        for (JobletContainerPart jobletContainer : jobletMap.keySet()) {
            boolean copyJobletNode = true;
            List<NodePart> list = jobletMap.get(jobletContainer);
            for (Object obj : jobletContainer.getChildren()) {
                if (obj instanceof NodePart) {
                    if (!list.contains(obj)) {
                        copyJobletNode = false;
                        break;
                    }
                }
            }
            if (copyJobletNode) {
                objectsToDelete.removeAll(list);
                PartFactory factory = new PartFactory();
                NodePart createEditPart = (NodePart) factory.createEditPart(jobletContainer, ((NodeContainer) jobletContainer.getModel()).getNode());
                createEditPart.setParent(jobletContainer);
                createEditPart.installEditPolicy(EditPolicy.COMPONENT_ROLE, new NodeEditPolicy());
                objectsToDelete.add(createEditPart);
            } else {
                nodeInJoblet = true;
            }
        }
        if (((nodeInJoblet || allJunitnode) && hasNode) || i == objects.size()) {
            return false;
        }
    }
    return true;
}
Also used : HashMap(java.util.HashMap) PartFactory(org.talend.designer.core.ui.editor.PartFactory) Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) NodeContainer(org.talend.designer.core.ui.editor.nodecontainer.NodeContainer) ConnectionLabel(org.talend.designer.core.ui.editor.connections.ConnectionLabel) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart) AbstractProcessProvider(org.talend.designer.core.model.process.AbstractProcessProvider) NodeEditPolicy(org.talend.designer.core.ui.editor.nodes.NodeEditPolicy) SubjobContainer(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainer) AbstractTalendEditor(org.talend.designer.core.ui.editor.AbstractTalendEditor) ArrayList(java.util.ArrayList) List(java.util.List) ProcessPart(org.talend.designer.core.ui.editor.process.ProcessPart) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) EditPart(org.eclipse.gef.EditPart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart) Connection(org.talend.designer.core.ui.editor.connections.Connection) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) JobletContainerPart(org.talend.designer.core.ui.editor.jobletcontainer.JobletContainerPart) ConnectionPart(org.talend.designer.core.ui.editor.connections.ConnectionPart) Note(org.talend.designer.core.ui.editor.notes.Note) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)

Example 18 with AbstractTalendEditor

use of org.talend.designer.core.ui.editor.AbstractTalendEditor in project tdi-studio-se by Talend.

the class GEFCopyAction method run.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
public void run() {
    List objects = GEFDeleteAction.filterSameObject(getSelectedObjects());
    if (!objects.isEmpty()) {
        Clipboard clipboard = Clipboard.getDefault();
        org.eclipse.swt.dnd.Clipboard systemClipboard = new org.eclipse.swt.dnd.Clipboard(Display.getCurrent());
        boolean noteTextActived = false;
        boolean connectionTextActived = false;
        boolean nodeLabelActived = false;
        Text text = null;
        if (objects.size() == 1) {
            if (objects.get(0) instanceof NoteEditPart) {
                NoteDirectEditManager directEditManager = ((NoteEditPart) objects.get(0)).getDirectEditManager();
                if (directEditManager != null && directEditManager.getCellEditor() != null) {
                    noteTextActived = true;
                }
            } else if (objects.get(0) instanceof ConnLabelEditPart) {
                ConnLabelEditPart connLabelEditPart = (ConnLabelEditPart) objects.get(0);
                if (connLabelEditPart.getDirectEditManager() != null && connLabelEditPart.getDirectEditManager().getTextControl() != null) {
                    connectionTextActived = true;
                }
            } else if (objects.get(0) instanceof NodeLabelEditPart) {
                NodeLabelEditPart nodeLabelEditPart = (NodeLabelEditPart) objects.get(0);
                if (nodeLabelEditPart.getDirectEditManager() != null && nodeLabelEditPart.getDirectEditManager().getCellEditor() != null) {
                    nodeLabelActived = true;
                }
            }
        }
        if (noteTextActived) {
            text = ((NoteEditPart) objects.get(0)).getDirectEditManager().getTextControl();
            clipboard.setContents(text.getSelectionText());
        } else if (connectionTextActived) {
            text = ((ConnLabelEditPart) objects.get(0)).getDirectEditManager().getTextControl();
            clipboard.setContents(text.getSelectionText());
        } else if (nodeLabelActived) {
            text = (Text) ((NodeLabelEditPart) objects.get(0)).getDirectEditManager().getCellEditor().getControl();
            clipboard.setContents(text.getSelectionText());
        } else {
            clipboard.setContents(objects);
        }
        if (text != null && !("").equals(text.getSelectionText())) {
            TextTransfer textTransfer = TextTransfer.getInstance();
            Transfer[] transfers = new Transfer[] { textTransfer };
            Object[] data = new Object[] { text.getSelectionText() };
            systemClipboard.setContents(data, transfers);
        }
    }
    // Refreshes the pasteAction's enable status.
    IWorkbenchPart part = getWorkbenchPart();
    if (part instanceof AbstractTalendEditor) {
        AbstractTalendEditor talendEditor = (AbstractTalendEditor) part;
        IAction action = talendEditor.getActionRegistry().getAction(ActionFactory.PASTE.getId());
        action.setEnabled(true);
    }
}
Also used : NoteDirectEditManager(org.talend.designer.core.ui.editor.notes.NoteDirectEditManager) IAction(org.eclipse.jface.action.IAction) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) NodeLabelEditPart(org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart) Text(org.eclipse.swt.widgets.Text) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) AbstractTalendEditor(org.talend.designer.core.ui.editor.AbstractTalendEditor) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) List(java.util.List) Clipboard(org.eclipse.gef.ui.actions.Clipboard) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Aggregations

AbstractTalendEditor (org.talend.designer.core.ui.editor.AbstractTalendEditor)18 IEditorPart (org.eclipse.ui.IEditorPart)14 AbstractMultiPageTalendEditor (org.talend.designer.core.ui.AbstractMultiPageTalendEditor)12 ArrayList (java.util.ArrayList)4 List (java.util.List)4 IEditorReference (org.eclipse.ui.IEditorReference)4 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)3 IProcess (org.talend.core.model.process.IProcess)3 IProcess2 (org.talend.core.model.process.IProcess2)3 ConnLabelEditPart (org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)3 HashMap (java.util.HashMap)2 EditPart (org.eclipse.gef.EditPart)2 CommandStack (org.eclipse.gef.commands.CommandStack)2 Clipboard (org.eclipse.gef.ui.actions.Clipboard)2 Text (org.eclipse.swt.widgets.Text)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 INode (org.talend.core.model.process.INode)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 AbstractProcessProvider (org.talend.designer.core.model.process.AbstractProcessProvider)2 PartFactory (org.talend.designer.core.ui.editor.PartFactory)2