Example usage for org.eclipse.jface.dialogs MessageDialog openConfirm

List of usage examples for org.eclipse.jface.dialogs MessageDialog openConfirm

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs MessageDialog openConfirm.

Prototype

public static boolean openConfirm(Shell parent, String title, String message) 

Source Link

Document

Convenience method to open a simple confirm (OK/Cancel) dialog.

Usage

From source file:ca.mcgill.cs.swevo.qualyzer.handlers.DeleteProjectHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    CommonNavigator view = (CommonNavigator) page.findView(QualyzerActivator.PROJECT_EXPLORER_VIEW_ID);
    ISelection selection = view.getCommonViewer().getSelection();
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

    if (selection != null && selection instanceof IStructuredSelection) {
        for (Object element : ((IStructuredSelection) selection).toArray()) {
            if (element instanceof IProject) {
                boolean confirm = fTesting || MessageDialog.openConfirm(shell,
                        Messages.getString("handler.DeleteProjectHandler.deleteProject"), //$NON-NLS-1$
                        Messages.getString("handler.DeleteProjectHandler.confirm")); //$NON-NLS-1$

                if (confirm) {
                    Project project = PersistenceManager.getInstance()
                            .getProject(((IProject) element).getName());
                    Facade.getInstance().deleteProject(project);
                }// w  w  w  . j av a 2s  .c  om
            }
        }
    }

    return null;
}

From source file:cane.brothers.e4.commander.handlers.ExitHandler.java

License:Open Source License

@Execute
public void execute(IWorkbench workbench, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell) {
    if (MessageDialog.openConfirm(shell, "Confirmation", //$NON-NLS-1$
            "Do you want to exit?")) { //$NON-NLS-1$
        workbench.close();//  w  w  w  .j  ava2  s . c  o  m
    }
}

From source file:carisma.modeltype.bpmn2.popup.ConvertYaoqiangAction.java

License:Open Source License

/**
 * @see IActionDelegate#run(IAction)/*  w  w w. j a v a2  s  . co  m*/
 */
@Override
public final void run(final IAction action) {
    if (this.selectedFile != null) {
        String ext = "." + this.selectedFile.getFileExtension();
        String name = this.selectedFile.getName().substring(0, this.selectedFile.getName().indexOf(ext));
        String updatedName = name;
        String path = this.selectedFile.getLocation().toString().substring(0,
                this.selectedFile.getLocation().toString().indexOf(name));
        String outputfile = "";

        if (name.length() > ConvertEmfAction.SUFFIX.length()
                && name.substring(name.length() - ConvertEmfAction.SUFFIX.length(), name.length())
                        .equals(ConvertEmfAction.SUFFIX)) {
            updatedName = name.substring(0, name.length() - ConvertEmfAction.SUFFIX.length());
        }
        if (!updatedName.contains(SUFFIX)) {
            outputfile = Utils.incrementFileNameIfNecessary(path + updatedName + SUFFIX + ".bpmn2");
        } else {
            outputfile = Utils.incrementFileNameIfNecessary(path + updatedName + ".bpmn2");
        }
        if (!YaoqiangHelper.isYaoqiangModel(path + name + ext)) {
            if (MessageDialog.openConfirm(this.shell, "CARiSMA",
                    "Model seems not be a Yaonqiang Model. Still start transformation?")) {
                startYaoqiangTransformation(path + name + ext, outputfile);
            }
        } else {
            startYaoqiangTransformation(path + name + ext, outputfile);
        }
    } else {
        MessageDialog.openError(this.shell, "Carisma", "No file selected!");
    }
    // refresh resources
    try {
        IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
        IProject[] projects = workspaceRoot.getProjects();
        for (IProject projectToRefresh : projects) {
            projectToRefresh.refreshLocal(IResource.DEPTH_INFINITE, null);
        }
    } catch (CoreException e) {
        Logger.log(LogLevel.ERROR, "could not refresh resource");
    }
}

From source file:ccw.editors.clojure.EvaluateTextUtil.java

License:Open Source License

/**
 * Verifies if all is OK. Currently, that just means that if the file is not
 * saved, we ask the user for the permission to save the file and continue
 * @return true if it is ok to do the action, false if the action is cancelled
 *//*  www  . jav a  2 s  . com*/
public static boolean canProceed(IEditorPart editor, String title, String message) {
    if (editor.isDirty()) {
        boolean saveAndCompileLoad = MessageDialog.openConfirm(editor.getSite().getShell(), title, message);
        if (saveAndCompileLoad) {
            editor.getSite().getWorkbenchWindow().getActivePage().saveEditor(editor, false);
            return true;
        } else {
            return false;
        }
    } else {
        return true;
    }
}

