use of org.talend.designer.core.ui.editor.AbstractTalendEditor 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.AbstractTalendEditor in project tdi-studio-se by Talend.
the class JobSettingsView method getProcess.
private IProcess getProcess(IRepositoryViewObject viewObject) {
boolean isOpen = RepositoryManager.isOpenedItemInEditor(viewObject);
if (isOpen) {
final IEditorPart activeEditor = getSite().getPage().getActiveEditor();
if (activeEditor != null && activeEditor instanceof AbstractMultiPageTalendEditor) {
AbstractTalendEditor talendEditor = ((AbstractMultiPageTalendEditor) activeEditor).getTalendEditor();
IProcess process = talendEditor.getProcess();
return process;
}
}
return null;
}
use of org.talend.designer.core.ui.editor.AbstractTalendEditor in project tdi-studio-se by Talend.
the class JobSettingsView method refresh.
public void refresh(boolean force, Object obj) {
if (force) {
cleanDisplay();
}
final IEditorPart activeEditor = getSite().getPage().getActiveEditor();
if (obj == null) {
if (activeEditor != null && activeEditor instanceof AbstractMultiPageTalendEditor) {
AbstractTalendEditor talendEditor = ((AbstractMultiPageTalendEditor) activeEditor).getTalendEditor();
IProcess process = talendEditor.getProcess();
if (process != null && process instanceof Element) {
this.selectedPrimary = true;
this.cleaned = force;
this.element = (Element) process;
// remove "Job" or "Joblet" from title
String title = activeEditor.getTitle();
if (title.startsWith(VIEW_NAME_JOBLET)) {
title = title.substring(VIEW_NAME_JOBLET.length() + 1);
} else if (title.startsWith(getViewNameLable())) {
title = title.substring(getViewNameLable().length() + 1);
}
setElement(element, title, null);
return;
}
} else {
IDiagramModelService diagramModelService = CorePlugin.getDefault().getDiagramModelService();
if (diagramModelService != null && diagramModelService.isBusinessDiagramEditor(activeEditor)) {
this.selectedPrimary = true;
this.cleaned = force;
IRepositoryViewObject object = retrieveBusiness(activeEditor);
if (object != null) {
//$NON-NLS-1$
String title = object.getLabel() + " " + object.getVersion();
Object type = object.getRepositoryObjectType();
setElement(activeEditor, type + SEPARATOR + title, null);
}
return;
}
}
} else {
this.selectedPrimary = true;
this.cleaned = force;
IRepositoryViewObject object = retrieveBusiness(activeEditor);
if (object != null) {
//$NON-NLS-1$
String title = object.getLabel() + " " + object.getVersion();
Object type = object.getRepositoryObjectType();
setElement(obj, type + SEPARATOR + title, null);
}
return;
}
cleanDisplay();
}
use of org.talend.designer.core.ui.editor.AbstractTalendEditor in project tdi-studio-se by Talend.
the class StatsAndLogsComposite method useProjectSettingButtonClick.
/*
* (non-Javadoc)
*
* @see org.talend.designer.core.ui.views.jobsettings.AbstractPreferenceComposite#useProjectSettingButtonClick()
*/
@Override
protected void useProjectSettingButtonClick() {
boolean flag = useProjectSetting.getSelection();
setMainCompositeEnable(!flag);
topComposite.setEnabled(true);
ElementParameter2ParameterType.setParameterValue(pType, EParameterName.STATANDLOG_USE_PROJECT_SETTINGS.getName(), Boolean.valueOf(flag));
PropertyChangeCommand cmd = new PropertyChangeCommand(elem, EParameterName.STATANDLOG_USE_PROJECT_SETTINGS.getName(), Boolean.valueOf(flag));
getCommandStack().execute(cmd);
updateContextValue(flag);
// hywang add for bug 7587
IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (activeEditor != null && activeEditor instanceof AbstractMultiPageTalendEditor) {
AbstractTalendEditor workbenchPart = ((AbstractMultiPageTalendEditor) activeEditor).getTalendEditor();
Boolean currentEditorDirty = workbenchPart.isDirty();
if (!currentEditorDirty) {
workbenchPart.setDirty(true);
}
}
if (flag) {
useProjectSetting();
}
}
use of org.talend.designer.core.ui.editor.AbstractTalendEditor in project tdi-studio-se by Talend.
the class SQLPatternComposite method executeCommand.
/**
* yzhang Comment method "executeCommand".
*
* @param cmd
*/
private void executeCommand(Command cmd) {
if (commandStack == null) {
IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (part instanceof AbstractMultiPageTalendEditor) {
AbstractTalendEditor editor = ((AbstractMultiPageTalendEditor) part).getTalendEditor();
commandStack = (CommandStack) editor.getAdapter(CommandStack.class);
}
}
if (commandStack == null) {
return;
}
commandStack.execute(cmd);
}
Aggregations