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:com.liferay.ide.project.ui.upgrade.animated.CustomJspPage.java

License:Open Source License

private String getLiferay62ServerLocation() {
    String liferay62ServerLocation = dataModel.getLiferay62ServerLocation().content(true);

    if (liferay62ServerLocation == null) {
        Set<IRuntime> liferayRuntimes = ServerUtil.getAvailableLiferayRuntimes();

        for (IRuntime liferayRuntime : liferayRuntimes) {
            if (liferayRuntime.getRuntimeType().getId().startsWith("com.liferay.ide.server.62.")) {
                liferay62ServerLocation = liferayRuntime.getLocation().removeLastSegments(1).toString();
                return liferay62ServerLocation;
            }//w w  w  . j av a2  s  .c  om
        }

        if (liferay62ServerLocation == null) {
            Boolean openAddLiferaryServerDialog = MessageDialog.openConfirm(UIUtil.getActiveShell(),
                    "Could not find Liferay 6.2 Runtime",
                    "This process requires Liferay 6.2 Runtime. " + "Click OK to add Liferay 6.2 Runtime.");

            if (openAddLiferaryServerDialog) {
                ServerUIUtil.showNewRuntimeWizard(UIUtil.getActiveShell(), null, null, "com.liferay.");
                return getLiferay62ServerLocation();
            }
        }
    }
    return liferay62ServerLocation;
}

From source file:com.liferay.ide.project.ui.upgrade.animated.CustomJspPage.java

License:Open Source License

private IRuntime getLiferay70Runtime() {
    String serverName = dataModel.getLiferay70ServerName().content();

    IServer server = ServerUtil.getServer(serverName);

    if (server != null) {
        return server.getRuntime();
    } else {//w  w w  .j  a v  a2s . co m
        IRuntime liferay70Runtime = getExistLiferay70Runtime();

        if (liferay70Runtime != null) {
            return liferay70Runtime;
        } else {
            Boolean openAddLiferaryServerDialog = MessageDialog.openConfirm(UIUtil.getActiveShell(),
                    "Could not find Liferay 7.x Runtime",
                    "This process requires 7.x Runtime. " + "Click OK to add Liferay 7.x Runtime.");

            if (openAddLiferaryServerDialog) {
                ServerUIUtil.showNewRuntimeWizard(UIUtil.getActiveShell(), "liferay.bundle", null,
                        "com.liferay.");
                return getExistLiferay70Runtime();
            }
        }
    }
    return null;
}

From source file:com.maccasoft.composer.InstrumentToolBar.java

License:Open Source License