From source file:ccw.launching.ClojureLaunchShortcut.java

License:Open Source License

private boolean userConfirmsNewLaunch(final IProject project, final int nb) {
    final boolean[] ret = new boolean[1];
    final String title = "Clojure Application Launcher";
    final String msg = (nb == 1 ? "A" : nb) + " REPL" + (nb == 1 ? " is" : "s are")
            + " already running for this project. Changes you made can "
            + "be evaluated in an existing REPL (see Clojure menu). "
            + "\n\nAre you sure you want to start up another REPL for this project?\n"
            + "(Cancel will open existing REPL)";
    DisplayUtil.syncExec(new Runnable() {
        public void run() {
            Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
            ret[0] = MessageDialog.openConfirm(shell, title, msg);
        }//from  w w  w  . ja va 2  s . c o  m
    });
    return ret[0];
}

From source file:ch.elexis.core.ui.contacts.dialogs.PatientErfassenDialog.java

License:Open Source License

@Override
protected void okPressed() {
    final String[] ret = new String[8];
    ret[0] = tName.getText();/*  w w w. j av a2s.com*/
    ret[1] = tVorname.getText();
    int idx = cbSex.getSelectionIndex();
    if (idx == -1) {
        char sex = cbSex.getText().charAt(0);
        if (sex == 'w' || sex == 'W' || sex == 'f' || sex == 'F') {
            idx = 1;
        } else if (sex == 'm' || sex == 'M') {
            idx = 0;
        }
    }
    if (idx == -1) {
        SWTHelper.showError("Bitte Geschlecht angeben", "Die Angabe des Geschlechts ist erforderlich");
        return;
    }
    ret[2] = cbSex.getItem(idx);
    ret[3] = tGebDat.getText();
    try {
        TimeTool check = null;
        if (!StringTool.isNothing(ret[3])) {
            check = new TimeTool(ret[3], true);
        }
        ret[4] = tStrasse.getText();
        ret[5] = tPlz.getText();
        ret[6] = tOrt.getText();
        ret[7] = tTel.getText();
        Query<Kontakt> qbe = new Query<Kontakt>(Kontakt.class);
        qbe.add("Bezeichnung1", Query.EQUALS, ret[0], true);
        qbe.add("Bezeichnung2", Query.EQUALS, ret[1], true);
        if (check != null)
            qbe.add(Person.BIRTHDATE, Query.EQUALS, check.toDBString(false), true);
        List<Kontakt> list = qbe.execute();
        if ((list != null) && (!list.isEmpty())) {
            Kontakt k = list.get(0);
            if (k.istPerson()) {
                k.set(Kontakt.FLD_IS_PATIENT, StringConstants.ONE);
                if (MessageDialog.openConfirm(getShell(), Messages.PatientErfassenDialog_personExists,
                        Messages.PatientErfassenDialog_personWithThisNameExists) == false) { //$NON-NLS-1$ //$NON-NLS-2$
                    // abort dialog
                    super.cancelPressed();
                    return;
                }
            }
        }
        result = new Patient(ret[0], ret[1], check, ret[2]);
        AcquireLockUi.aquireAndRun(result, new ILockHandler() {

            @Override
            public void lockFailed() {
                result.delete();
            }

            @Override
            public void lockAcquired() {
                result.set(new String[] { Kontakt.FLD_STREET, Kontakt.FLD_ZIP, Kontakt.FLD_PLACE,
                        Kontakt.FLD_PHONE1 }, new String[] { ret[4], ret[5], ret[6], ret[7] });

                ElexisEventDispatcher.fireSelectionEvent(result);
            }
        });
        super.okPressed();
    } catch (TimeFormatException e) {
        ExHandler.handle(e);
        SWTHelper.showError("Falsches Datumsformat", "Das Geburtsdatum kann nicht interpretiert werden");
        return;
    } catch (PersonDataException pe) {
        ExHandler.handle(pe);
        SWTHelper.showError("Unplausible Angaben", "Bitte berprfen Sie die Eingaben nochmals.");
    }
}

From source file:ch.elexis.core.ui.contacts.views.PatientMenuPopulator.java

License:Open Source License

