List of usage examples for org.eclipse.jface.dialogs MessageDialog open
public int open()
From source file:ac.soton.fmusim.components.ui.actions.DeleteDiagramAction.java
License:Open Source License
@Override public void run() { if (!(site.getStructuredViewer().getSelection().isEmpty())) { IStructuredSelection ssel = (IStructuredSelection) site.getStructuredViewer().getSelection(); Object element = ssel.getFirstElement(); // TODO: add support for multiple files if (element instanceof IAdaptable) { View view = (View) ((IAdaptable) element).getAdapter(View.class); Resource resource = view.eResource(); if (resource != null && resource.isLoaded()) { IFile file = WorkspaceSynchronizer.getFile(resource); MessageDialog dialog = new MessageDialog(site.getViewSite().getShell(), "Confirm Diagram Delete", null, "Are you sure you want to delete the diagram file '" + file.getName() + "' from the project '" + file.getParent().getName() + "' ?", MessageDialog.QUESTION, new String[] { "Yes", "No" }, 0); if (dialog.open() == 0) { Resource domResource = view.getElement().eResource(); try { closeOpenedEditor(file); file.delete(false, false, new NullProgressMonitor()); WorkspaceSynchronizer.getFile(domResource).delete(false, false, new NullProgressMonitor()); } catch (PartInitException e) { e.printStackTrace(); } catch (CoreException e) { e.printStackTrace(); }//from w w w .j a va 2 s . c o m } } } } // MULTIPLE FILES HANDLING (from Systerel's ActionCollection) // // // Putting the selection into a set which does not contains any pair // // of parent and child // Collection<IRodinElement> set = new ArrayList<IRodinElement>(); // // IStructuredSelection ssel = (IStructuredSelection) site.getStructuredViewer().getSelection(); // // for (Iterator<?> it = ssel.iterator(); it.hasNext();) { // final Object obj = it.next(); // if (!(obj instanceof IRodinElement)) { // continue; // } // IRodinElement elem = (IRodinElement) obj; // if (elem.isRoot()) { // elem = elem.getParent(); // } // set = UIUtils.addToTreeSet(set, elem); // } // // int answer = YesToAllMessageDialog.YES; // for (IRodinElement element : set) { // if (element instanceof IRodinFile) { // if (answer != YesToAllMessageDialog.YES_TO_ALL) { // answer = YesToAllMessageDialog.openYesNoToAllQuestion( // site.getViewSite().getShell(), // "Confirm File Delete", // "Are you sure you want to delete file '" // + ((IRodinFile) element) // .getElementName() // + "' in project '" // + element.getParent().getElementName() // + "' ?"); // } // if (answer == YesToAllMessageDialog.NO_TO_ALL) // break; // // if (answer != YesToAllMessageDialog.NO) { // try { // closeOpenedEditor((IRodinFile) element); // ((IRodinFile) element).delete(true, // new NullProgressMonitor()); // } catch (PartInitException e) { // MessageDialog.openError(null, "Error", "Could not delete file"); // } catch (RodinDBException e) { // MessageDialog.openError(null, "Error", "Could not delete file"); // } // } // } // } }
From source file:ac.soton.multisim.ui.actions.DeleteDiagramAction.java
License:Open Source License
@Override public void run() { if (!(site.getStructuredViewer().getSelection().isEmpty())) { IStructuredSelection ssel = (IStructuredSelection) site.getStructuredViewer().getSelection(); Object element = ssel.getFirstElement(); if (element instanceof IAdaptable) { View view = (View) ((IAdaptable) element).getAdapter(View.class); Resource resource = view.eResource(); if (resource != null && resource.isLoaded()) { IFile file = WorkspaceSynchronizer.getFile(resource); MessageDialog dialog = new MessageDialog(site.getViewSite().getShell(), "Confirm Diagram Delete", null, "Are you sure you want to delete the diagram file '" + file.getName() + "' from the project '" + file.getParent().getName() + "' ?", MessageDialog.QUESTION, new String[] { "Yes", "No" }, 0); if (dialog.open() == 0) { Resource domResource = view.getElement().eResource(); try { closeOpenedEditor(file); file.delete(false, false, new NullProgressMonitor()); WorkspaceSynchronizer.getFile(domResource).delete(false, false, new NullProgressMonitor()); } catch (PartInitException e) { e.printStackTrace(); } catch (CoreException e) { e.printStackTrace(); }/*from w w w . ja v a 2 s.c o m*/ } } } } }
From source file:ac.soton.xeventb.ui.AbstractXEventBActionProvider.java
License:Open Source License
/** * Provides a delete action for IXEventBNavigatorObject * Deletes the xtext as well as the corresponding Event-B files * // w w w .ja va2 s . c o m * @param site * The information for the action provider * @return A delete action */ public Action getDeleteAction(final ICommonActionExtensionSite site) { final Action doubleClickAction = new Action("Delete") { @Override public void run() { try { final ISelection selection = site.getStructuredViewer().getSelection(); final Object obj = ((IStructuredSelection) selection).getFirstElement(); if ((obj instanceof IXEventBNavigatorObject)) { final IFile resource = ((IXEventBNavigatorObject) obj).getResource(); String name = resource.getName(); int _length = name.length(); int _minus = (_length - 1); name = name.substring(0, _minus); IPath path = resource.getLocation(); path = path.removeLastSegments(1); path = path.addTrailingSeparator().append(name); final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IFile ifile = workspace.getRoot().getFileForLocation(path); final Shell shell = site.getViewSite().getShell(); String _name = resource.getName(); String _plus = ("Are you sure you want to delete \"" + _name); final String msg = (_plus + "\" and its corresponding Event-B files?"); final String[] options = { "Yes to All", "Yes", "No" }; final MessageDialog dialog = new MessageDialog(shell, "Confirm Delete", null, msg, MessageDialog.CONFIRM, options, 0); final int result = dialog.open(); if ((result == 0)) { resource.delete(true, null); ifile.delete(true, null); } else { if ((result == 1)) { resource.delete(true, null); } } } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } } }; return doubleClickAction; }
From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.wizard.clazz.NewHtmlTemplateWizard.java
License:Open Source License
@Override protected IFile createFile() { IPath path;// w w w. jav a2s .co m IPackageFragment fragment = getDomainClass().getPackageFragment(); if (fragment != null) { String cuName = getDomainClass().getName() + JavaFXUIPlugin.FILEEXTENSION_HTML_TEMPLATE; path = fragment.getPath().append(cuName); } else { String cuName = getDomainClass().getName() + JavaFXUIPlugin.FILEEXTENSION_HTML_TEMPLATE; IFolder p = (IFolder) getDomainClass().getFragmentRoot().getResource(); path = p.getLocation().append(cuName); } // If the path already exists then confirm overwrite. IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); if (file.exists()) { String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }; String question = NLS.bind(IDEWorkbenchMessages.SaveAsDialog_overwriteQuestion, path.toString()); MessageDialog d = new MessageDialog(getShell(), IDEWorkbenchMessages.Question, null, question, MessageDialog.QUESTION, buttons, 0) { protected int getShellStyle() { return super.getShellStyle() | SWT.SHEET; } }; int overwrite = d.open(); switch (overwrite) { case 0: // Yes break; case 1: // No return null; case 2: // Cancel default: return null; } } return file; }
From source file:be.ibridge.kettle.trans.step.BaseStepDialog.java
License:LGPL
/** * Gets unused fields from previous steps and inserts them as rows into a table view. * @param row the input fields// w ww . j a v a 2 s. c o m * @param tableView the table view to modify * @param keyColumn the column in the table view to match with the names of the fields, checks for existance if >0 * @param nameColumn the column numbers in which the name should end up in * @param dataTypeColumn the target column numbers in which the data type should end up in * @param lengthColumn the length column where the length should end up in (if >0) * @param precisionColumn the length column where the precision should end up in (if >0) * @param listener A listener that you can use to do custom modifications to the inserted table item, based on a value from the provided row */ public static final void getFieldsFromPrevious(Row row, TableView tableView, int keyColumn, int nameColumn[], int dataTypeColumn[], int lengthColumn, int precisionColumn, TableItemInsertListener listener) { if (row == null || row.size() == 0) return; // nothing to do Table table = tableView.table; // get a list of all the non-empty keys (names) // List keys = new ArrayList(); for (int i = 0; i < table.getItemCount(); i++) { TableItem tableItem = table.getItem(i); String key = tableItem.getText(keyColumn); if (!Const.isEmpty(key) && keys.indexOf(key) < 0) keys.add(key); } int choice = 0; if (keys.size() > 0) { // Ask what we should do with the existing data in the step. // MessageDialog md = new MessageDialog(tableView.getShell(), Messages.getString("BaseStepDialog.GetFieldsChoice.Title"), //"Warning!" null, Messages.getString("BaseStepDialog.GetFieldsChoice.Message", "" + keys.size(), "" + row.size()), MessageDialog.WARNING, new String[] { Messages.getString("BaseStepDialog.AddNew"), Messages.getString("BaseStepDialog.Add"), Messages.getString("BaseStepDialog.ClearAndAdd"), Messages.getString("BaseStepDialog.Cancel"), }, 0); int idx = md.open(); choice = idx & 0xFF; } if (choice == 3 || choice == 255 /* 255 = escape pressed */) return; // Cancel clicked if (choice == 2) { tableView.clearAll(false); } for (int i = 0; i < row.size(); i++) { Value v = row.getValue(i); boolean add = true; if (choice == 0) // hang on, see if it's not yet in the table view { if (keys.indexOf(v.getName()) >= 0) add = false; } if (add) { TableItem tableItem = new TableItem(table, SWT.NONE); for (int c = 0; c < nameColumn.length; c++) { tableItem.setText(nameColumn[c], Const.NVL(v.getName(), "")); } for (int c = 0; c < dataTypeColumn.length; c++) { tableItem.setText(dataTypeColumn[c], v.getTypeDesc()); } if (lengthColumn > 0) { if (v.getLength() >= 0) tableItem.setText(lengthColumn, Integer.toString(v.getLength())); } if (precisionColumn > 0) { if (v.getPrecision() >= 0) tableItem.setText(precisionColumn, Integer.toString(v.getPrecision())); } if (listener != null) { if (!listener.tableItemInserted(tableItem, v)) { tableItem.dispose(); // remove it again } } } } tableView.removeEmptyRows(); tableView.setRowNums(); tableView.optWidth(true); }
From source file:ca.mcgill.sable.soot.launching.DavaHandler.java
License:Open Source License
private boolean createSpecialDavaProject(IPath jreLibPath) { IWorkbenchWindow window = SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow(); MessageDialog create = new MessageDialog(window.getShell(), Messages.getString("DavaHandler.Soot_Question"), null,/*from ww w. ja v a 2s . c om*/ Messages.getString( "DavaHandler.Would_you_like_to_create_a_new_Dava_Project_with_generated_Dava_src_files"), 0, new String[] { Messages.getString("DavaHandler.OK"), Messages.getString("DavaHandler.Cancel") }, 0); create.open(); if (create.getReturnCode() == Dialog.OK) { // create proj IProject proj = SootPlugin.getWorkspace().getRoot().getProject(getDavaProjName()); if (!proj.exists()) { try { proj.create(null); proj.open(null); IProjectDescription pd = proj.getDescription(); String[] natures = new String[] { Messages.getString("org.eclipse.jdt.core.javanature") }; pd.setNatureIds(natures); proj.setDescription(pd, null); setDavaProj(JavaCore.create(proj)); IFolder folder = proj.getFolder(Messages.getString("DavaHandler.src")); //$NON-NLS-1$ if (!folder.exists()) { folder.create(false, true, null); } setSrcFolder(folder); IFolder out = proj.getFolder(Messages.getString("DavaHandler.bin")); //$NON-NLS-1$ if (!folder.exists()) { folder.create(false, true, null); } getDavaProj().setOutputLocation(out.getFullPath(), null); IClasspathEntry[] entries = new IClasspathEntry[2]; entries[0] = JavaCore.newSourceEntry(folder.getFullPath()); if (jreLibPath != null) { entries[1] = JavaCore.newContainerEntry(jreLibPath); } getDavaProj().setRawClasspath(entries, null); return true; } catch (CoreException e) { e.printStackTrace(); return false; } } } return false; }
From source file:ca.mcgill.sable.soot.launching.DavaHandler.java
License:Open Source License
private boolean shouldCopyFiles() { IWorkbenchWindow window = SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow(); MessageDialog copy = new MessageDialog(window.getShell(), Messages.getString("DavaHandler.Soot_Question"), //$NON-NLS-1$ null, Messages.getString("DavaHandler.Would_you_like_to_copy_Dava_src_files_to_the_Dava_Project"), //$NON-NLS-1$ 0, new String[] { Messages.getString("DavaHandler.OK"), Messages.getString("DavaHandler.Cancel") }, //$NON-NLS-1$//$NON-NLS-2$ 0);// w w w .j av a 2 s .c o m copy.open(); if (copy.getReturnCode() == Dialog.OK) return true; return false; }
From source file:ca.mcgill.sable.soot.launching.SootFileLauncher.java
License:Open Source License
private void handleSourceFile(ICompilationUnit cu) { IPackageFragmentRoot pfr = (IPackageFragmentRoot) cu.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); IPackageFragment pf = (IPackageFragment) cu.getAncestor(IJavaElement.PACKAGE_FRAGMENT); if (isSrcPrec() && getSrcPrec().equals("java")) { setClasspathAppend(platform_location + pfr.getPath().toOSString()); } else {/* w ww . ja v a 2 s. c o m*/ try { IProject proj = cu.getJavaProject().getProject(); IFolder output = proj.getFolder(cu.getJavaProject().getOutputLocation().lastSegment()); IPackageFragment pkf = (IPackageFragment) cu.getAncestor(IJavaElement.PACKAGE_FRAGMENT); IFile exists = null; if (pkf.isDefaultPackage()) { exists = output.getFile(removeFileExt(cu.getElementName()) + ".class"); } else { IFolder pkg = output.getFolder(dotsToSlashes(pf.getElementName())); exists = pkg.getFile(removeFileExt(cu.getElementName()) + ".class"); } if (!exists.exists()) { window = SootPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow(); MessageDialog noClassFound = new MessageDialog(window.getShell(), "Soot Information", null, "No underlying class file was found, maybe build project.", 0, new String[] { "OK" }, 0); noClassFound.open(); setDoNotContinue(true); } setClasspathAppend(platform_location + cu.getJavaProject().getOutputLocation().toOSString()); } catch (CoreException e) { } } addJars(); if (pf.isDefaultPackage()) { getToProcessList().add(removeFileExt(cu.getElementName())); } else { getToProcessList().add(pf.getElementName() + "." + removeFileExt(cu.getElementName())); } }
From source file:ca.mcgill.sable.soot.launching.SootFileLauncher.java
License:Open Source License
private void handleClassFile(IFile file) { ClassFile cf = new ClassFile(file.getLocation().toOSString()); FileInputStream fis = null;// w ww .j a v a 2 s .co m try { fis = new FileInputStream(file.getLocation().toOSString()); } catch (FileNotFoundException e) { } if (!cf.loadClassFile(fis)) { MessageDialog noClassFound = new MessageDialog(window.getShell(), "Soot Information", null, "Could not determine package for class file will not continue.", 0, new String[] { "OK" }, 0); noClassFound.open(); setDoNotContinue(true); } getToProcessList().add(replaceWithDot(cf.toString())); setClasspathAppend(file.getLocation().toOSString().substring(0, file.getLocation().toOSString().indexOf(cf.toString()))); addJars(); }
From source file:ca.mcgill.sable.soot.ui.SootConfigManagerDialog.java
License:Open Source License
private void deletePressed() { if (getSelected() == null) return;/*from w w w. j a v a2s . c o m*/ String result = this.getSelected(); // maybe ask if they are sure here first MessageDialog msgDialog = new MessageDialog(this.getShell(), Messages.getString("SootConfigManagerDialog.Soot_Configuration_Remove_Message"), null, //$NON-NLS-1$ Messages.getString("SootConfigManagerDialog.Are_you_sure_you_want_to_remove_this_configuration"), 0, //$NON-NLS-1$ new String[] { Messages.getString("SootConfigManagerDialog.Yes"), //$NON-NLS-1$ Messages.getString("SootConfigManagerDialog.No") }, //$NON-NLS-1$ 0); msgDialog.open(); if (msgDialog.getReturnCode() == 0) { // do the delete ArrayList toRemove = new ArrayList(); toRemove.add(result); SavedConfigManager scm = new SavedConfigManager(); scm.setDeleteList(toRemove); scm.handleDeletes(); // remove also from tree getTreeRoot().removeChild(result); refreshTree(); } }