public InstrumentToolBar(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout gridLayout = new GridLayout(3, false);
    gridLayout.marginWidth = gridLayout.marginHeight = 0;
    composite.setLayout(gridLayout);//from  w ww. j  a va  2  s . c  o  m

    shell = parent.getShell();

    GC gc = new GC(parent);
    FontMetrics fontMetrics = gc.getFontMetrics();
    gc.dispose();

    Label label = new Label(composite, SWT.NONE);
    label.setText("Instrument");

    viewer = new ComboViewer(composite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.NO_FOCUS);
    viewer.getCombo().setVisibleItemCount(20);
    viewer.getCombo()
            .setLayoutData(new GridData(Dialog.convertWidthInCharsToPixels(fontMetrics, 30), SWT.DEFAULT));
    viewer.setContentProvider(new ObservableListContentProvider());
    viewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return String.format("%s - %s", project.getInstrumentId((Instrument) element), element.toString());
        }
    });

    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            duplicate.setEnabled(!selection.isEmpty());
            edit.setEnabled(!selection.isEmpty());
            delete.setEnabled(!selection.isEmpty());
        }
    });

    ToolBar toolBar = new ToolBar(composite, SWT.FLAT | SWT.NO_FOCUS);
    ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH);
    toolItem.setImage(ImageRegistry.getImageFromResources("application_add.png"));
    toolItem.setToolTipText("New instrument");
    toolItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Instrument instrument = new InstrumentBuilder("New instrument") //
                    .setModulation(0, 50) //
                    .setVolume(95) //
                    .setEnvelope(2, 2).repeat(1) //
                    .jump(-1).build();

            InstrumentEditor editor = new InstrumentEditor(shell, instrument);
            editor.setSerialPort(serialPort);
            if (editor.open() == InstrumentEditor.OK) {
                project.add(instrument);
                viewer.setSelection(new StructuredSelection(instrument));
            }
        }
    });

    duplicate = new ToolItem(toolBar, SWT.PUSH);
    duplicate.setImage(ImageRegistry.getImageFromResources("application_double.png"));
    duplicate.setToolTipText("Duplicate instrument");
    duplicate.setEnabled(false);
    duplicate.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = viewer.getStructuredSelection();
            if (selection.isEmpty()) {
                return;
            }
            Instrument selectedInstrument = (Instrument) selection.getFirstElement();

            Instrument instrument = new Instrument(selectedInstrument.getName() + " (1)");
            List<Command> list = new ArrayList<Command>();
            try {
                for (Command cmd : selectedInstrument.getCommands()) {
                    list.add(cmd.clone());
                }
                instrument.setCommands(list);
            } catch (Exception ex) {
                ex.printStackTrace();
            }

            InstrumentEditor editor = new InstrumentEditor(shell, instrument);
            editor.setSerialPort(serialPort);
            if (editor.open() == InstrumentEditor.OK) {
                project.add(instrument);
                viewer.setSelection(new StructuredSelection(instrument));
            }
        }
    });

    edit = new ToolItem(toolBar, SWT.PUSH);
    edit.setImage(ImageRegistry.getImageFromResources("application_edit.png"));
    edit.setToolTipText("Edit instrument");
    edit.setEnabled(false);
    edit.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = viewer.getStructuredSelection();
            if (selection.isEmpty()) {
                return;
            }
            Instrument selectedInstrument = (Instrument) selection.getFirstElement();

            InstrumentEditor editor = new InstrumentEditor(shell, selectedInstrument);
            editor.setSerialPort(serialPort);
            if (editor.open() == InstrumentEditor.OK) {
                viewer.refresh();
                viewer.setSelection(new StructuredSelection(selectedInstrument));
            }
        }
    });

    new ToolItem(toolBar, SWT.SEPARATOR);

    delete = new ToolItem(toolBar, SWT.PUSH);
    delete.setImage(ImageRegistry.getImageFromResources("application_delete.png"));
    delete.setToolTipText("Delete instrument");
    delete.setEnabled(false);
    delete.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = viewer.getStructuredSelection();
            if (selection.isEmpty()) {
                return;
            }

            Instrument selectedInstrument = (Instrument) selection.getFirstElement();
            if (isInstrumentUsed(selectedInstrument)) {
                if (!MessageDialog.openConfirm(shell, Main.APP_TITLE,
                        "The instrument is used in a song.  You really want to delete?")) {
                    return;
                }
            }
            project.remove(selectedInstrument);
        }
    });
}

From source file:com.maccasoft.composer.MusicEditor.java

License:Open Source License