PatientMenuPopulator(PatientenListeView plv, final StructuredViewer structuredViewer) {
    mine = plv;//  ww w.ja  va2 s .co  m
    stickerAction = new RestrictedAction(AccessControlDefaults.KONTAKT_ETIKETTE,
            Messages.PatientMenuPopulator_StickerAction) { // $NON-NLS-1$
        {
            setToolTipText(Messages.PatientMenuPopulator_StickerToolTip); // $NON-NLS-1$
        }

        @Override
        public void doRun() {
            Patient p = mine.getSelectedPatient();
            AssignStickerDialog aed = new AssignStickerDialog(Hub.getActiveShell(), p);
            aed.open();
        }

    };
    delPatAction = new LockRequestingRestrictedAction<Patient>(AccessControlDefaults.KONTAKT_DELETE,
            Messages.PatientMenuPopulator_DeletePatientAction) {

        @Override
        public void doRun(Patient p) {
            if (MessageDialog.openConfirm(mine.getViewSite().getShell(),
                    Messages.PatientMenuPopulator_DeletePatientConfirm, p.getLabel()) == true) {
                if (p.delete(false) == false) {
                    SWTHelper.alert(Messages.PatientMenuPopulator_DeletePatientRejectCaption,
                            Messages.PatientMenuPopulator_DeletePatientRejectBody);
                } else {
                    mine.reload();
                }
            }
        }

        @Override
        public Patient getTargetedObject() {
            StructuredSelection selection = (StructuredSelection) structuredViewer.getSelection();
            if (selection != null) {
                return (Patient) selection.getFirstElement();
            }
            return null;
        }
    };
    exportKGAction = new Action(Messages.PatientMenuPopulator_ExportEMRAction, Action.AS_DROP_DOWN_MENU) { // $NON-NLS-1$
        Menu menu = null;

        {
            setToolTipText(Messages.PatientMenuPopulator_ExportEMRToolTip); // $NON-NLS-1$
            setMenuCreator(new IMenuCreator() {

                public void dispose() {
                    if (menu != null) {
                        menu.dispose();
                        menu = null;
                    }
                }

                public Menu getMenu(Control parent) {
                    menu = new Menu(parent);
                    createMenu();
                    return menu;
                }

                public Menu getMenu(Menu parent) {
                    menu = new Menu(parent);
                    createMenu();
                    return menu;
                }

            });
        }

        void createMenu() {
            Patient p = mine.getSelectedPatient();
            if (p != null) {
                List<IConfigurationElement> list = Extensions
                        .getExtensions(ExtensionPointConstantsUi.TRANSPORTER); // $NON-NLS-1$
                for (final IConfigurationElement ic : list) {
                    // TODO "Acceptable Types" is not part of
                    // ch.elexis.Transporter
                    // never was?! Should we remove this code? - mde
                    String handler = ic.getAttribute("AcceptableTypes"); //$NON-NLS-1$
                    if (handler == null) {
                        continue;
                    }
                    if (handler.contains("ch.elexis.data.Patient") //$NON-NLS-1$
                            || (handler.contains("ch.elexis.data.*"))) { //$NON-NLS-1$
                        MenuItem it = new MenuItem(menu, SWT.NONE);
                        it.setText(ic.getAttribute("name")); //$NON-NLS-1$
                        it.addSelectionListener(new SelectionAdapter() {
                            @Override
                            public void widgetSelected(SelectionEvent e) {
                                Patient pat = mine.getSelectedPatient();
                                try {
                                    IDataSender sender = (IDataSender) ic
                                            .createExecutableExtension("ExporterClass"); //$NON-NLS-1$
                                    sender.store(pat);
                                    sender.finalizeExport();
                                    SWTHelper.showInfo(Messages.PatientMenuPopulator_EMRExported, // $NON-NLS-1$
                                            MessageFormat.format(Messages.PatientMenuPopulator_ExportEmrSuccess, // $NON-NLS-1$
                                                    pat.getLabel()));
                                } catch (CoreException e1) {
                                    ExHandler.handle(e1);
                                } catch (XChangeException xx) {
                                    SWTHelper.showError(Messages.PatientMenuPopulator_ErrorCaption, // $NON-NLS-1$
                                            MessageFormat.format(Messages.PatientMenuPopulator_ExportEmrFailure, // $NON-NLS-1$
                                                    pat.getLabel()));

                                }
                            }
                        });

                    }
                }
            }
        }
    };
}

From source file:ch.elexis.core.ui.dialogs.DocumentSelectDialog.java

License:Open Source License

