use of org.eclipse.gef.commands.CommandStack in project archi-modelrepository-plugin by archi-contribs.
the class GraficoModelImporter method importAsModel.
/**
* Import the grafico XML files as a IArchimateModel
* @throws IOException
*/
public IArchimateModel importAsModel() throws IOException {
// Create folders for model and images
File modelFolder = new File(fLocalRepoFolder, IGraficoConstants.MODEL_FOLDER);
modelFolder.mkdirs();
File imagesFolder = new File(fLocalRepoFolder, IGraficoConstants.IMAGES_FOLDER);
imagesFolder.mkdirs();
// If the top folder.xml does not exist then there is nothing to import, so return null
if (!(new File(modelFolder, IGraficoConstants.FOLDER_XML)).isFile()) {
return null;
}
// Reset the ID -> Object lookup table
fIDLookup = new HashMap<String, IIdentifier>();
// Load the Model from files (it will contain unresolved proxies)
fModel = loadModel(modelFolder);
// Create a new Resource for the model object so we can work with it in the ModelCompatibility class
Resource resource = new XMLResourceImpl();
resource.getContents().add(fModel);
// Resolve proxies
resolveProxies();
// New model compatibility
ModelCompatibility modelCompatibility = new ModelCompatibility(resource);
// And then the ModelCompatibility won't be able to tell the version number
try {
modelCompatibility.fixCompatibility();
} catch (CompatibilityHandlerException ex) {
// $NON-NLS-1$
ModelRepositoryPlugin.INSTANCE.log(IStatus.ERROR, "Error loading model", ex);
}
// We now have to remove the Eobject from its Resource so it can be saved in its proper *.archimate format
resource.getContents().remove(fModel);
// Add Archive Manager and CommandStack so we can save the model
IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(fModel);
fModel.setAdapter(IArchiveManager.class, archiveManager);
// TODO: After Archi 4.7 we don't need a CommandStack
CommandStack cmdStack = new CommandStack();
fModel.setAdapter(CommandStack.class, cmdStack);
// Load images
loadImages(imagesFolder, archiveManager);
return fModel;
}
use of org.eclipse.gef.commands.CommandStack in project dbeaver by serge-rider.
the class ExtendedDirectEditManager method commit.
/**
* Commits the current value of the cell editor by getting a {@link Command}
* from the source edit part and executing it via the {@link CommandStack}.
* Finally, {@link #bringDown()}is called to perform and necessary cleanup.
*/
@Override
protected void commit() {
if (committing)
return;
committing = true;
try {
//we set the cell editor control to invisible to remove any
// possible flicker
getCellEditor().getControl().setVisible(false);
if (isDirty()) {
CommandStack stack = getEditPart().getViewer().getEditDomain().getCommandStack();
Command command = getEditPart().getCommand(getDirectEditRequest());
if (command != null && command.canExecute())
stack.execute(command);
}
} finally {
bringDown();
committing = false;
}
}
use of org.eclipse.gef.commands.CommandStack in project tdi-studio-se by Talend.
the class GenericElementParameter method updateSchema.
private void updateSchema() {
IElement element = this.getElement();
if (element instanceof Node) {
Node node = (Node) element;
List<INodeConnector> connectors = node.getConnectorsFromType(EConnectionType.FLOW_MAIN);
for (INodeConnector connector : connectors) {
if (connector instanceof GenericNodeConnector) {
Connector componentConnector = ((GenericNodeConnector) connector).getComponentConnector();
Schema schema = null;
schema = getRootProperties().getSchema(componentConnector, ((GenericNodeConnector) connector).isOutput());
IMetadataTable mainTable = node.getMetadataFromConnector(connector.getName());
if (schema != null && mainTable != null) {
MetadataTable metadataTable = MetadataToolAvroHelper.convertFromAvro(schema);
IMetadataTable newTable = MetadataToolHelper.convert(metadataTable);
if (!mainTable.sameMetadataAs(newTable) || !newTable.sameMetadataAs(mainTable)) {
mainTable.setListColumns(newTable.getListColumns());
List<IElementParameter> schemaParameters = node.getElementParametersFromField(EParameterFieldType.SCHEMA_REFERENCE);
updateSchemaParameters(schemaParameters, connector.getName(), schema);
if (this.askPropagate == null && node.getOutgoingConnections().size() != 0) {
boolean hasPropagation = false;
for (IConnection connection : node.getOutgoingConnections()) {
if (connector.getName().equals(connection.getConnectorName())) {
if (isSchemaPropagated(connection.getTarget())) {
hasPropagation = true;
break;
}
}
}
if (hasPropagation) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
askPropagate = ChangeMetadataCommand.askPropagate();
}
});
}
}
if (this.askPropagate != null && this.askPropagate) {
for (IConnection connection : node.getOutgoingConnections()) {
if (connector.getName().equals(connection.getConnectorName())) {
INode target = connection.getTarget();
if (!isSchemaPropagated(target)) {
continue;
}
ChangeMetadataCommand cmd = new ChangeMetadataCommand(target, null, null, newTable, null);
cmd.setPropagate(true);
IProcess process = node.getProcess();
if (process instanceof org.talend.designer.core.ui.editor.process.Process) {
CommandStack commandStack = ((org.talend.designer.core.ui.editor.process.Process) process).getCommandStack();
commandStack.execute(cmd);
}
}
}
}
}
}
}
}
this.askPropagate = null;
}
}
use of org.eclipse.gef.commands.CommandStack in project tdi-studio-se by Talend.
the class ProcessLayoutEditPolicy method getConnectionAndEndCommands.
protected Command getConnectionAndEndCommands(CreateConnectionRequest request) {
CompoundCommand cc = new CompoundCommand("CreateNodeCommand");
ProcessPart processPart = (ProcessPart) this.getHost();
final GraphicalViewer graphicalViewer = (GraphicalViewer) processPart.getViewer();
final CommandStack commandStack = processPart.getViewer().getEditDomain().getCommandStack();
final String categoryName = ComponentsFactoryProvider.getInstance().getComponentsHandler().extractComponentsCategory().getName();
final IProcess2 process = (IProcess2) processPart.getModel();
TalendEditorConnectionTargetAssist assist = new TalendEditorConnectionTargetAssist(categoryName, graphicalViewer, commandStack, process);
char start = '*';
assist.showComponentCreationAssist(start);
ConnectionCreateCommand cmd = (ConnectionCreateCommand) request.getStartCommand();
if (assist.getComponentName() == null) {
assist.releaseText();
return cmd;
}
IComponent component = TalendEditorComponentCreationUtil.getComponentsInCategory(categoryName).get(assist.getComponentName());
if (component == null) {
assist.releaseText();
return cmd;
}
assist.releaseText();
Node newNode = new Node(component);
NodeContainer nodeContainer = ((Process) newNode.getProcess()).loadNodeContainer(newNode, false);
CreateNodeContainerCommand command = new CreateNodeContainerCommand((org.talend.designer.core.ui.editor.process.Process) newNode.getProcess(), nodeContainer, request.getLocation());
cc.add(command);
cmd.setTarget(newNode);
cc.add(cmd);
return cc;
}
use of org.eclipse.gef.commands.CommandStack in project tdi-studio-se by Talend.
the class MapperUI method closeMapperDialog.
public void closeMapperDialog(int response) {
mapperResponse = response;
if (response == SWT.OK || response == SWT.APPLICATION_MODAL) {
prepareClosing(response);
mapperComponent.setExternalEmfData(copyOfMapData);
if (response == SWT.APPLICATION_MODAL) {
IExternalNode externalNode = mapperComponent;
IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (externalNode != null && (part instanceof AbstractMultiPageTalendEditor)) {
INode node = externalNode.getOriginalNode();
if (node != null && node instanceof Node) {
Command cmd = new ExternalNodeChangeCommand((Node) node, externalNode);
CommandStack cmdStack = (CommandStack) part.getAdapter(CommandStack.class);
cmdStack.execute(cmd);
}
}
}
IElementParameter elementParameter = mapperComponent.getElementParameter("DIE_ON_ERROR");
if (elementParameter != null) {
elementParameter.setValue(mapperManager.isDieOnError());
}
}
if (response == SWT.OK) {
closeWithoutPrompt = true;
}
if (response == SWT.OK || response == SWT.CANCEL) {
mapperShell.close();
}
}
Aggregations