void createHeader(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout gridLayout = new GridLayout(12, false);
    gridLayout.marginWidth = gridLayout.marginHeight = 0;
    composite.setLayout(gridLayout);/*from  w  w w .  j  a v a2  s . c o m*/
    composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    Label label = new Label(composite, SWT.NONE);
    label.setText("Song");

    songsCombo = new ComboViewer(composite, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.NO_FOCUS);
    songsCombo.getCombo().setVisibleItemCount(20);
    songsCombo.getCombo()
            .setLayoutData(new GridData(Dialog.convertWidthInCharsToPixels(fontMetrics, 30), SWT.DEFAULT));
    songsCombo.setContentProvider(new ObservableListContentProvider());
    songsCombo.setLabelProvider(new LabelProvider());

    ToolBar toolBar = new ToolBar(composite, SWT.FLAT | SWT.NO_FOCUS);

    edit = new ToolItem(toolBar, SWT.PUSH);
    edit.setImage(ImageRegistry.getImageFromResources("application_edit.png"));
    edit.setToolTipText("Rename");
    edit.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IInputValidator validator = new IInputValidator() {

                @Override
                public String isValid(String newText) {
                    if (newText.length() == 0) {
                        return "";
                    }
                    for (Song song : project.getSongs()) {
                        if (song != currentSong && newText.equalsIgnoreCase(song.getName())) {
                            return "A song with the same title already exists";
                        }
                    }
                    return null;
                }
            };
            InputDialog dlg = new InputDialog(shell, "Rename Song", "Title:", currentSong.getName(), validator);
            if (dlg.open() == InputDialog.OK) {
                currentSong.setName(dlg.getValue());
                songsCombo.refresh();
            }
        }
    });

    new ToolItem(toolBar, SWT.SEPARATOR);

    play = new ToolItem(toolBar, SWT.PUSH);
    play.setImage(ImageRegistry.getImageFromResources("control_play_blue.png"));
    play.setToolTipText("Play");
    play.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Runnable playThread = new Runnable() {

                @Override
                public void run() {
                    try {
                        ProjectCompiler compiler = new ProjectCompiler(project);
                        Music music = compiler.build(currentSong);
                        byte[] data = music.toArray();
                        try {
                            serialPort.writeInt('P');
                            serialPort.writeInt(data.length & 0xFF);
                            serialPort.writeInt((data.length >> 8) & 0xFF);
                            serialPort.writeBytes(data);
                        } catch (SerialPortException e) {
                            e.printStackTrace();
                        }
                    } catch (final ProjectException ex) {
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                if (shell.isDisposed()) {
                                    return;
                                }
                                MessageDialog.openError(shell, Main.APP_TITLE,
                                        "An error occurred while compiling song:\r\n\r\n" + ex.getMessage());
                                focusOnErrorCell(ex);
                            }
                        });
                    }
                }
            };
            new Thread(playThread).start();
        }
    });

    stop = new ToolItem(toolBar, SWT.PUSH);
    stop.setImage(ImageRegistry.getImageFromResources("control_stop_blue.png"));
    stop.setToolTipText("Stop");
    stop.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            try {
                serialPort.writeInt('0');
            } catch (SerialPortException ex) {
                ex.printStackTrace();
            }
        }
    });

    new ToolItem(toolBar, SWT.SEPARATOR);

    delete = new ToolItem(toolBar, SWT.PUSH);
    delete.setImage(ImageRegistry.getImageFromResources("application_delete.png"));
    delete.setToolTipText("Delete song");
    delete.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = songsCombo.getStructuredSelection();
            if (selection.isEmpty()) {
                return;
            }
            if (!MessageDialog.openConfirm(shell, Main.APP_TITLE, "You really want to delete this song?")) {
                return;
            }
            int index = project.getSongs().indexOf(selection.getFirstElement());
            if (index > 0) {
                songsCombo.setSelection(new StructuredSelection(project.getSong(index - 1)));
            } else {
                songsCombo.setSelection(new StructuredSelection(project.getSong(index + 1)));
            }
            project.getObservableSongs().remove(selection.getFirstElement());
            delete.setEnabled(currentSong != null && project.getSongs().size() > 1);
        }
    });

    label = new Label(composite, SWT.NONE);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    label = new Label(composite, SWT.NONE);
    label.setText("BPM");

    bpm = new Spinner(composite, SWT.BORDER | SWT.NO_FOCUS);
    bpm.setValues(120, 0, 9999, 0, 1, 1);
    bpm.setLayoutData(new GridData(Dialog.convertWidthInCharsToPixels(fontMetrics, 5), SWT.DEFAULT));
    bpm.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (currentSong != null) {
                currentSong.setBpm(bpm.getSelection());
            }
        }
    });

    label = new Label(composite, SWT.NONE);
    label.setText("Rows");

    rows = new Spinner(composite, SWT.BORDER | SWT.NO_FOCUS);
    rows.setValues(0, 0, 9999, 0, 1, 1);
    rows.setLayoutData(new GridData(Dialog.convertWidthInCharsToPixels(fontMetrics, 5), SWT.DEFAULT));
    rows.setEnabled(false);
    rows.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (currentSong == null) {
                return;
            }
            int totalRows = rows.getSelection();
            while (currentSong.getObservableRows().size() > totalRows) {
                currentSong.getObservableRows().remove(currentSong.getObservableRows().size() - 1);
            }
            while (currentSong.getObservableRows().size() < totalRows) {
                currentSong.getObservableRows().add(new SongRow());
            }
        }
    });

    label = new Label(composite, SWT.NONE);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    label = new Label(composite, SWT.NONE);
    label.setText("Octave");

    octave = new Spinner(composite, SWT.BORDER | SWT.NO_FOCUS);
    octave.setValues(3, 1, 9, 0, 1, 1);
    octave.setLayoutData(new GridData(Dialog.convertWidthInCharsToPixels(fontMetrics, 3), SWT.DEFAULT));
    octave.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            viewer.getControl().setFocus();
        }
    });

    instrumentToolBar = new InstrumentToolBar(composite);

    songsCombo.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            currentSong = (Song) selection.getFirstElement();
            updateSongView();
        }
    });
}

