use of org.eclipse.core.runtime.IAdaptable in project tdi-studio-se by Talend.
the class BusinessProcessCanonicalEditPolicy method createConnections.
/**
* @generated
*/
private Collection createConnections(Collection linkDescriptors) {
if (linkDescriptors.isEmpty()) {
return Collections.EMPTY_LIST;
}
List adapters = new LinkedList();
for (Iterator linkDescriptorsIterator = linkDescriptors.iterator(); linkDescriptorsIterator.hasNext(); ) {
final LinkDescriptor nextLinkDescriptor = (LinkDescriptor) linkDescriptorsIterator.next();
EditPart sourceEditPart = getEditPartFor(nextLinkDescriptor.getSource());
EditPart targetEditPart = getEditPartFor(nextLinkDescriptor.getDestination());
if (sourceEditPart == null || targetEditPart == null) {
continue;
}
CreateConnectionViewRequest.ConnectionViewDescriptor descriptor = new CreateConnectionViewRequest.ConnectionViewDescriptor(nextLinkDescriptor.getSemanticAdapter(), null, ViewUtil.APPEND, false, ((IGraphicalEditPart) getHost()).getDiagramPreferencesHint());
CreateConnectionViewRequest ccr = new CreateConnectionViewRequest(descriptor);
ccr.setType(RequestConstants.REQ_CONNECTION_START);
ccr.setSourceEditPart(sourceEditPart);
sourceEditPart.getCommand(ccr);
ccr.setTargetEditPart(targetEditPart);
ccr.setType(RequestConstants.REQ_CONNECTION_END);
Command cmd = targetEditPart.getCommand(ccr);
if (cmd != null && cmd.canExecute()) {
executeCommand(cmd);
IAdaptable viewAdapter = (IAdaptable) ccr.getNewObject();
if (viewAdapter != null) {
adapters.add(viewAdapter);
}
}
}
return adapters;
}
use of org.eclipse.core.runtime.IAdaptable 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.core.runtime.IAdaptable 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.core.runtime.IAdaptable in project tdi-studio-se by Talend.
the class TalendConnectionCreationTool method selectAddedObject.
protected void selectAddedObject(EditPartViewer viewer, Collection objects) {
final List editparts = new ArrayList();
final EditPart[] primaryEP = new EditPart[1];
for (Iterator i = objects.iterator(); i.hasNext(); ) {
Object object = i.next();
if (object instanceof IAdaptable) {
Object editPart = viewer.getEditPartRegistry().get(((IAdaptable) object).getAdapter(View.class));
if (editPart instanceof GraphicalEditPart) {
editparts.add(editPart);
}
}
}
if (!editparts.isEmpty()) {
viewer.setSelection(new StructuredSelection(editparts));
// automatically put the first shape into edit-mode
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
if (primaryEP[0] == null) {
primaryEP[0] = (EditPart) editparts.get(0);
}
// code is being executed. (see RATLC00527114)
if (primaryEP[0].isActive()) {
primaryEP[0].performRequest(new Request("direct edit"));
}
}
});
}
}
use of org.eclipse.core.runtime.IAdaptable in project tdi-studio-se by Talend.
the class AbstractSection method setInput.
@Override
public void setInput(IWorkbenchPart part, ISelection selection) {
super.setInput(part, selection);
Assert.isTrue(selection instanceof IStructuredSelection);
Object input = ((IStructuredSelection) selection).getFirstElement();
if (!(input instanceof RepositoryNode)) {
if (input instanceof IAdaptable) {
// see ProcessPart.getAdapter()
IAdaptable adaptable = (IAdaptable) input;
input = adaptable.getAdapter(RepositoryNode.class);
}
}
Assert.isTrue(input instanceof RepositoryNode);
repositoryNode = (RepositoryNode) input;
repositoryObject = repositoryNode.getObject();
if (repositoryObject == null) {
repositoryObject = new EmptyRepositoryObject();
enableControls(false);
showControls(false);
return;
}
manageLock();
ERepositoryObjectType type = repositoryObject.getRepositoryObjectType();
showControls(type != ERepositoryObjectType.METADATA_CON_TABLE);
}
Aggregations