private void makeActions() {
    deleteTemplateAction = new Action(DELETE_TEMPLATE) {
        @Override/*from w w  w . j a  v a 2s. co  m*/
        public void run() {
            Brief sel = (Brief) ((IStructuredSelection) tv.getSelection()).getFirstElement();
            if (MessageDialog.openConfirm(getShell(), DELETE_TEMPLATE,
                    MessageFormat.format(Messages.DocumentSelectDialog_reallyDeleteTemplate, sel.getBetreff())) //$NON-NLS-1$
            == true) {
                sel.delete();
                tv.refresh();
            }
        }
    };
    deleteTextAction = new Action(DELETE_DOCUMENT) {
        @Override
        public void run() {
            Brief sel = (Brief) ((IStructuredSelection) tv.getSelection()).getFirstElement();
            if (MessageDialog.openConfirm(getShell(), DELETE_DOCUMENT,
                    MessageFormat.format(Messages.DocumentSelectDialog_reallyDeleteDocument, sel.getBetreff())) //$NON-NLS-1$
            == true) {
                sel.set("geloescht", StringConstants.ONE); //$NON-NLS-1$
                tv.refresh();
            }
        }
    };
    editNameAction = new Action(Messages.DocumentSelectDialog_changeSubjectAction) { //$NON-NLS-1$
        @Override
        public void run() {
            Brief sel = (Brief) ((IStructuredSelection) tv.getSelection()).getFirstElement();
            InputDialog inp = new InputDialog(getShell(), Messages.DocumentSelectDialog_changeSubjectAction, //$NON-NLS-1$
                    Messages.DocumentSelectDialog_changeSubjectAction, //$NON-NLS-1$
                    sel.getBetreff(), null);
            int inputResult = inp.open();
            if (inputResult == InputDialog.OK) {
                sel.setBetreff(inp.getValue());
                tv.refresh();
            }
        }
    };
    editDontAskForAddressee = new Action(Messages.DocumentSelectDialog_askForAddressee) { //$NON-NLS-1$
        @Override
        public void run() {
            Brief sel = (Brief) ((IStructuredSelection) tv.getSelection()).getFirstElement();
            setDontAskForAddresseeForThisTemplate(sel, !getDontAskForAddresseeForThisTemplate(sel));
            tv.refresh();
        }
    };
}

From source file:ch.elexis.core.ui.dialogs.KontaktErfassenDialog.java

License:Open Source License

