List of usage examples for org.eclipse.jface.dialogs MessageDialog open
public int open()
From source file:de.loskutov.anyedit.actions.SaveToFileAction.java
License:Open Source License
/** * @param file/*from w w w .j ava2s . com*/ * non null * @return OVERRIDE if file not exists or exists and may be overriden, APPEND if it * exists and should be reused, CANCEL if action should be cancelled */ private int checkForExisting(File file) { if (file.exists()) { MessageDialog md = new MessageDialog(AnyEditToolsPlugin.getShell(), Messages.SaveTo_ShouldOpen, null, Messages.SaveTo_FileExists, MessageDialog.WARNING, new String[] { Messages.SaveTo_Append, Messages.SaveTo_Override, "Cancel" }, 0); int result = md.open(); switch (result) { case APPEND: // Append btn index return APPEND; case OVERRIDE: // Override btn index return OVERRIDE; default: return CANCEL; } } return OVERRIDE; }
From source file:de.loskutov.eclipse.jdepend.views.SaveToFileAction.java
License:Open Source License
/** * @param file/*from w w w . j av a 2s .c o m*/ * non null * @return OVERRIDE if file not exists or exists and may be overriden, APPEND if it * exists and should be reused, CANCEL if action should be cancelled */ private int checkForExisting(File file) { if (file.exists()) { MessageDialog md = new MessageDialog(getShell(), "Warning: file already exist", null, "Warning: file already exist", MessageDialog.WARNING, new String[] { "Append", "Override", "Cancel" }, 0); int result = md.open(); switch (result) { case APPEND: // Append btn index return APPEND; case OVERRIDE: // Override btn index return OVERRIDE; default: return CANCEL; } } return OVERRIDE; }
From source file:de.ovgu.featureide.examples.wizards.ExampleNewWizardPage.java
License:Open Source License
/** * The <code>WizardDataTransfer</code> implementation of this * <code>IOverwriteQuery</code> method asks the user whether the existing * resource at the given path should be overwritten. * /*from ww w .j a v a 2s. c o m*/ * @param pathString * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>, * <code>"ALL"</code>, or <code>"CANCEL"</code> */ public String queryOverwrite(String pathString) { Path path = new Path(pathString); String messageString; // Break the message up if there is a file name and a directory // and there are at least 2 segments. if (path.getFileExtension() == null || path.segmentCount() < 2) { messageString = pathString + " already exists. Would you like to overwrite it?"; } else { messageString = "Overwrite " + path.lastSegment() + " in folder " + path.removeLastSegments(1).toOSString() + " ?"; } final MessageDialog dialog = new MessageDialog(getContainer().getShell(), "Question", null, messageString, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL, IDialogConstants.CANCEL_LABEL }, 0); // run in syncExec because callback is from an operation, // which is probably not running in the UI thread. getControl().getDisplay().syncExec(new Runnable() { public void run() { dialog.open(); } }); return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()]; }
From source file:de.ovgu.featureide.fm.ui.editors.featuremodel.operations.DeleteAllOperation.java
License:Open Source License
@Override public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { featureList = new LinkedList<Feature>(); containedFeatureList = new LinkedList<Feature>(); LinkedList<Feature> list = new LinkedList<Feature>(); list.add(feature);// w w w . j a v a 2s. c om getFeaturesToDelete(list); if (containedFeatureList.isEmpty()) { for (Feature feat : featureList) { AbstractFeatureModelOperation op = new FeatureDeleteOperation(featureModel, feat); executeOperation(op); operations.add(op); } } else { final String containedFeatures = containedFeatureList.toString(); MessageDialog dialog = new MessageDialog(new Shell(), " Delete Error ", FEATURE_SYMBOL, "The following features are contained in constraints:" + '\n' + containedFeatures.substring(1, containedFeatures.length() - 1) + '\n' + '\n' + "Unable to delete this features until all relevant constraints are removed.", MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0); dialog.open(); } return Status.OK_STATUS; }
From source file:de.ovgu.featureide.fm.ui.editors.featuremodel.operations.DeleteOperation.java
License:Open Source License
/** * Opens an error dialog displaying the {@link Feature}s which could not be replaced by alternatives. * @param notDeletable The not deletable features *//*from w w w. j av a 2 s . c o m*/ private void openErrorDialog(List<Feature> notDeletable) { String notDeletedFeatures = null; for (Feature f : notDeletable) { if (notDeletedFeatures == null) { notDeletedFeatures = "\"" + f.getName() + "\""; } else { notDeletedFeatures += ", \"" + f.getName() + "\""; } } MessageDialog dialog = new MessageDialog(new Shell(), " Delete Error ", FEATURE_SYMBOL, ((notDeletable.size() != 1) ? "The following features are contained in constraints:" : "The following feature is contained in constraints:") + "\n" + notDeletedFeatures + "\n" + ((notDeletable.size() != 1) ? "Select only one feature in order to replace it with an equivalent one." : "It can not be replaced with an equivalent one."), MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0); dialog.open(); }
From source file:de.ovgu.featureide.fm.ui.editors.featuremodel.operations.ElementDeleteOperation.java
License:Open Source License
/** * Opens an error dialog displaying the {@link Feature}s which could not be replaced by alternatives. * //from w ww . j av a 2 s . co m * @param notDeletable The not deletable features */ private void openErrorDialog(List<IFeature> notDeletable) { String notDeletedFeatures = null; for (IFeature f : notDeletable) { if (notDeletedFeatures == null) { notDeletedFeatures = "\"" + f.getName() + "\""; } else { notDeletedFeatures += ", \"" + f.getName() + "\""; } } MessageDialog dialog = new MessageDialog(new Shell(), DELETE_ERROR, FEATURE_SYMBOL, ((notDeletable.size() != 1) ? "The following features are contained in constraints:" : "The following feature is contained in constraints:") + "\n" + notDeletedFeatures + "\n" + ((notDeletable.size() != 1) ? SELECT_ONLY_ONE_FEATURE_IN_ORDER_TO_REPLACE_IT_WITH_AN_EQUIVALENT_ONE_ : IT_CAN_NOT_BE_REPLACED_WITH_AN_EQUIVALENT_ONE_), MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0); dialog.open(); }
From source file:de.ovgu.featureide.fm.ui.editors.featuremodel.operations.FeatureTreeDeleteOperation.java
License:Open Source License
@Override protected void createSingleOperations() { featureList = new LinkedList<IFeature>(); containedFeatureList = new LinkedList<IFeature>(); LinkedList<IFeature> list = new LinkedList<IFeature>(); list.add(feature);// www . j av a 2 s . com getFeaturesToDelete(list); if (containedFeatureList.isEmpty()) { for (IFeature feat : featureList) { AbstractFeatureModelOperation op = new DeleteFeatureOperation(featureModel, feat); operations.add(op); } } else { final String containedFeatures = containedFeatureList.toString(); MessageDialog dialog = new MessageDialog(new Shell(), DELETE_ERROR, FEATURE_SYMBOL, "The following features are contained in constraints:" + '\n' + containedFeatures.substring(1, containedFeatures.length() - 1) + '\n' + '\n' + UNABLE_TO_DELETE_THIS_FEATURES_UNTIL_ALL_RELEVANT_CONSTRAINTS_ARE_REMOVED_, MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0); dialog.open(); } }
From source file:de.ovgu.featureide.fm.ui.GraphicsExporter.java
License:Open Source License
public static boolean exportAs(GraphicalViewerImpl viewer, File file) { boolean succ = false; if (file.getAbsolutePath().endsWith(".svg")) { ScalableFreeformRootEditPart part = (ScalableFreeformRootEditPart) viewer.getEditPartRegistry() .get(LayerManager.ID);/*from w w w.jav a2 s . c om*/ IFigure rootFigure = part.getFigure(); Bundle bundleExportSVG = null; for (Bundle b : InternalPlatform.getDefault().getBundleContext().getBundles()) { if (b.getSymbolicName().equals("nl.utwente.ce.imageexport.svg")) { bundleExportSVG = b; break; } } // check if gef-imageexport is existing and activated! if (bundleExportSVG != null) { try { org.osgi.framework.BundleActivator act = ((org.osgi.framework.BundleActivator) bundleExportSVG .loadClass("nl.utwente.ce.imagexport.export.svg.Activator").newInstance()); act.start(InternalPlatform.getDefault().getBundleContext()); Class<?> cl = bundleExportSVG.loadClass("nl.utwente.ce.imagexport.export.svg.ExportSVG"); Method m = cl.getMethod("exportImage", String.class, String.class, IFigure.class); m.invoke(cl.newInstance(), "SVG", file.getAbsolutePath(), rootFigure); succ = true; } catch (Exception e) { FMUIPlugin.getDefault().logError(e); } } else { final String infoMessage = "Eclipse plugin for exporting diagram in SVG format is not existing." + "\nIf you want to use this, you have to install GEF Imageexport with SVG in Eclipse from " + "\nhttp://veger.github.com/eclipse-gef-imageexport"; MessageDialog dialog = new MessageDialog(new Shell(), "SVG export failed", FMUIPlugin.getImage("FeatureIconSmall.ico"), infoMessage, MessageDialog.INFORMATION, new String[] { IDialogConstants.OK_LABEL }, 0); dialog.open(); FMUIPlugin.getDefault().logInfo(infoMessage); return false; } } else { GEFImageWriter.writeToFile(viewer, file); succ = true; } GraphicsExporter.printExportMessage(file, succ); return succ; }
From source file:de.ovgu.featureide.ui.statistics.core.CsvExporter.java
License:Open Source License
/** * Puts the description of each selected node in the first row as header and * it's value in the second row./*from w ww. j ava 2s . co m*/ * */ private void actualExport() { Job job = new Job("Export statistics into csv") { private StringBuilder firstBuffer; private StringBuilder secondBuffer; @Override protected IStatus run(IProgressMonitor monitor) { List<String> descs = new LinkedList<String>(); List<String> vals = new LinkedList<String>(); getExportData(descs, vals); firstBuffer = new StringBuilder(); secondBuffer = new StringBuilder(); prepareDataForExport(descs, vals, firstBuffer, secondBuffer); return actualWriting(); } /** * @param firstBuffer * @param secondBuffer * @return */ private IStatus actualWriting() { BufferedWriter writer = null; if (!returnVal.endsWith(".csv")) { returnVal += ".csv"; } File file = new File(returnVal); try { if (!file.exists()) { file.createNewFile(); } writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))); writer.write(firstBuffer.toString()); writer.newLine(); writer.write(secondBuffer.toString()); } catch (FileNotFoundException e) { giveUserFeedback(true); return Status.CANCEL_STATUS; } catch (IOException e) { UIPlugin.getDefault().logError(e); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { UIPlugin.getDefault().logError(e); } } } giveUserFeedback(false); return Status.OK_STATUS; } /** * */ private void giveUserFeedback(final boolean error) { UIJob errorJob = new UIJob(error ? "show errordialog" : "show dialog") { @Override public IStatus runInUIThread(IProgressMonitor monitor) { Shell shell = Display.getDefault().getActiveShell(); if (error) { MessageDialog dial = new MessageDialog(shell, "Error", GUIDefaults.FEATURE_SYMBOL, "The file cannot be accessed!\nTry again?", MessageDialog.ERROR, new String[] { "OK", "Cancel" }, 0); if (dial.open() == 0) { actualWriting(); } } else { // MessageDialog.openInformation(shell, , // "Data was successfully exported."); new MessageDialog(shell, "Success", GUIDefaults.FEATURE_SYMBOL, "Data was successfully exported", MessageDialog.INFORMATION, new String[] { "OK" }, 0).open(); } return Status.OK_STATUS; } }; errorJob.setPriority(INTERACTIVE); errorJob.schedule(); } /** * @param descs * @param vals * @param buffer * @param secBuf */ private void prepareDataForExport(List<String> descs, List<String> vals, StringBuilder buffer, StringBuilder secBuf) { for (String desc : descs) { buffer.append(desc); buffer.append(SEPARATOR); } for (String val : vals) { secBuf.append(val); secBuf.append(SEPARATOR); } } /** * @param descs * @param vals */ private void getExportData(List<String> descs, List<String> vals) { descs.add("Description: "); vals.add("Value: "); Parent last = null; for (Object o : visibleExpandedElements) { if (o instanceof Parent) { Parent parent = ((Parent) o); if (parent.getParent().equals(last)) { int end = descs.size() - 1; descs.set(end, descs.get(end) + ":"); } descs.add(parent.getDescription()); vals.add(parent.getValue() != null ? parent.getValue().toString() : ""); last = parent; } } } }; job.setPriority(Job.SHORT); job.schedule(); }
From source file:de.ovgu.featureide.ui.views.collaboration.action.DeleteAction.java
License:Open Source License
public void run() { MessageDialog messageDialog = new MessageDialog(null, "Delete Resources", null, "Are you sure you want to remove " + getDialogText(), MessageDialog.INFORMATION, new String[] { "OK", "Cancel" }, 0); if (messageDialog.open() != 0) { return;//ww w. j ava 2s . c om } if (part instanceof RoleEditPart) { Role role = ((RoleEditPart) part).getRoleModel(); try { role.getRoleFile().delete(true, null); } catch (CoreException e) { UIPlugin.getDefault().logError(e); } } else if (part instanceof ClassEditPart) { Class c = ((ClassEditPart) part).getClassModel(); List<Role> roles = c.getRoles(); for (Role role : roles) { //if (part != null) try { role.getRoleFile().delete(true, null); } catch (CoreException e) { UIPlugin.getDefault().logError(e); } } } else if (part instanceof CollaborationEditPart) { Collaboration coll = ((CollaborationEditPart) part).getCollaborationModel(); for (Role role : coll.getRoles()) { try { role.getRoleFile().delete(true, null); } catch (CoreException e) { UIPlugin.getDefault().logError(e); } } } }