use of org.eclipse.gmf.runtime.notation.Diagram in project tdi-studio-se by Talend.
the class FindAssignmentAction method doRun.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.action.Action#run()
*/
@Override
protected void doRun() {
RepositoryNode repositoryNode = (RepositoryNode) getFirstSelectedObject();
IEditorPart activeEditor = getActiveEditor();
// remove frames draw last time
for (BusinessItemShapeFigure shapFigure : repaintedFigures) {
shapFigure.setDrawFrame(false);
shapFigure.revalidate();
shapFigure.repaint();
}
if (activeEditor instanceof BusinessDiagramEditor) {
BusinessDiagramEditor businessDiagramEditor = (BusinessDiagramEditor) activeEditor;
Diagram diagram = (Diagram) businessDiagramEditor.getDiagramEditPart().getModel();
BusinessProcess businessProcess = (BusinessProcess) diagram.getElement();
// PTODO mhelleboid use OCL or using a visitor
List list = new ArrayList();
for (Iterator iter = businessProcess.getBusinessItems().iterator(); iter.hasNext(); ) {
BusinessItem businessItem = (BusinessItem) iter.next();
for (Iterator iterator = businessItem.getAssignments().iterator(); iterator.hasNext(); ) {
BusinessAssignment businessAssignment = (BusinessAssignment) iterator.next();
TalendItem talendItem = businessAssignment.getTalendItem();
IRepositoryViewObject obj = repositoryNode.getObject();
if (talendItem.getId().equals(repositoryNode.getId())) {
list.add(businessItem);
} else if (talendItem instanceof SQLPattern || talendItem instanceof Routine || talendItem instanceof TableMetadata || talendItem instanceof Query || talendItem instanceof SapFunctionMetadata) {
if (talendItem.getLabel().equals(repositoryNode.getProperties(EProperties.LABEL))) {
list.add(businessItem);
}
}
}
}
IDiagramGraphicalViewer diagramGraphicalViewer = businessDiagramEditor.getDiagramGraphicalViewer();
List editParts = new ArrayList();
for (Iterator iter = list.iterator(); iter.hasNext(); ) {
BusinessItem businessItem = (BusinessItem) iter.next();
editParts.addAll(diagramGraphicalViewer.findEditPartsForElement(EMFCoreUtil.getProxyID(businessItem), BaseBusinessItemRelationShipEditPart.class));
editParts.addAll(diagramGraphicalViewer.findEditPartsForElement(EMFCoreUtil.getProxyID(businessItem), BusinessItemShapeEditPart.class));
}
diagramGraphicalViewer.deselectAll();
// add a frame when use findAassignment
for (Iterator iter = editParts.iterator(); iter.hasNext(); ) {
EditPart editPart = (EditPart) iter.next();
if (editPart instanceof BusinessItemShapeEditPart) {
BusinessItemShapeEditPart shapEditPart = (BusinessItemShapeEditPart) editPart;
IFigure figure = shapEditPart.getFigure();
for (Object child : figure.getChildren()) {
if (child instanceof BusinessItemShapeFigure) {
BusinessItemShapeFigure shapFigure = (BusinessItemShapeFigure) child;
shapFigure.setDrawFrame(true);
shapFigure.revalidate();
shapFigure.repaint();
repaintedFigures.add(shapFigure);
}
}
}
diagramGraphicalViewer.getSelectionManager().appendSelection(editPart);
}
ZoomManager zoomManager = (ZoomManager) businessDiagramEditor.getAdapter(ZoomManager.class);
zoomFitSelection(zoomManager, editParts, businessDiagramEditor.getDiagramEditPart(), true);
}
}
use of org.eclipse.gmf.runtime.notation.Diagram in project tdi-studio-se by Talend.
the class BusinessNewDiagramFileWizard method performFinish.
/**
* @generated
*/
public boolean performFinish() {
IFile diagramFile = myFileCreationPage.createNewFile();
try {
//$NON-NLS-1$
diagramFile.setCharset("UTF-8", new NullProgressMonitor());
} catch (CoreException e) {
//$NON-NLS-1$
BusinessDiagramEditorPlugin.getInstance().logError("Unable to set charset for diagram file", e);
}
ResourceSet resourceSet = myEditingDomain.getResourceSet();
final Resource diagramResource = resourceSet.createResource(URI.createPlatformResourceURI(diagramFile.getFullPath().toString()));
List affectedFiles = new LinkedList();
affectedFiles.add(mySelectedModelFile);
affectedFiles.add(diagramFile);
AbstractTransactionalCommand command = new AbstractTransactionalCommand(myEditingDomain, //$NON-NLS-1$
"Initializing diagram contents", //$NON-NLS-1$
affectedFiles) {
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
int diagramVID = BusinessVisualIDRegistry.getDiagramVisualID(myDiagramRoot);
if (diagramVID != BusinessProcessEditPart.VISUAL_ID) {
//$NON-NLS-1$
return CommandResult.newErrorCommandResult("Incorrect model object stored as a root resource object");
}
Diagram diagram = ViewService.createDiagram(myDiagramRoot, BusinessProcessEditPart.MODEL_ID, BusinessDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
diagramResource.getContents().add(diagram);
diagramResource.getContents().add(diagram.getElement());
return CommandResult.newOKCommandResult();
}
};
try {
OperationHistoryFactory.getOperationHistory().execute(command, new NullProgressMonitor(), null);
diagramResource.save(Collections.EMPTY_MAP);
IDE.openEditor(myWorkbenchPage, diagramFile);
} catch (ExecutionException e) {
//$NON-NLS-1$
BusinessDiagramEditorPlugin.getInstance().logError("Unable to create model and diagram", e);
} catch (IOException ex) {
BusinessDiagramEditorPlugin.getInstance().logError("Save operation failed for: " + diagramFile.getFullPath().toString(), //$NON-NLS-1$
ex);
} catch (PartInitException ex) {
//$NON-NLS-1$
BusinessDiagramEditorPlugin.getInstance().logError("Unable to open editor", ex);
}
return true;
}
use of org.eclipse.gmf.runtime.notation.Diagram in project tdi-studio-se by Talend.
the class ClipboardActionHandler method getCommand.
@Override
public ICommand getCommand(IGlobalActionContext cntxt) {
IWorkbenchPart part = cntxt.getActivePart();
if (!(part instanceof IDiagramWorkbenchPart)) {
return null;
}
IDiagramWorkbenchPart workbenchPart = (IDiagramWorkbenchPart) part;
DiagramEditPart diagramEditPart = workbenchPart.getDiagramEditPart();
ICommand command = null;
String actionId = cntxt.getActionId();
if (actionId.equals(GlobalActionId.COPY)) {
command = getCopyCommand(cntxt, workbenchPart, false);
transfer(cntxt.getSelection());
isCut = false;
older = workbenchPart;
orginalCopyFrom = workbenchPart;
clonedSourceProcessItemsList = new ArrayList<BusinessItem>(((BusinessProcess) ((Diagram) diagramEditPart.getModel()).getElement()).getBusinessItems());
} else if (actionId.equals(GlobalActionId.CUT) && cntxt.getSelection() != null) {
saveCut(cntxt.getSelection());
command = getCutCommand(cntxt, workbenchPart);
transfer(cntxt.getSelection());
isCut = true;
older = workbenchPart;
clonedSourceProcessItemsList = new ArrayList<BusinessItem>(((BusinessProcess) ((Diagram) diagramEditPart.getModel()).getElement()).getBusinessItems());
} else if (actionId.equals(GlobalActionId.SAVE)) {
if (workbenchPart instanceof IEditorPart) {
IEditorPart editorPart = (IEditorPart) workbenchPart;
if (editorPart.isDirty()) {
IWorkbenchPage page = editorPart.getSite().getPage();
page.saveEditor(editorPart, false);
}
}
}
if (actionId.equals(GlobalActionId.PASTE)) {
// diagramPart.getDiagramGraphicalViewer().setSelection(new
// StructuredSelection(diagramPart.getDiagramEditPart()));
PasteViewRequest pasteReq = createPasteViewRequest();
CommandStack cs = workbenchPart.getDiagramEditDomain().getDiagramCommandStack();
IStructuredSelection selection = (IStructuredSelection) cntxt.getSelection();
if (!(selection.getFirstElement() instanceof BusinessProcessEditPart)) {
selection = new StructuredSelection(workbenchPart.getDiagramEditPart());
}
Object[] objects = selection.toArray();
Collection returnValues = null;
if (objects.length == 1) {
Command paste = ((EditPart) objects[0]).getCommand(pasteReq);
if (paste != null) {
cs.execute(paste);
workbenchPart.getDiagramEditPart().getFigure().invalidate();
workbenchPart.getDiagramEditPart().getFigure().validate();
returnValues = DiagramCommandStack.getReturnValues(paste);
// selectAddedObject(diagramPart.getDiagramGraphicalViewer(), returnValues);
}
}
Object elements = TemplateTransfer.getInstance().getObject();
if (elements instanceof List) {
List<BusinessItem> list = (List<BusinessItem>) elements;
boolean inEditors = false;
if (older != workbenchPart) {
inEditors = true;
} else if (!this.isCut && orginalCopyFrom != workbenchPart) {
// bug 16065 fixed, by xtan. to resolve the copy(A)/parse(B)/parse(B)/parse(B)... problem.
inEditors = true;
}
// always keep the last one as the current selection.
older = workbenchPart;
GmfPastCommand pastBusiness = new GmfPastCommand((BusinessProcess) ((Diagram) diagramEditPart.getModel()).getElement(), list, diagramEditPart, this.cutItemIds, this.isCut | inEditors);
pastBusiness.setClonedSourceProcessItemsList(clonedSourceProcessItemsList);
try {
pastBusiness.execute(null, null);
} catch (ExecutionException e) {
ExceptionHandler.process(e);
}
}
if (returnValues != null) {
selectAddedObject(workbenchPart.getDiagramGraphicalViewer(), returnValues);
}
return null;
}
return command;
}
use of org.eclipse.gmf.runtime.notation.Diagram in project tdi-studio-se by Talend.
the class BusinessDiagramEditorUtil method createNewDiagramFile.
/**
* <p>
* This method should be called within a workspace modify operation since it creates resources.
* </p>
*
* @generated
* @return the created file resource, or <code>null</code> if the file was not created
*/
public static final IFile createNewDiagramFile(DiagramFileCreator diagramFileCreator, IPath containerFullPath, String fileName, InputStream initialContents, String kind, Shell shell, IProgressMonitor progressMonitor) {
TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE.createEditingDomain();
ResourceSet resourceSet = editingDomain.getResourceSet();
//$NON-NLS-1$
progressMonitor.beginTask("Creating diagram and model files", 4);
final IProgressMonitor subProgressMonitor = new SubProgressMonitor(progressMonitor, 1);
final IFile diagramFile = diagramFileCreator.createNewFile(containerFullPath, fileName, initialContents, shell, new IRunnableContext() {
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException {
runnable.run(subProgressMonitor);
}
});
final Resource diagramResource = resourceSet.createResource(URI.createPlatformResourceURI(diagramFile.getFullPath().toString()));
List affectedFiles = new ArrayList();
affectedFiles.add(diagramFile);
final String kindParam = kind;
AbstractTransactionalCommand command = new AbstractTransactionalCommand(editingDomain, //$NON-NLS-1$
"Creating diagram and model", //$NON-NLS-1$
affectedFiles) {
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
BusinessProcess model = createInitialModel();
diagramResource.getContents().add(model);
Diagram diagram = ViewService.createDiagram(model, kindParam, BusinessDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
if (diagram != null) {
diagramResource.getContents().add(diagram);
diagram.setName(diagramFile.getName());
diagram.setElement(model);
}
try {
diagramResource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
BusinessDiagramEditorPlugin.getInstance().logError("Unable to store model and diagram resources", //$NON-NLS-1$
e);
}
return CommandResult.newOKCommandResult();
}
};
try {
OperationHistoryFactory.getOperationHistory().execute(command, new SubProgressMonitor(progressMonitor, 1), null);
} catch (ExecutionException e) {
//$NON-NLS-1$
BusinessDiagramEditorPlugin.getInstance().logError("Unable to create model and diagram", e);
}
try {
//$NON-NLS-1$
diagramFile.setCharset("UTF-8", new SubProgressMonitor(progressMonitor, 1));
} catch (CoreException e) {
//$NON-NLS-1$
BusinessDiagramEditorPlugin.getInstance().logError("Unable to set charset for diagram file", e);
}
return diagramFile;
}
use of org.eclipse.gmf.runtime.notation.Diagram in project tdi-studio-se by Talend.
the class BusinessModelingAssistantProvider method selectExistingElement.
/**
* @generated
*/
protected EObject selectExistingElement(IAdaptable host, Collection types) {
if (types.isEmpty()) {
return null;
}
IGraphicalEditPart editPart = (IGraphicalEditPart) host.getAdapter(IGraphicalEditPart.class);
if (editPart == null) {
return null;
}
Diagram diagram = (Diagram) editPart.getRoot().getContents().getModel();
Collection elements = new HashSet();
for (Iterator it = diagram.getElement().eAllContents(); it.hasNext(); ) {
EObject element = (EObject) it.next();
if (isApplicableElement(element, types)) {
elements.add(element);
}
}
if (elements.isEmpty()) {
return null;
}
return selectElement((EObject[]) elements.toArray(new EObject[elements.size()]));
}
Aggregations