use of org.eclipse.gef.ui.actions.Clipboard 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);
}
}
Aggregations