use of org.talend.designer.core.ui.editor.notes.NoteEditPart in project tdi-studio-se by Talend.
the class GEFPasteAction method run.
@Override
@SuppressWarnings("unchecked")
public void run() {
Object clipBoardContent;
try {
clipBoardContent = Clipboard.getDefault().getContents();
} catch (RuntimeException e) {
return;
}
AbstractTalendEditor editor = (AbstractTalendEditor) this.getWorkbenchPart();
org.eclipse.swt.dnd.Clipboard systemClipboard = new org.eclipse.swt.dnd.Clipboard(Display.getCurrent());
Object systemObject = systemClipboard.getContents(TextTransfer.getInstance());
if (clipBoardContent instanceof List) {
List<EditPart> partsList = (List<EditPart>) clipBoardContent;
if (partsList == null || partsList.isEmpty()) {
return;
}
List<NodePart> nodeParts = new ArrayList<NodePart>();
List<NoteEditPart> noteParts = new ArrayList<NoteEditPart>();
List<SubjobContainerPart> subjobParts = new ArrayList<SubjobContainerPart>();
for (Object o : partsList) {
if (o instanceof NodePart) {
if (!nodeParts.contains(o)) {
nodeParts.add((NodePart) o);
}
} else if (o instanceof NoteEditPart) {
noteParts.add((NoteEditPart) o);
} else if (o instanceof SubjobContainerPart) {
SubjobContainerPart subjob = (SubjobContainerPart) o;
for (Iterator iterator = subjob.getChildren().iterator(); iterator.hasNext(); ) {
NodeContainerPart nodeContainerPart = (NodeContainerPart) iterator.next();
// add for bug TDI-20206
if (nodeContainerPart instanceof JobletContainerPart) {
for (Object obj : nodeContainerPart.getChildren()) {
if (obj instanceof NodePart && !nodeParts.contains(obj)) {
nodeParts.add((NodePart) obj);
}
}
}
NodePart nodePart = nodeContainerPart.getNodePart();
if (nodePart != null) {
if (!nodeParts.contains(nodePart)) {
nodeParts.add(nodePart);
}
subjobParts.add(subjob);
}
}
}
}
Map<JobletContainerPart, List<NodePart>> jobletMap = new HashMap<JobletContainerPart, List<NodePart>>();
for (NodePart nodePart : nodeParts) {
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);
}
}
List<NodePart> expandedJobletNodes = new ArrayList<NodePart>();
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) {
nodeParts.removeAll(list);
PartFactory factory = new PartFactory();
NodePart createEditPart = (NodePart) factory.createEditPart(jobletContainer, ((NodeContainer) jobletContainer.getModel()).getNode());
createEditPart.setParent(jobletContainer);
nodeParts.add(createEditPart);
expandedJobletNodes.add(createEditPart);
}
}
org.eclipse.draw2d.geometry.Point gefPoint = getCursorLocation();
// qli comment
// if the components instanceof JobletInputOutputComponent and current process instanceof not
// JobletGEFProcess,just create a messageBox and return.
AbstractProcessProvider findProcessProviderFromPID = AbstractProcessProvider.findProcessProviderFromPID(IComponent.JOBLET_PID);
if (findProcessProviderFromPID != null) {
for (NodePart copiedNodePart : nodeParts) {
Node copiedNode = (Node) copiedNodePart.getModel();
// add for bug TDI-20207.if copy joblet/job to itself,then return.
EComponentType componentType = null;
String copideNodeId = null;
String editorProcessId = null;
if (copiedNode.getComponent() != null) {
componentType = copiedNode.getComponent().getComponentType();
if (copiedNode.getComponent().getProcess() != null) {
copideNodeId = copiedNode.getComponent().getProcess().getId();
}
}
if (editor.getProcess() != null) {
editorProcessId = editor.getProcess().getId();
}
for (IElementParameter element : copiedNode.getElementParametersFromField(EParameterFieldType.PROCESS_TYPE)) {
for (Map.Entry<String, IElementParameter> entry : element.getChildParameters().entrySet()) {
if (("PROCESS_TYPE_PROCESS").equals(entry.getKey())) {
if (editorProcessId != null && editorProcessId.equals(entry.getValue().getValue())) {
return;
}
}
}
}
if ((EComponentType.JOBLET).equals(componentType)) {
if (editorProcessId != null && editorProcessId.equals(copideNodeId)) {
return;
}
}
if (findProcessProviderFromPID.isJobletInputOrOutputComponent(copiedNode)) {
if (!findProcessProviderFromPID.isExtensionProcess(editor.getProcess())) {
MessageBox messagebox = new MessageBox(PlatformUI.getWorkbench().getDisplay().getActiveShell(), SWT.ICON_WARNING);
//$NON-NLS-1$
messagebox.setText(Messages.getString("GEFPasteAction.textWarning"));
//$NON-NLS-1$
messagebox.setMessage(Messages.getString("GEFPasteAction.warningMessages"));
messagebox.open();
return;
}
}
if (copiedNode.getJobletNode() != null) {
boolean canP = canPasteJobletNode(editor.getProcess(), copiedNode);
if (!canP) {
return;
}
}
}
}
if (nodeParts.size() != 0 && noteParts.size() != 0) {
MultiplePasteCommand mpc = new MultiplePasteCommand(nodeParts, noteParts, (org.talend.designer.core.ui.editor.process.Process) editor.getProcess(), gefPoint);
mpc.setSelectedSubjobs(subjobParts);
mpc.setSelectedExpandedJoblet(expandedJobletNodes);
execute(mpc);
} else if (nodeParts.size() != 0) {
NodesPasteCommand cmd = new NodesPasteCommand(nodeParts, editor.getProcess(), gefPoint);
cmd.setSelectedSubjobs(subjobParts);
cmd.setSelectedExpandedJoblet(expandedJobletNodes);
execute(cmd);
} else if (noteParts.size() != 0) {
NotesPasteCommand cmd = new NotesPasteCommand(noteParts, (org.talend.designer.core.ui.editor.process.Process) editor.getProcess(), gefPoint, false, null);
execute(cmd);
}
setCursorLocation(null);
} else if (clipBoardContent instanceof String) {
List objects = getSelectedObjects();
if (objects.size() == 1) {
String content = (String) clipBoardContent;
if (objects.get(0) instanceof NoteEditPart && ((NoteEditPart) objects.get(0)).getDirectEditManager() != null) {
Text text = ((NoteEditPart) objects.get(0)).getDirectEditManager().getTextControl();
if (text != null) {
text.insert(content);
}
} else if (objects.get(0) instanceof ConnLabelEditPart && ((ConnLabelEditPart) objects.get(0)).getDirectEditManager() != null) {
Text text = ((ConnLabelEditPart) objects.get(0)).getDirectEditManager().getTextControl();
if (text != null) {
text.insert(content);
}
} else if (objects.get(0) instanceof NodeLabelEditPart && ((NodeLabelEditPart) objects.get(0)).getDirectEditManager() != null) {
{
Text text = (Text) ((NodeLabelEditPart) objects.get(0)).getDirectEditManager().getCellEditor().getControl();
if (text != null) {
text.insert(content);
}
}
}
}
} else if (systemObject != null && systemObject instanceof String) {
List objects = getSelectedObjects();
if (objects.size() == 1) {
String content = (String) systemObject;
if (objects.get(0) instanceof NoteEditPart && ((NoteEditPart) objects.get(0)).getDirectEditManager() != null) {
Text text = ((NoteEditPart) objects.get(0)).getDirectEditManager().getTextControl();
if (text != null) {
text.insert(content);
}
} else if (objects.get(0) instanceof ConnLabelEditPart && ((ConnLabelEditPart) objects.get(0)).getDirectEditManager() != null) {
Text text = ((ConnLabelEditPart) objects.get(0)).getDirectEditManager().getTextControl();
if (text != null) {
text.insert(content);
}
} else if (objects.get(0) instanceof NodeLabelEditPart && ((NodeLabelEditPart) objects.get(0)).getDirectEditManager() != null) {
{
Text text = (Text) ((NodeLabelEditPart) objects.get(0)).getDirectEditManager().getCellEditor().getControl();
if (text != null) {
text.insert(content);
}
}
}
}
}
}
use of org.talend.designer.core.ui.editor.notes.NoteEditPart in project tdi-studio-se by Talend.
the class NodePartKeyHander method getNavigationSiblings.
@Override
protected List getNavigationSiblings() {
EditPart focusPart = getFocusEditPart();
boolean displayVa = true;
if (focusPart.getParent() != null) {
if (focusPart instanceof SubjobContainerPart) {
// return getNodePart((SubjobContainerPart) focusPart);
SubjobContainerPart subConPart = (SubjobContainerPart) focusPart;
List subList = focusPart.getParent().getChildren();
for (int j = 0; j < subList.size(); j++) {
if (subList.get(j) instanceof SubjobContainerPart) {
subConPart = (SubjobContainerPart) subList.get(j);
SubjobContainer subContainer = (SubjobContainer) subConPart.getModel();
if (subContainer.isDisplayed() == false) {
displayVa = false;
}
} else if (subList.get(j) instanceof NoteEditPart) {
NoteEditPart notePart = (NoteEditPart) subList.get(j);
return getNodePart((ProcessPart) notePart.getParent());
} else if (subList.get(j) instanceof NodePart) {
NodePart node = (NodePart) subList.get(j);
return getNodePart((ProcessPart) node.getParent().getParent().getParent());
}
}
if (displayVa == false) {
return getNodePart((ProcessPart) focusPart.getParent());
}
} else if (focusPart instanceof NodePart) {
// get all node part for a job.
return getNodePart((ProcessPart) focusPart.getParent().getParent().getParent());
// return getNodePart((SubjobContainerPart) focusPart.getParent().getParent());
} else if (focusPart instanceof NoteEditPart) {
return getNodePart((ProcessPart) focusPart.getParent());
}
return focusPart.getParent().getChildren();
}
List list = new ArrayList();
list.add(focusPart);
return list;
}
use of org.talend.designer.core.ui.editor.notes.NoteEditPart in project tdi-studio-se by Talend.
the class NotesPasteCommand method createNoteList.
@SuppressWarnings("unchecked")
private void createNoteList() {
int firstIndex = 0;
int index = 0;
noteList = new ArrayList<Note>();
// create the notes
for (NoteEditPart copiedNodePart : noteParts) {
Note copiedNote = (Note) copiedNodePart.getModel();
Note pastedNote = new Note();
pastedNote.setOpaque(copiedNote.isOpaque());
pastedNote.setText(copiedNote.getText());
pastedNote.setSize(copiedNote.getSize());
// see bug 0005571: Copy/Paste of Note doesn't keep Format
EParameterName[] params = new EParameterName[] { EParameterName.NOTE_FONT, EParameterName.FONT_SIZE, EParameterName.FONT_BOLD, EParameterName.FONT_ITALIC, EParameterName.NOTE_LINECOLOR, EParameterName.NOTE_COLOR, EParameterName.NOTETXT_COLOR, EParameterName.NOTETXT_LEFT, EParameterName.NOTETXT_RIGHT, EParameterName.NOTETXT_CENTER, EParameterName.NOTELABEL_CENTER, EParameterName.NOTETXT_TOP, EParameterName.NOTETXT_BOTTOM };
for (EParameterName param : params) {
Object value = copiedNote.getElementParameter(param.getName()).getValue();
pastedNote.getElementParameter(param.getName()).setValue(value);
}
pastedNote.setOpaque(copiedNote.isOpaque());
pastedNote.setProcess(process);
Point location = null;
if (getCursorLocation() == null) {
location = copiedNote.getLocation();
} else {
location = getCursorLocation();
index = noteParts.indexOf(copiedNodePart);
}
if (process.isGridEnabled()) {
// replace the component to set it on the grid if it's enabled
int tempVar = location.x / TalendEditor.GRID_SIZE;
location.x = tempVar * TalendEditor.GRID_SIZE;
tempVar = location.y / TalendEditor.GRID_SIZE;
location.y = tempVar * TalendEditor.GRID_SIZE;
}
pastedNote.setLocation(findLocationForNote(location, copiedNote.getSize(), index, firstIndex));
noteList.add(pastedNote);
}
}
use of org.talend.designer.core.ui.editor.notes.NoteEditPart in project tdi-studio-se by Talend.
the class GefEditorLabelProvider method getImage.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
*/
public Image getImage(Object objects) {
Node node = null;
if (objects == null || objects.equals(StructuredSelection.EMPTY)) {
return null;
}
if (!(objects instanceof IStructuredSelection)) {
return null;
}
final boolean[] multiple = { false };
Object object = getObject(objects, multiple);
if (object == null) {
return null;
}
if ((object instanceof NodeTreeEditPart)) {
node = (Node) ((NodeTreeEditPart) object).getModel();
} else {
if (object instanceof NodeReturnsTreeEditPart) {
node = lastNode;
} else {
if (object instanceof ProcessPart) {
return ImageProvider.getImage(ECoreImage.PROCESS_ICON);
}
if (object instanceof ConnectionPart) {
return ImageProvider.getImage(EImage.RIGHT_ICON);
}
if (object instanceof NoteEditPart) {
return ImageProvider.getImage(ECoreImage.CODE_ICON);
}
if (object instanceof ConnLabelEditPart) {
return ImageProvider.getImage(EImage.RIGHT_ICON);
}
if ((object instanceof NodeLabelEditPart)) {
node = ((NodeContainer) ((NodeLabelEditPart) object).getParent().getModel()).getNode();
}
if (!(object instanceof NodePart)) {
return null;
}
if (node == null) {
node = (Node) ((NodePart) object).getModel();
}
}
}
if (lastNode != node) {
lastNode = node;
}
return CoreImageProvider.getComponentIcon(node.getComponent(), ICON_SIZE.ICON_24);
}
use of org.talend.designer.core.ui.editor.notes.NoteEditPart in project tdi-studio-se by Talend.
the class GefEditorLabelProvider method getText.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
*/
public String getText(Object objects) {
Node node = null;
if (objects == null || objects.equals(StructuredSelection.EMPTY)) {
//$NON-NLS-1$
return "No items selected";
}
if (!(objects instanceof IStructuredSelection)) {
return null;
}
final boolean[] multiple = { false };
Object object = getObject(objects, multiple);
if (object == null) /* || ((IStructuredSelection) objects).size() > 1 */
{
//$NON-NLS-1$
return "No items selected";
} else {
if (object instanceof NodeContainerPart) {
NodeContainerPart nContainer = (NodeContainerPart) object;
Process process = (Process) nContainer.getParent().getModel();
return process.getName();
} else if (object instanceof ProcessPart) {
Process process = (Process) ((ProcessPart) object).getModel();
return process.getLabel();
} else if (object instanceof ProcessTreeEditPart) {
Process process = (Process) ((ProcessTreeEditPart) object).getModel();
return process.getName();
}
if (object instanceof ConnectionPart) {
Connection conn = (Connection) ((ConnectionPart) object).getModel();
return conn.getName();
}
if (object instanceof NoteEditPart) {
return Note.class.getSimpleName();
}
if (object instanceof ConnLabelEditPart) {
Connection conn = (Connection) ((ConnectionLabel) ((ConnLabelEditPart) object).getModel()).getConnection();
return conn.getName();
}
if (object instanceof NodeTreeEditPart) {
node = (Node) ((NodeTreeEditPart) object).getModel();
} else {
if (object instanceof NodeReturnsTreeEditPart) {
node = lastNode;
} else {
if (object instanceof NodeLabelEditPart) {
node = ((NodeContainer) ((NodeLabelEditPart) object).getParent().getModel()).getNode();
}
if (!(object instanceof NodePart)) {
return null;
}
if (node == null) {
node = (Node) ((NodePart) object).getModel();
}
}
}
if (lastNode != node) {
lastNode = node;
}
String name = node.getUniqueName();
// }
return name;
}
}
Aggregations