List of usage examples for org.eclipse.jface.dialogs MessageDialog getImage
public static Image getImage(String key)
From source file:com.nokia.carbide.cpp.internal.project.ui.editors.images.MultiImageEditorContext.java
License:Open Source License
/** * Save changes to the multi-image source. * <p>/*from ww w .j av a 2 s . co m*/ * If the context was initialized with a null IOperationHistory, * the incoming IMultiImageSource is directly modified. Otherwise, * the change is executed and added as an operation to that history. */ public void doSave() { if (sourceDisposition == SourceDisposition.FROM_VIEW) { // modify through the parent editor's operation history if (editorHistory != null) { // make the save operation for the parent editor IUndoableOperation operation = getEditingOperation(); try { operation.addContext(editorUndoContext); editorHistory.execute(operation, null, null); } catch (ExecutionException e) { ProjectUIPlugin.log(e); } } else { ownedMultiImageSource.set(multiImageSource); } } else { // in this mode, we directly update the view while (true) { try { ownedMultiImageSource.set(multiImageSource); view.commit(); break; } catch (IllegalStateException e) { // rollback or overwrite? ProjectUIPlugin.log(e); MessageDialog dialog = new MessageDialog((Shell) editorContext.getAdapter(Shell.class), Messages.getString("MultiImageEditorContext.ConflictingChangesTitle"), //$NON-NLS-1$ MessageDialog.getImage(MessageDialog.DLG_IMG_MESSAGE_ERROR), MessageFormat.format( Messages.getString("MultiImageEditorContext.ConflictingChangesMessage"), //$NON-NLS-1$ new Object[] { ((IOwnedModel) view.getModel()).getPath() }), MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0); dialog.open(); view.revert(); } } try { getMultiImageSourceWorkaround(); // redraw entire UI this.page.dispose(); createControl(this.parent); this.page.setVisible(true); } catch (PartInitException e) { // just fail -- this is a workaround, after all ProjectUIPlugin.log(e); } } }
From source file:com.ultimatetech.cim.views.CIMInstanceView.java
License:Open Source License
private void makeActions() { setInstanceAct = new Action() { public void run() { //get client CIMClient client = null;/* ww w . java2 s . co m*/ try { client = CIMConnect.connectUsingPreferences(); try { client.setInstance(cimInstance.getObjectPath(), cimInstance, false, (String[]) changedProps.toArray(new String[] {})); showMessage("Set instance successfull"); setInstanceAct.setEnabled(false); } catch (CIMException e) { e.printStackTrace(); ErrorDialog ed = new ErrorDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Set Instance Error", "Set Instance failed:" + e.getMessage(), new Status(Status.ERROR, "CIMPlugin", e.getXmlCode(e.getID()), e.getMessage(), e), IStatus.ERROR); ed.open(); } } finally { if (client != null) { try { client.close(); } catch (CIMException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }; setInstanceAct.setText("Set instance"); setInstanceAct.setToolTipText("Set instance"); setInstanceAct.setImageDescriptor(CIMPlugin.getImageDescriptor("icons/save.gif")); setInstanceAct.setDisabledImageDescriptor(CIMPlugin.getImageDescriptor("icons/save_disabled.gif")); setInstanceAct.setEnabled(false); deleteInstance = new Action() { public void run() { CIMClient client = CIMConnect.connectUsingPreferences(); try { MessageDialog areYouSure = new MessageDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Delete Instance?", MessageDialog.getImage(MessageDialog.DLG_IMG_QUESTION), "Delete this instance?", MessageDialog.QUESTION, new String[] { "OK", "Cancel" }, 0); areYouSure.open(); if (areYouSure.getReturnCode() == MessageDialog.OK) { client.deleteInstance(cimInstance.getObjectPath()); clearView(); CIMExplorerView cev = (CIMExplorerView) PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getActivePage().showView("com.ultimatetech.cim.views.CIMExplorerView"); cev.refreshAllTreeNodes(); } } catch (CIMException e) { ErrorDialog ed = new ErrorDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Delete Instance Error", "Delete instance failed:" + e.getMessage(), new Status(Status.ERROR, "CIMPlugin", e.getXmlCode(e.getID()), e.getMessage(), e), IStatus.ERROR); ed.open(); } catch (Exception e) { ErrorDialog ed = new ErrorDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Delete Instance Error", "Delete instance failed:" + e.getMessage(), new Status(Status.ERROR, "CIMPlugin", 100, e.getMessage(), e), IStatus.ERROR); ed.open(); } finally { if (client != null) { try { client.close(); } catch (CIMException e) { e.printStackTrace(); } } } //showMessage("Delete instance not yet implemented"); } }; deleteInstance.setText("Delete instance"); deleteInstance.setToolTipText("Delete instance"); deleteInstance.setImageDescriptor( PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_ERROR_TSK)); /*doubleClickAction = new Action() { public void run() { ISelection selection = viewer.getSelection(); Object obj = ((IStructuredSelection)selection).getFirstElement(); showMessage("Double-click detected on "+obj.toString()); } };*/ refreshAction = new Action() { public void run() { CIMClient client = CIMConnect.connectUsingPreferences(); try { cimInstance = client.getInstance(cimInstance.getObjectPath(), false, true, true, null); showMessage("Instance reloaded"); } catch (CIMException e) { e.printStackTrace(); ErrorDialog ed = new ErrorDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Reload Instance Error", "Reload Instance failed:" + e.getMessage(), new Status(Status.ERROR, "CIMPlugin", e.getXmlCode(e.getID()), e.getMessage(), e), IStatus.ERROR); ed.open(); } finally { if (client != null) { try { client.close(); } catch (CIMException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } setInstanceAct.setEnabled(false); } }; refreshAction.setText("Reload instance"); refreshAction.setToolTipText("Reload instance"); refreshAction.setImageDescriptor( PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_REDO)); }
From source file:org.eclipse.emf.compare.mpatch.emfdiff2mpatch.actions.CompareAndTransformAction.java
License:Open Source License
/** * Call EMF Compare to create an emfdiff for the given models. * /*from ww w.j av a2s.c o m*/ * @param oldFile * The unchanged version of a model. * @param newFile * The changed version of the same model. * @param shell * The shell for showing dialogs. * @return The emfdiff in case of successful differencing or <code>null</code> otherwise. */ private static ComparisonSnapshot createComparisonSnapshot(final IFile oldFile, final IFile newFile, Shell shell) { ComparisonResourceSnapshot emfdiff = null; try { // get resources final ResourceSet resourceSet = new ResourceSetImpl(); final Resource oldResource = resourceSet .getResource(URI.createFileURI(oldFile.getFullPath().toString()), true); final Resource newResource = resourceSet .getResource(URI.createFileURI(newFile.getFullPath().toString()), true); if (oldResource.getContents().size() != 1) throw new IllegalArgumentException( oldFile.getFullPath() + " is expected to contain exactly one root model element, but " + oldResource.getContents().size() + " elements found!"); if (newResource.getContents().size() != 1) throw new IllegalArgumentException( newFile.getFullPath() + " is expected to contain exactly one root model element, but " + newResource.getContents().size() + " elements found!"); // ask user which is the modified version of the model @SuppressWarnings("deprecation") final MessageDialog dialog = new MessageDialog(shell, "Please select the modified model", MessageDialog.getImage(Dialog.DLG_IMG_QUESTION), "Please select the file which contains the MODIFIED version:", MessageDialog.QUESTION, new String[] { newFile.getName(), oldFile.getName() }, 0); final int dialogResult = dialog.open(); if (dialogResult == SWT.DEFAULT) return null; // use emf compare to compute differences final EObject oldModel = (dialogResult == 0 ? oldResource : newResource).getContents().get(0); final EObject newModel = (dialogResult == 0 ? newResource : oldResource).getContents().get(0); emfdiff = CommonUtils.createEmfdiff(newModel, oldModel); if (emfdiff != null) return emfdiff; throw new IllegalArgumentException("EMF Compare failed to compute differences."); } catch (Exception e) { final String message = "Could not create differences with EMF Compare."; Emfdiff2mpatchActivator.getDefault().logError(message, e); MessageDialog.openError(shell, "Could not create differences with EMF Compare!", message + " See error log for details.\n" + "Error message: " + e.getMessage()); return null; } }