use of org.talend.designer.core.ui.editor.AbstractTalendEditor in project tdi-studio-se by Talend.
the class JavaCodeProblemsChecker method retrieveDetailedProblems.
/**
* DOC amaumont Comment method "retrieveDetailedProblems".
*
* @return
*/
private List<DetailedProblem> retrieveDetailedProblems(final IAloneProcessNodeConfigurer nodeConfigurer) {
final ArrayList<DetailedProblem> iproblems = new ArrayList<DetailedProblem>();
final IWorkbench workbench = PlatformUI.getWorkbench();
Display display = workbench.getDisplay();
if (display != null) {
display.syncExec(new Runnable() {
public void run() {
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
IEditorPart editorPart = page.getActiveEditor();
if (editorPart instanceof AbstractMultiPageTalendEditor) {
AbstractMultiPageTalendEditor multiPageTalendEditor = ((AbstractMultiPageTalendEditor) editorPart);
AbstractTalendEditor talendEditor = multiPageTalendEditor.getTalendEditor();
TalendJavaEditor codeEditor = (TalendJavaEditor) multiPageTalendEditor.getCodeEditor();
org.eclipse.jdt.core.ICompilationUnit compilationUnit = (org.eclipse.jdt.core.ICompilationUnit) codeEditor.getUnit();
IProcess process = talendEditor.getProcess();
if (AbstractProcessProvider.isExtensionProcessForJoblet(process)) {
// joblet
return;
}
String selectedNodeName = multiPageTalendEditor.getSelectedNodeName();
if (selectedNodeName == null) {
return;
}
String uniqueNodeName = null;
boolean found = false;
List<? extends INode> generatingNodes = process.getGeneratingNodes();
int generatingNodesListSize = generatingNodes.size();
for (int i = 0; i < generatingNodesListSize; i++) {
INode node = generatingNodes.get(i);
/* startsWith method used in case of virtual component such as 'tMap_1_TMAP_OUT' */
if (node.getUniqueName().equals(selectedNodeName) || node.getUniqueName().startsWith(selectedNodeName + "_")) {
//$NON-NLS-1$
uniqueNodeName = node.getUniqueName();
found = true;
break;
}
}
if (!found) {
// in case the component doesn't exist
return;
}
final String code = retrieveCode(process, uniqueNodeName, nodeConfigurer);
// System.out.println(code);
// create requestor for accumulating discovered problems
MyProblemRequestor problemRequestor = new MyProblemRequestor(code, iproblems, selectedNodeName);
// use working copy to hold source with error
org.eclipse.jdt.core.ICompilationUnit workingCopy = null;
try {
JavaProcessorUtilities.computeLibrariesPath(process.getNeededModules(false), process);
try {
WorkingCopyOwner workingCopyOwner = new WorkingCopyOwner() {
};
workingCopy = ((org.eclipse.jdt.core.ICompilationUnit) compilationUnit).getWorkingCopy(workingCopyOwner, problemRequestor, null);
problemRequestor.setReportProblems(true);
((IOpenable) workingCopy).getBuffer().setContents(code);
((org.eclipse.jdt.core.ICompilationUnit) workingCopy).reconcile(ICompilationUnit.NO_AST, true, null, null);
problemRequestor.setReportProblems(false);
} finally {
if (workingCopy != null) {
workingCopy.discardWorkingCopy();
}
}
} catch (JavaModelException e) {
ExceptionHandler.process(e);
} catch (CoreException e) {
ExceptionHandler.process(e);
}
}
}
});
}
return iproblems;
}
use of org.talend.designer.core.ui.editor.AbstractTalendEditor 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.AbstractTalendEditor 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