From source file:com.mercatis.lighthouse3.status.ui.editors.pages.StatusOverviewEditorPage.java

License:Apache License

public void markStatusForDelete(StatusEditingObject status) {
    if (MessageDialog.openConfirm(getSite().getShell(), "Remove Status",
            "The selected status will get deleted when you save your changes.\n\nDo you really want to remove \""
                    + status.getCode() + "\"?")) {
        statuusToDelete.add(status);/*from ww  w .ja  v a  2s  .co m*/
        statuus.remove(status);
        statusViewer.remove(status);
        getEditor().editorDirtyStateChanged();
    }
}

From source file:com.mercatis.lighthouse3.ui.operations.ui.editors.pages.InstalledOperationsEditorPage.java

License:Apache License

public void markJobForDelete(Job job) {
    if (MessageDialog.openConfirm(getSite().getShell(), "Remove Job",
            "The selected job will get deleted when you save your changes.\n\nDo you really want to remove \""
                    + job.getCode() + "\"?")) {
        jobs.remove(job);/*from  ww  w  .  j  av  a2 s .  c o  m*/
        jobsToDelete.add(job);
        fillJobTable();
        getEditor().editorDirtyStateChanged();
    }
}

From source file:com.mercatis.lighthouse3.ui.operations.ui.editors.pages.InstalledOperationsEditorPage.java

License:Apache License

public void markOperationInstallationForRemove(OperationInstallation operationInstallation) {
    if (MessageDialog.openConfirm(getSite().getShell(), "Remove Operation",
            "The selected operation will get deleted when you save your changes.\n\nDo you really want to remove this operation?")) {
        installations.remove(operationInstallation);
        installationsToDelete.add(operationInstallation);
        fillOperationInstallationTree();
        getEditor().editorDirtyStateChanged();
    }//from   w  ww.  j  a va2s.  co  m
}

From source file:com.metaaps.eoclipse.common.Util.java

License:Open Source License

public static boolean confirmMessage(String title, String message) {
    Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
    return MessageDialog.openConfirm(shell, title, message);
}

From source file:com.microsoft.applicationinsights.preference.ApplicationInsightsPreferencePage.java

License:Open Source License

/**
 * Method removes application insight resource from local cache.
 *///w w  w  .  jav a  2 s . co  m
protected void removeButtonListener() {
    int curSelIndex = tableViewer.getTable().getSelectionIndex();
    if (curSelIndex > -1) {
        String keyToRemove = ApplicationInsightsResourceRegistry.getKeyAsPerIndex(curSelIndex);
        String projName = AIResourceChangeListener.getProjectNameAsPerKey(keyToRemove);
        if (projName != null && !projName.isEmpty()) {
            PluginUtil.displayErrorDialog(getShell(), Messages.appTtl,
                    String.format(Messages.rsrcUseMsg, projName));
        } else {
            boolean choice = MessageDialog.openConfirm(getShell(), Messages.appTtl, Messages.rsrcRmvMsg);
            if (choice) {
                ApplicationInsightsResourceRegistry.getAppInsightsResrcList().remove(curSelIndex);
                ApplicationInsightsPreferences.save();
                tableViewer.refresh();
                selIndex = -1;
            }
        }
    }
}

From source file:com.microsoft.azureexplorer.forms.SubscriptionPropertyPage.java

License:Open Source License

private void clearSubscriptions(boolean isSigningOut) {
    boolean choice = MessageDialog.openConfirm(new Shell(), (isSigningOut ? "Clear Subscriptions" : "Sign out"),
            (isSigningOut ? "Are you sure you would like to clear all subscriptions?"
                    : "Are you sure you would like to sign out?"));
    if (choice) {
        AzureManager apiManager = AzureManagerImpl.getManager();
        apiManager.clearAuthentication();
        apiManager.clearImportedPublishSettingsFiles();
        WizardCacheManager.clearSubscriptions();
        subscriptionList.clear();/*from   ww  w .  j  ava  2  s. c  o m*/
        tableViewer.refresh();
        // todo ?
        //            DefaultLoader.getIdeHelper().unsetProperty(AppSettingsNames.SELECTED_SUBSCRIPTIONS);

        removeButton.setEnabled(false);

        refreshSignInCaption();
    }
}