use of org.talend.designer.core.ui.editor.notes.NoteEditPart in project tdi-studio-se by Talend.
the class SubjobContainerLayoutEditPolicy method createChangeConstraintCommand.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#createChangeConstraintCommand(org.eclipse.gef.EditPart,
* java.lang.Object)
*/
protected Command createChangeConstraintCommand(final EditPart child, final Object constraint) {
if (child instanceof NoteEditPart) {
if (((Note) child.getModel()).isReadOnly()) {
return null;
}
MoveNoteCommand locationCommand = new MoveNoteCommand((Note) child.getModel(), ((Rectangle) constraint).getLocation());
return locationCommand;
}
if (child instanceof NodeLabelEditPart) {
boolean nodeSelected;
// if (((NodeLabelEditPart) child).getNodePart().getSelected() != 0) {
// nodeSelected = true;
// } else {
nodeSelected = false;
// }
MoveNodeLabelCommand locationCommand = new MoveNodeLabelCommand((NodeLabel) child.getModel(), ((Rectangle) constraint).getLocation(), nodeSelected);
return locationCommand;
} else if (child instanceof NodePart) {
if (((Node) child.getModel()).isReadOnly()) {
return null;
}
MoveNodeCommand locationCommand = new MoveNodeCommand((Node) child.getModel(), ((Rectangle) constraint).getLocation());
return locationCommand;
} else {
return null;
}
}
use of org.talend.designer.core.ui.editor.notes.NoteEditPart in project tdi-studio-se by Talend.
the class AbstractNotePropertySection method setInput.
@Override
public void setInput(IWorkbenchPart part, ISelection selection) {
super.setInput(part, selection);
if (part instanceof AbstractMultiPageTalendEditor) {
multiPageTalendEditor = (AbstractMultiPageTalendEditor) part;
} else {
multiPageTalendEditor = (AbstractMultiPageTalendEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
}
if (getSelection() instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) getSelection();
if (structuredSelection.getFirstElement() instanceof NoteEditPart) {
NoteEditPart noteEditPart = (NoteEditPart) structuredSelection.getFirstElement();
note = (Note) noteEditPart.getModel();
}
}
}
use of org.talend.designer.core.ui.editor.notes.NoteEditPart 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;
}
use of org.talend.designer.core.ui.editor.notes.NoteEditPart in project tdi-studio-se by Talend.
the class GEFDeleteAction method createDeleteCommand.
@Override
public Command createDeleteCommand(List objects) {
objects = filterSameObject(objectsToDelete);
if (objects.isEmpty()) {
return null;
}
if (!(objects.get(0) instanceof EditPart)) {
return null;
}
EditPart object = (EditPart) objects.get(0);
// for TUP-1015
boolean isConnAttachedJLTriggerComp = false;
ConnectionPart connectionPart = null;
if (object instanceof ConnectionPart) {
connectionPart = (ConnectionPart) object;
} else if (object instanceof ConnLabelEditPart) {
connectionPart = (ConnectionPart) object.getParent();
}
if (connectionPart != null) {
Node srcNode = null;
Object srcModel = connectionPart.getSource().getModel();
if (srcModel instanceof Node) {
srcNode = (Node) srcModel;
}
Node tarNode = null;
Object tarModel = connectionPart.getTarget().getModel();
if (tarModel instanceof Node) {
tarNode = (Node) tarModel;
}
if (srcNode == null || tarNode == null) {
return null;
}
IProcess process = srcNode.getProcess();
if (AbstractProcessProvider.isExtensionProcessForJoblet(process)) {
IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
if (service != null && (service.isTriggerNode(srcNode) || service.isTriggerNode(tarNode))) {
isConnAttachedJLTriggerComp = true;
}
}
}
IPreferenceStore preferenceStore = DesignerPlugin.getDefault().getPreferenceStore();
String preKey = TalendDesignerPrefConstants.NOT_SHOW_WARNING_WHEN_DELETE_LINK_WITH_JOBLETTRIGGERLINKCOMPONENT;
if (isConnAttachedJLTriggerComp && !preferenceStore.getBoolean(preKey)) {
MessageDialogWithToggle jlTriggerConfirmDialog = new MessageDialogWithToggle(null, //$NON-NLS-1$
Messages.getString("GEFDeleteAction.deleteConnectionDialog.title"), // accept the default window icon
null, Messages.getString("GEFDeleteAction.deleteConnectionDialog.msg"), MessageDialog.WARNING, new String[] { //$NON-NLS-1$
IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0, //$NON-NLS-1$
Messages.getString("GEFDeleteAction.deleteConnectionDialog.toggleMsg"), preferenceStore.getDefaultBoolean(preKey));
jlTriggerConfirmDialog.setPrefStore(preferenceStore);
jlTriggerConfirmDialog.setPrefKey(preKey);
if (jlTriggerConfirmDialog.open() != IDialogConstants.YES_ID) {
return null;
}
preferenceStore.setValue(preKey, jlTriggerConfirmDialog.getToggleState());
}
List nodeParts = new ArrayList();
List noteParts = new ArrayList();
List others = new ArrayList(objects);
for (Object o : objects) {
if (o instanceof NodePart) {
others.remove(o);
Node model = (Node) ((NodePart) o).getModel();
if (model.getJobletNode() != null) {
continue;
}
if (model.getJunitNode() != null) {
continue;
}
nodeParts.add(o);
} else if (o instanceof NoteEditPart) {
noteParts.add(o);
others.remove(o);
} else if (o instanceof SubjobContainerPart) {
others.remove(o);
SubjobContainerPart subjob = (SubjobContainerPart) o;
for (Iterator iterator = subjob.getChildren().iterator(); iterator.hasNext(); ) {
NodeContainerPart nodeContainerPart = (NodeContainerPart) iterator.next();
if (nodeContainerPart instanceof JobletContainerPart) {
JobletContainer jobletCon = (JobletContainer) ((JobletContainerPart) nodeContainerPart).getModel();
JobletContainerFigure jobletFigure = (JobletContainerFigure) ((JobletContainerPart) nodeContainerPart).getFigure();
if (!jobletCon.isCollapsed()) {
jobletFigure.doCollapse();
}
}
NodePart nodePart = nodeContainerPart.getNodePart();
if (nodePart != null) {
Node model = (Node) nodePart.getModel();
if (model.getJunitNode() != null) {
continue;
}
nodeParts.add(nodePart);
}
}
}
}
if (others.size() == 0) {
// so notes & nodes only
CompoundCommand cpdCmd = new CompoundCommand();
//$NON-NLS-1$
cpdCmd.setLabel(Messages.getString("GEFDeleteAction.DeleteItems"));
if (nodeParts.size() != 0) {
GroupRequest deleteReq = new GroupRequest(RequestConstants.REQ_DELETE);
deleteReq.setEditParts(nodeParts);
cpdCmd.add(((NodePart) nodeParts.get(0)).getCommand(deleteReq));
}
if (noteParts.size() != 0) {
GroupRequest deleteReq = new GroupRequest(RequestConstants.REQ_DELETE);
deleteReq.setEditParts(noteParts);
cpdCmd.add(((NoteEditPart) noteParts.get(0)).getCommand(deleteReq));
}
return cpdCmd;
} else {
GroupRequest deleteReq = new GroupRequest(RequestConstants.REQ_DELETE);
deleteReq.setEditParts(objects);
Command cmd = object.getCommand(deleteReq);
return cmd;
}
}
use of org.talend.designer.core.ui.editor.notes.NoteEditPart 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;
}
Aggregations