List of usage examples for org.eclipse.jface.dialogs MessageDialog openError
public static void openError(Shell parent, String title, String message)
From source file:ac.soton.multisim.diagram.part.MultisimDocumentProvider.java
License:Open Source License
/** * Persists EventB component./* w ww .j av a2 s .c om*/ * Stores EventBComponent as an extension in a machine. * * @param document * @custom */ private void saveEventB(IDocument document) { ComponentDiagram diagram = (ComponentDiagram) ((IDiagramDocument) document).getDiagram().getElement(); final TransactionalEditingDomain domain = ((IDiagramDocument) document).getEditingDomain(); CompoundCommand compoundCmd = new CompoundCommand(); for (final Component comp : diagram.getComponents()) { if (comp instanceof EventBComponent && ((EventBComponent) comp).getMachine() != null) { // adds command to extend Event-B machine with component config // NOTE: replaces existing extension of the same id compoundCmd.append(new RecordingCommand(domain) { @Override protected void doExecute() { EventBComponent compCopy = (EventBComponent) EcoreUtil.copy(comp); try { Resource resource = domain.getResourceSet().getResource(compCopy.getMachine().getURI(), true); if (resource != null && resource.isLoaded()) { Machine machine = (Machine) resource.getContents().get(0); if (machine == null) return; // remove any existing extensions of the same id (EventB component) Iterator<AbstractExtension> it = machine.getExtensions().iterator(); while (it.hasNext()) { if (MultisimPackage.EXTENSION_ID.equals(it.next().getExtensionId())) { it.remove(); } } // compCopy.setReference(ComponentsPackage.COMPONENTS_EXTENSION_ID // + "." + EcoreUtil.generateUUID()); machine.getExtensions().add(compCopy); resource.save(Collections.EMPTY_MAP); } } catch (IOException e) { MessageDialog.openError(Display.getDefault().getActiveShell(), "Event-B Component", "Failed to save component '" + comp.getName() + "' to its machine."); } } }); } } domain.getCommandStack().execute(compoundCmd); }
From source file:ac.soton.multisim.diagram.part.MultisimInitDiagramFileAction.java
License:Open Source License
/** * @generated//from w ww . jav a2 s . c o m */ public void run(IAction action) { TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE.createEditingDomain(); ResourceSet resourceSet = new ResourceSetImpl(); EObject diagramRoot = null; try { Resource resource = resourceSet.getResource(domainModelURI, true); diagramRoot = (EObject) resource.getContents().get(0); } catch (WrappedException ex) { MultisimDiagramEditorPlugin.getInstance().logError("Unable to load resource: " + domainModelURI, ex); //$NON-NLS-1$ } if (diagramRoot == null) { MessageDialog.openError(getShell(), Messages.InitDiagramFile_ResourceErrorDialogTitle, Messages.InitDiagramFile_ResourceErrorDialogMessage); return; } Wizard wizard = new MultisimNewDiagramFileWizard(domainModelURI, diagramRoot, editingDomain); wizard.setWindowTitle(NLS.bind(Messages.InitDiagramFile_WizardTitle, ComponentDiagramEditPart.MODEL_ID)); MultisimDiagramEditorUtil.runWizard(getShell(), wizard, "InitDiagramFile"); //$NON-NLS-1$ }
From source file:ac.soton.multisim.ui.actions.OpenMachineAction.java
License:Open Source License
@Override public void run(IAction action) { View view = selectedElement.getNotationView(); EventBComponent component = (EventBComponent) view.getElement(); Machine machine = component.getMachine(); //XXX add error marker if (machine == null || machine.eResource() == null) { MessageDialog.openError(Display.getDefault().getActiveShell(), "Machine Failure", "Machine is not set."); return;/* w ww .java 2 s . c o m*/ } // try to open machine in a default editor IWorkbenchPage page = part.getSite().getPage(); IFile file = WorkspaceSynchronizer.getFile(machine.eResource()); IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName()); try { page.openEditor(new FileEditorInput(file), desc.getId()); } catch (PartInitException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:ac.soton.multisim.ui.actions.SetParametersAction.java
License:Open Source License
@Override public void run(IAction action) { final FMUComponent component = (FMUComponent) selectedElement.getNotationView().getElement(); Map<String, Object> componentParams = new HashMap<String, Object>(component.getParameters().size()); for (FMUParameter p : component.getParameters()) componentParams.put(p.getName(), p.getStartValue()); // read model description FMIModelDescription modelDescription = null; if (component.getFmu() != null) { modelDescription = component.getFmu().getModelDescription(); } else {// www.ja v a 2s . c o m if (component.getPath() == null) { MessageDialog.openError(Display.getDefault().getActiveShell(), "Parameters Failure", "FMU path is not set."); return; } try { modelDescription = FMUFile.parseFMUFile(component.getPath()); } catch (IOException e) { MessageDialog.openError(Display.getDefault().getActiveShell(), "Parameters Failure", "Could not read the FMU file '" + component.getPath() + "'."); return; } } // list all the parameters final List<FMUParameter> allParams = new ArrayList<FMUParameter>(modelDescription.modelVariables.size()); Set<FMUParameter> modifiedParams = new HashSet<FMUParameter>(componentParams.size()); for (FMIScalarVariable variable : modelDescription.modelVariables) { if (variable.variability == Variability.parameter) { //XXX according to specification a parameter must also be an input, i.e. variable.causality == Causality.input FMUParameter param = MultisimFactory.eINSTANCE.createFMUParameter(); param.setName(variable.name); param.setCausality(SimulationUtil.fmiGetCausality(variable)); param.setType(SimulationUtil.fmiGetType(variable)); param.setValue(SimulationUtil.fmiGetDefaultValue(variable)); param.setComment(variable.description); allParams.add(param); if (componentParams.containsKey(variable.name)) { param.setStartValue(componentParams.get(variable.name)); modifiedParams.add(param); } else { param.setStartValue(param.getValue()); } } } // display configuration window final FMUParametersDialog dialog = new FMUParametersDialog(Display.getCurrent().getActiveShell(), allParams); dialog.setModified(modifiedParams); dialog.create(); if (Window.OK == dialog.open()) { try { new AbstractEMFOperation(selectedElement.getEditingDomain(), "Set parameters command") { @Override protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { component.getParameters().clear(); component.getParameters().addAll(dialog.getModified()); return null; } }.execute(null, null); } catch (ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:ac.soton.multisim.ui.policies.ComponentCreateCommand.java
License:Open Source License
/** * Imports FMU component from a system File. * //from w w w . java 2s . com * @param fmuFile * @return */ private Component importFMUComponent(File fmuFile) { FMIModelDescription modelDescription; try { modelDescription = FMUFile.parseFMUFile(fmuFile.getAbsolutePath()); if (Double.parseDouble(modelDescription.fmiVersion) != 1d) throw new IOException("Wrong FMI version"); } catch (IOException e) { e.printStackTrace(); Display.getCurrent().asyncExec(new Runnable() { @Override public void run() { MessageDialog.openError(Display.getCurrent().getActiveShell(), "FMU Import Error", "FMU file cannot be parsed.\n" + "Check wether it is corrupt or not supported: only FMI 1.0 for Co-simulation files are supported for import."); } }); return null; } FMUComponent component = MultisimFactory.eINSTANCE.createFMUComponent(); component.setName(modelDescription.modelName); component.setPath(fmuFile.getAbsolutePath()); for (FMIScalarVariable scalarVariable : modelDescription.modelVariables) { if (scalarVariable.causality == Causality.input) { createFMUInput(scalarVariable, component); } else if (scalarVariable.causality == Causality.output) { createFMUOutput(scalarVariable, component); } } return component; }
From source file:ac.soton.multisim.ui.policies.DisplayComponentOpenEditPolicy.java
License:Open Source License
@Override protected Command getOpenCommand(Request request) { final DisplayComponentEditPart part = (DisplayComponentEditPart) getHost(); return new Command() { @Override// w w w . j a va2s . com public void execute() { final DisplayComponent component = (DisplayComponent) part.resolveSemanticElement(); assert component != null; if (component.getChart() == null) { try { component.instantiate(); } catch (SimulationException | ModelException e) { MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Display Error", "Failed to instantiate the Display. See error log for details."); MultisimUIActivator.getDefault().logError("Display instantiation failed", e); return; } } final Chart2D chart = component.getChart(); // display the chart if not visible yet if (!chart.isVisible()) { JPanel container = new JPanel(); container.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); container.setBackground(java.awt.Color.WHITE); container.setLayout(new java.awt.BorderLayout()); container.add(chart, java.awt.BorderLayout.CENTER); final JFrame frame = new JFrame("Display"); frame.getContentPane().add(container); frame.setSize(300, 300); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { frame.dispose(); chart.setVisible(false); } }); chart.setVisible(true); frame.setVisible(true); } } }; }
From source file:ac.soton.rms.components.diagram.part.ComponentsDocumentProvider.java
License:Open Source License
/** * Persists EventB component./* ww w .ja v a 2 s . com*/ * Stores EventBComponent as an extension in a machine. * * @param document * @custom */ private void saveEventB(IDocument document) { ComponentDiagram diagram = (ComponentDiagram) ((IDiagramDocument) document).getDiagram().getElement(); final TransactionalEditingDomain domain = ((IDiagramDocument) document).getEditingDomain(); CompoundCommand compoundCmd = new CompoundCommand(); for (final Component comp : diagram.getComponents()) { if (comp instanceof EventBComponent && ((EventBComponent) comp).getMachine() != null) { // adds command to extend Event-B machine with component config // NOTE: replaces existing extension of the same id compoundCmd.append(new RecordingCommand(domain) { @Override protected void doExecute() { EventBComponent compCopy = (EventBComponent) EcoreUtil.copy(comp); try { Resource resource = domain.getResourceSet().getResource(compCopy.getMachine().getURI(), true); if (resource != null && resource.isLoaded()) { Machine machine = (Machine) resource.getContents().get(0); if (machine == null) return; // remove any existing extensions of the same id (EventB component) Iterator<AbstractExtension> it = machine.getExtensions().iterator(); while (it.hasNext()) { if (ComponentsPackage.COMPONENTS_EXTENSION_ID .equals(it.next().getExtensionId())) { it.remove(); } } // compCopy.setReference(ComponentsPackage.COMPONENTS_EXTENSION_ID // + "." + EcoreUtil.generateUUID()); machine.getExtensions().add(compCopy); resource.save(Collections.EMPTY_MAP); } } catch (IOException e) { MessageDialog.openError(Display.getDefault().getActiveShell(), "Event-B Component", "Failed to save component '" + comp.getLabel() + "' to its machine."); } } }); } } domain.getCommandStack().execute(compoundCmd); }
From source file:ac.soton.rms.components.diagram.part.ComponentsInitDiagramFileAction.java
License:Open Source License
/** * @generated//w w w. j a va 2 s. c o m */ public void run(IAction action) { TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE.createEditingDomain(); ResourceSet resourceSet = new ResourceSetImpl(); EObject diagramRoot = null; try { Resource resource = resourceSet.getResource(domainModelURI, true); diagramRoot = (EObject) resource.getContents().get(0); } catch (WrappedException ex) { ComponentsDiagramEditorPlugin.getInstance().logError("Unable to load resource: " + domainModelURI, ex); //$NON-NLS-1$ } if (diagramRoot == null) { MessageDialog.openError(getShell(), Messages.InitDiagramFile_ResourceErrorDialogTitle, Messages.InitDiagramFile_ResourceErrorDialogMessage); return; } Wizard wizard = new ComponentsNewDiagramFileWizard(domainModelURI, diagramRoot, editingDomain); wizard.setWindowTitle(NLS.bind(Messages.InitDiagramFile_WizardTitle, ComponentDiagramEditPart.MODEL_ID)); ComponentsDiagramEditorUtil.runWizard(getShell(), wizard, "InitDiagramFile"); //$NON-NLS-1$ }
From source file:ac.soton.rms.ui.actions.OpenMachine.java
License:Open Source License
@Override public void run(IAction action) { View view = selectedElement.getNotationView(); EventBComponent component = (EventBComponent) view.getElement(); Machine machine = component.getMachine(); // if machine isn't set, add error marker if (machine == null || machine.eResource() == null) { MessageDialog.openError(Display.getDefault().getActiveShell(), "Machine Failure", "Machine reference is not set."); return;//from w w w .j ava 2 s.c o m } // try to open machine in a default editor IWorkbenchPage page = part.getSite().getPage(); IFile file = WorkspaceSynchronizer.getFile(machine.eResource()); IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName()); try { page.openEditor(new FileEditorInput(file), desc.getId()); } catch (PartInitException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:ac.soton.rms.ui.actions.SetParameters.java
License:Open Source License
@Override public void run(IAction action) { final FMUComponent component = (FMUComponent) selectedElement.getNotationView().getElement(); FMIModelDescription modelDescription = null; // read model description if (component.getFmu() != null) { modelDescription = component.getFmu().getModelDescription(); } else {//from w w w .j av a 2s.co m if (component.getPath() == null) { MessageDialog.openError(Display.getDefault().getActiveShell(), "Parameters Failure", "FMU path is not set."); return; } try { modelDescription = FMUFile.parseFMUFile(component.getPath()); } catch (IOException e) { MessageDialog.openError(Display.getDefault().getActiveShell(), "Parameters Failure", "Could not read the FMU '" + component.getPath() + "' for parameters."); return; } } // list all the parameters final List<FMUParameter> parameters = new ArrayList<FMUParameter>(); if (component.getParameters().isEmpty()) { for (FMIScalarVariable variable : modelDescription.modelVariables) { if (variable.variability == Variability.parameter) { //XXX according to specification a parameter must also be an input, i.e. variable.causality == Causality.input FMUParameter param = ComponentsFactory.eINSTANCE.createFMUParameter(); param.setName(variable.name); param.setCausality(SimulationUtil.fmiGetCausality(variable)); param.setType(SimulationUtil.fmiGetType(variable)); param.setDefaultValue(SimulationUtil.fmiGetDefaultValue(variable)); param.setStartValue(param.getDefaultValue()); param.setDescription(variable.description); parameters.add(param); } } } else { parameters.addAll(EcoreUtil.copyAll(component.getParameters())); } // display configuration window FMUParametersDialog dialog = new FMUParametersDialog(Display.getCurrent().getActiveShell()); dialog.setParameters(parameters); dialog.create(); if (Window.OK == dialog.open()) { try { new AbstractEMFOperation(selectedElement.getEditingDomain(), "Set parameters command") { @Override protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { component.getParameters().clear(); component.getParameters().addAll(parameters); return null; } }.execute(null, null); } catch (ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }