Search in sources :

Example 11 with NodeLabelEditPart

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

the class GEFPasteAction method calculateEnabled.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
     */
@Override
protected boolean calculateEnabled() {
    Object o;
    try {
        o = Clipboard.getDefault().getContents();
    } catch (RuntimeException e) {
        return false;
    }
    org.eclipse.swt.dnd.Clipboard systemClipboard = new org.eclipse.swt.dnd.Clipboard(Display.getCurrent());
    Object systemObject = null;
    if (systemClipboard != null) {
        systemObject = systemClipboard.getContents(TextTransfer.getInstance());
    }
    List obj = getSelectedObjects();
    if (o == null && systemObject != null && systemObject instanceof String && obj != null && obj.size() == 1 && (obj.get(0) instanceof NodeLabelEditPart || obj.get(0) instanceof ConnLabelEditPart || obj.get(0) instanceof NoteEditPart)) {
        return true;
    }
    if (o instanceof String) {
        return true;
    }
    if (!(o instanceof List)) {
        return false;
    }
    List objects = (List) o;
    if (objects.isEmpty()) {
        return false;
    }
    for (Object currentObject : objects) {
        if (!(currentObject instanceof NodePart) && !(currentObject instanceof NoteEditPart) && !(currentObject instanceof SubjobContainerPart)) {
            return false;
        }
    }
    return true;
}
Also used : NodeLabelEditPart(org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart) ArrayList(java.util.ArrayList) List(java.util.List) Clipboard(org.eclipse.gef.ui.actions.Clipboard) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)

Example 12 with NodeLabelEditPart

use of org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart 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

NodeLabelEditPart (org.talend.designer.core.ui.editor.nodes.NodeLabelEditPart)12 NodePart (org.talend.designer.core.ui.editor.nodes.NodePart)10 NoteEditPart (org.talend.designer.core.ui.editor.notes.NoteEditPart)10 Node (org.talend.designer.core.ui.editor.nodes.Node)9 ConnLabelEditPart (org.talend.designer.core.ui.editor.connections.ConnLabelEditPart)8 List (java.util.List)5 ArrayList (java.util.ArrayList)4 EditPart (org.eclipse.gef.EditPart)4 Clipboard (org.eclipse.gef.ui.actions.Clipboard)4 ConnectionPart (org.talend.designer.core.ui.editor.connections.ConnectionPart)4 SubjobContainerPart (org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart)4 Rectangle (org.eclipse.draw2d.geometry.Rectangle)3 Text (org.eclipse.swt.widgets.Text)3 MoveNodeCommand (org.talend.designer.core.ui.editor.cmd.MoveNodeCommand)3 MoveNodeLabelCommand (org.talend.designer.core.ui.editor.cmd.MoveNodeLabelCommand)3 NodeContainerPart (org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart)3 Note (org.talend.designer.core.ui.editor.notes.Note)3 NodeTreeEditPart (org.talend.designer.core.ui.editor.outline.NodeTreeEditPart)3 ProcessPart (org.talend.designer.core.ui.editor.process.ProcessPart)3 Map (java.util.Map)2