private void createKontakt() {
    String[] ret = new String[8];
    ret[0] = tName.getText();/*from   ww w. j  a  va2s .  c  om*/
    ret[1] = tVorname.getText();
    int idx = cbSex.getSelectionIndex();
    if (idx == -1) {
        SWTHelper.showError(Messages.KontaktErfassenDialog_geschlechtFehlt_title, //$NON-NLS-1$
                Messages.KontaktErfassenDialog_geschlechtFehlt_msg); //$NON-NLS-1$
        return;
    }
    ret[2] = cbSex.getItem(idx);
    ret[3] = tGebDat.getText();
    try {
        if (!StringTool.isNothing(ret[3])) {
            new TimeTool(ret[3], true);
        }
        ret[4] = tStrasse.getText();
        ret[5] = tPlz.getText();
        ret[6] = tOrt.getText();
        ret[7] = tTel.getText();
        if (newKontakt == null) {
            Query<Kontakt> qbe = new Query<Kontakt>(Kontakt.class);
            qbe.add("Bezeichnung1", "=", ret[0]); //$NON-NLS-1$ //$NON-NLS-2$
            qbe.add("Bezeichnung2", "=", ret[1]); //$NON-NLS-1$ //$NON-NLS-2$
            List<Kontakt> list = qbe.execute();
            if ((list != null) && (!list.isEmpty())) {
                Kontakt k = list.get(0);
                if (bOrganisation.getSelection() && k.istOrganisation()) {
                    if (bLabor.getSelection()) {
                        k.set("istOrganisation", "1"); //$NON-NLS-1$ //$NON-NLS-2$
                    }
                    if (MessageDialog.openConfirm(getShell(),
                            Messages.KontaktErfassenDialog_organisationExistiert_title, //$NON-NLS-1$
                            Messages.KontaktErfassenDialog_organisationExistiert_msg) == false) { //$NON-NLS-1$
                        super.okPressed();
                        return;
                    }
                }
                if (k.istPerson()) {
                    if (bAnwender.getSelection()) {
                        k.set("istAnwender", "1"); //$NON-NLS-1$ //$NON-NLS-2$
                    }
                    if (bMandant.getSelection()) {
                        k.set("istMandant", "1"); //$NON-NLS-1$ //$NON-NLS-2$
                    }
                    if (bPatient.getSelection()) {
                        k.set("istPatient", "1"); //$NON-NLS-1$ //$NON-NLS-2$
                    }
                    if (MessageDialog.openConfirm(getShell(),
                            Messages.KontaktErfassenDialog_personExisitiert_title, //$NON-NLS-1$
                            Messages.KontaktErfassenDialog_personExisitiert_msg) == false) { //$NON-NLS-1$
                        super.okPressed();
                        return;
                    }
                }
            }

            /**
             * Neuer Kontakt erstellen. Reihenfolge der Abfrage ist Wichtig, da ein Anwender
             * auch ein Mandant sein kann. "Organisation", - "Labor", "Person" - "Patient" -
             * "Anwender" - "Mandant"
             */
            if (bMandant.getSelection()) {
                newKontakt = new Mandant(ret[0], ret[1], ret[3], ret[2]);
                newKontakt.set("Zusatz", tZusatz.getText()); //$NON-NLS-1$
            } else if (bAnwender.getSelection()) {
                newKontakt = new Anwender(ret[0], ret[1], ret[3], ret[2]);
                newKontakt.set("Zusatz", tZusatz.getText()); //$NON-NLS-1$
            } else if (bPatient.getSelection()) {
                newKontakt = new Patient(ret[0], ret[1], ret[3], ret[2]);
                newKontakt.set("Zusatz", tZusatz.getText()); //$NON-NLS-1$
            } else if (bPerson.getSelection()) {
                newKontakt = new Person(ret[0], ret[1], ret[3], ret[2]);
                newKontakt.set("Zusatz", tZusatz.getText()); //$NON-NLS-1$
            } else if (bLabor.getSelection()) {
                newKontakt = new Labor(ret[0], ret[0]);
                newKontakt.set("Zusatz1", ret[1]); //$NON-NLS-1$
                newKontakt.set("Ansprechperson", tZusatz.getText()); //$NON-NLS-1$
            } else if (bOrganisation.getSelection()) {
                newKontakt = new Organisation(ret[0], ret[1]);
                newKontakt.set("Ansprechperson", tZusatz.getText()); //$NON-NLS-1$
            } else {
                MessageDialog.openInformation(getShell(), Messages.KontaktErfassenDialog_unbekannterTyp_title, //$NON-NLS-1$
                        Messages.KontaktErfassenDialog_unbekannterTyp_msg); //$NON-NLS-1$
                return;
            }
        }
        if (CoreHub.getLocalLockService().acquireLock(newKontakt).isOk()) {
            newKontakt.set(new String[] { "Strasse", "Plz", "Ort", "Telefon1", "Fax", "E-Mail" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
            }, new String[] { ret[4], ret[5], ret[6], ret[7], tFax.getText(), tEmail.getText() });

            ElexisEventDispatcher.fireSelectionEvent(newKontakt);
            CoreHub.getLocalLockService().releaseLock(newKontakt);
        }
    } catch (TimeFormatException e) {
        ExHandler.handle(e);
        SWTHelper.showError(Messages.KontaktErfassenDialog_falschesDatum_title, //$NON-NLS-1$
                Messages.KontaktErfassenDialog_falschesDatum_msg); //$NON-NLS-1$
        return;
    }
}

From source file:ch.elexis.core.ui.eigenleistung.EigenleistungContextMenu.java

License:Open Source License

private void makeActions(final Eigenleistung art) {
    deleteAction = new Action(Messages.EigenleistungContextMenu_deleteAction) {
        {/*from   w w w  .ja  v  a  2  s.c om*/
            setImageDescriptor(Images.IMG_DELETE.getImageDescriptor());
            setToolTipText(art.getClass().getName() + Messages.EigenleistungContextMenu_deleteActionToolTip);
        }

        @Override
        public void run() {
            Eigenleistung act = (Eigenleistung) ElexisEventDispatcher.getSelected(art.getClass());
            if (MessageDialog.openConfirm(cv.getViewerWidget().getControl().getShell(),
                    Messages.EigenleistungContextMenu_deleteActionConfirmCaption,
                    MessageFormat.format(Messages.EigenleistungContextMenu_deleteConfirmBody, act.getText()))) {
                act.delete();
                cv.getConfigurer().getControlFieldProvider().fireChangedEvent();
                cv.notify(CommonViewer.Message.update);
            }

        }
    };
    editAction = new Action(Messages.EigenleistungContextMenu_propertiesAction) {
        {
            setImageDescriptor(Images.IMG_EDIT.getImageDescriptor());
            setToolTipText(Messages.EigenleistungContextMenu_propertiesTooltip);
        }

        @Override
        public void run() {
            Eigenleistung lstg = (Eigenleistung) ElexisEventDispatcher.getSelected(art.getClass());
            EditEigenleistungUi.executeWithParams(lstg);
        }
    };
}