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.astra.ses.spell.gui.preferences.ui.pages.GeneralPreferencePage.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {
    // CONTAINER//w ww .  j  a va  2s  .  co m
    Composite container = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(1, true);
    GridData layoutData = new GridData(GridData.FILL_BOTH);
    container.setLayout(layout);
    container.setLayoutData(layoutData);

    /* Page layout */
    GridData expand = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
    expand.grabExcessVerticalSpace = true;
    expand.grabExcessHorizontalSpace = true;

    /*
     * Startup connection button
     */
    Composite startupConnection = new Composite(container, SWT.NONE);
    startupConnection.setLayout(new GridLayout(2, false));
    startupConnection.setLayoutData(GridDataFactory.copyData(expand));
    // Button
    m_startupConnect = new Button(startupConnection, SWT.CHECK);
    // Label
    Label startupDesc = new Label(startupConnection, SWT.NONE);
    startupDesc.setText("Connect to server at startup");

    // Label
    Label scpUser = new Label(startupConnection, SWT.NONE);
    scpUser.setText("User for SCP connections");
    // Text
    m_scpUser = new Text(startupConnection, SWT.BORDER);
    m_scpUser.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    // Label
    Label scpPwd = new Label(startupConnection, SWT.NONE);
    scpPwd.setText("Password for SCP connections");
    // Text
    m_scpPassword = new Text(startupConnection, SWT.BORDER | SWT.PASSWORD);
    m_scpPassword.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    /*
     * Communication group
     */
    GridLayout communicationLayout = new GridLayout(3, false);
    Group communicationGroup = new Group(container, SWT.BORDER);
    communicationGroup.setText("Communication");
    communicationGroup.setLayout(communicationLayout);
    communicationGroup.setLayoutData(GridDataFactory.copyData(expand));
    /*
     * Response timeout
     */
    // Label
    Label responseTimeout = new Label(communicationGroup, SWT.NONE);
    responseTimeout.setText("Response timeout");
    // Text
    m_responseTimeout = new Text(communicationGroup, SWT.BORDER | SWT.RIGHT);
    m_responseTimeout.setLayoutData(GridDataFactory.copyData(expand));
    // Units label
    Label units = new Label(communicationGroup, SWT.NONE);
    units.setText("milliseconds");
    /*
     * Procedure opening timeout
     */
    // Label
    Label procedureOpenLabel = new Label(communicationGroup, SWT.NONE);
    procedureOpenLabel.setText("Procedure opening timeout");
    // Text
    m_openTimeout = new Text(communicationGroup, SWT.BORDER | SWT.RIGHT);
    m_openTimeout.setLayoutData(GridDataFactory.copyData(expand));
    // Label
    Label openUnits = new Label(communicationGroup, SWT.NONE);
    openUnits.setText("milliseconds");

    /*
     * User group
     */
    GridLayout userLayout = new GridLayout(3, true);
    Group userGroup = new Group(container, SWT.BORDER);
    userGroup.setText("User settings");
    userGroup.setLayout(userLayout);
    userGroup.setLayoutData(GridDataFactory.copyData(expand));
    /*
     * Prompt delay
     */
    // Label
    Label promptDelayLabel = new Label(userGroup, SWT.NONE);
    promptDelayLabel.setText("Prompt blinking delay");
    m_promptDelay = new Text(userGroup, SWT.BORDER | SWT.RIGHT);
    m_promptDelay.setLayoutData(GridDataFactory.copyData(expand));
    // Label
    Label promptDelayUnitsLabel = new Label(userGroup, SWT.NONE);
    promptDelayUnitsLabel.setText("seconds");
    /*
     * Prompt sound file
     */
    // Label
    Label promptSoundLabel = new Label(userGroup, SWT.NONE);
    promptSoundLabel.setText("Prompt sound file");
    m_soundFile = new Text(userGroup, SWT.BORDER);
    m_soundFile.setLayoutData(GridDataFactory.copyData(expand));
    // Browse button
    final Button browse = new Button(userGroup, SWT.PUSH);
    browse.setText("Browse...");
    browse.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent arg0) {
            FileDialog dialog = new FileDialog(browse.getShell());
            dialog.setFilterExtensions(new String[] { "*.wav" });
            dialog.setText("Select prompt sound file");
            dialog.setFilterNames(new String[] { "Waveform files (*.wav)" });
            String selected = dialog.open();
            if (selected != null) {
                m_soundFile.setText(selected);
            }
        }
    });

    /*
     * Save group
     */
    GridLayout saveLayout = new GridLayout(3, true);
    Group saveGroup = new Group(container, SWT.BORDER);
    saveGroup.setText("Save preferences");
    saveGroup.setLayout(saveLayout);
    saveGroup.setLayoutData(GridDataFactory.copyData(expand));

    /*
     * Save to current XML file
     */
    final Button saveBtn = new Button(saveGroup, SWT.PUSH);
    saveBtn.setText("Save to current file");
    saveBtn.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            IConfigurationManager conf = getConfigurationManager();
            String cfgFile = conf.getConfigurationFile();
            try {
                if (!MessageDialog.openConfirm(saveBtn.getShell(), "Overwrite preferences?",
                        "This action will overwrite the current preferences stored in "
                                + "the default configuration file '" + cfgFile + "'. Do you want to continue?"))
                    return;

                GUIPreferencesSaver saver = new GUIPreferencesSaver(cfgFile);
                saver.savePreferences();
                MessageDialog.openInformation(saveBtn.getShell(), "Preferences saved",
                        "Preferences saved to file '" + cfgFile + "'");
            } catch (Exception ex) {
                MessageDialog.openError(saveBtn.getShell(), "Cannot save preferences",
                        "Unable to save preferences to '" + cfgFile + "'\n" + ex.getLocalizedMessage());
            }
        }
    });

    /*
     * Save to alternate XML file
     */
    final Button saveOtherBtn = new Button(saveGroup, SWT.PUSH);
    saveOtherBtn.setText("Save to another file...");
    saveOtherBtn.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            FileDialog dialog = new FileDialog(saveOtherBtn.getShell(), SWT.SAVE);
            dialog.setFilterExtensions(new String[] { "*.xml" });
            dialog.setText("Select file to save preferences");
            dialog.setFilterNames(new String[] { "XML files (*.xml)" });
            String selected = dialog.open();
            if (selected != null) {
                /*
                 * If user has not set the file extension, then add it
                 */
                if (!selected.endsWith(".xml")) {
                    selected += ".xml";
                }
                try {
                    File file = new File(selected);
                    if (file.exists()) {
                        if (!MessageDialog.openConfirm(saveOtherBtn.getShell(), "Overwrite file?",
                                "File '" + selected + "' already exists. Overwrite?"))
                            return;
                    }
                    GUIPreferencesSaver saver = new GUIPreferencesSaver(selected);
                    saver.savePreferences();
                    MessageDialog.openInformation(saveOtherBtn.getShell(), "Preferences saved",
                            "Preferences saved to file '" + selected + "'");
                } catch (Exception ex) {
                    MessageDialog.openError(saveOtherBtn.getShell(), "Cannot save preferences",
                            "Unable to save preferences to '" + selected + "'\n" + ex.getLocalizedMessage());
                }
            }
        }
    });

    /*
     * Load preferences from an external file
     */
    final Button loadPrefsBtn = new Button(saveGroup, SWT.PUSH);
    loadPrefsBtn.setText("Load from external file...");
    loadPrefsBtn.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            FileDialog dialog = new FileDialog(loadPrefsBtn.getShell(), SWT.OPEN);
            dialog.setFilterExtensions(new String[] { "*.xml", "*.XML" });
            String selected = dialog.open();
            if (selected != null) {
                File file = new File(selected);
                if (file.exists()) {
                    if (!MessageDialog.openConfirm(loadPrefsBtn.getShell(), "Overwrite preferences?",
                            "All the current values will be replaced with the ones defined in the selected file.\n"
                                    + "Do you wish to continue?"))
                        return;

                }

                /*
                 * Overwrite preferences dialog
                 */
                IPreferenceStore store = Activator.getDefault().getPreferenceStore();
                GUIPreferencesLoader loader = new GUIPreferencesLoader(selected, store);
                boolean loaded = loader.overwrite();
                if (!loaded) {
                    MessageDialog.openError(loadPrefsBtn.getShell(), "Error while loading configuration file",
                            "An unexpected error ocurred while loading the configuration file.\n"
                                    + "Check the application log for details");
                }
            }
        }
    });

    refreshPage();
    return container;
}

From source file:com.astra.ses.spell.gui.shared.views.controls.ScopeTab.java

License:Open Source License

/***************************************************************************
 * /*from  w ww .ja va 2s .co  m*/
 **************************************************************************/
public ScopeTab(TabFolder parent, ISharedScope table, SharedVariablesView view, boolean monitoringMode) {
    super(parent, SWT.NONE);

    Logger.debug("Created tab: " + table.getScopeName(), Level.GUI, this);

    m_table = table;
    m_view = view;
    m_monitoringMode = monitoringMode;

    Composite top = new Composite(parent, SWT.NONE);
    top.setLayout(new GridLayout(isGlobal() ? 4 : 5, true));
    top.setLayoutData(new GridData(GridData.FILL_BOTH));

    m_viewer = new SharedVariablesTableViewer(top, table, monitoringMode);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = isGlobal() ? 4 : 5;
    m_viewer.getControl().setLayoutData(gd);
    m_viewer.addSelectionChangedListener(this);

    if (isGlobal()) {
        setText("GLOBAL");
    } else {
        setText(m_table.getScopeName());
    }

    m_btnNew = new Button(top, SWT.PUSH);
    m_btnNew.setText("New variable");
    m_btnNew.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    m_btnNew.setEnabled(false);
    m_btnNew.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent ev) {
            SharedVariableDialog dialog = new SharedVariableDialog(m_viewer.getControl().getShell(), true, "",
                    "");
            if (dialog.open() == IDialogConstants.OK_ID) {
                String key = dialog.getKey();
                String value = dialog.getValue();
                if (!key.trim().isEmpty() && !value.trim().isEmpty()) {
                    m_table.set(dialog.getKey(), dialog.getValue());
                    refresh();
                }
            }
        }
    });

    m_btnDel = new Button(top, SWT.PUSH);
    m_btnDel.setText("Delete variable");
    m_btnDel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    m_btnDel.setEnabled(false);
    m_btnDel.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent ev) {
            IStructuredSelection sel = (IStructuredSelection) m_viewer.getSelection();
            if (!sel.isEmpty()) {
                @SuppressWarnings("rawtypes")
                Iterator it = sel.iterator();
                String toDeleteText = "Are you sure to delete the following shared variables?\n\n";
                List<SharedVariable> toDelete = new LinkedList<SharedVariable>();
                while (it.hasNext()) {
                    SharedVariable var = (SharedVariable) it.next();
                    toDelete.add(var);
                    toDeleteText += "  - " + var.name + "\n";
                }
                if (MessageDialog.openConfirm(m_viewer.getControl().getShell(), "Delete shared variables",
                        toDeleteText)) {
                    ClearSharedVariablesJob job = new ClearSharedVariablesJob(m_table, toDelete);
                    CommandHelper.executeInProgress(job, true, true);
                    refresh();
                }
            }
        }
    });

    m_btnClear = new Button(top, SWT.PUSH);
    m_btnClear.setText("Remove all variables");
    m_btnClear.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    m_btnClear.setEnabled(false);
    m_btnClear.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent ev) {
            String text = "This action will remove all shared variables in the scope.\n\nDo you want to proceed?";
            if (MessageDialog.openConfirm(m_viewer.getControl().getShell(), "Delete shared variables", text)) {
                ClearSharedVariablesJob job = new ClearSharedVariablesJob(m_table);
                CommandHelper.executeInProgress(job, true, true);
                refresh();
            }
        }
    });

    Button refreshScope = new Button(top, SWT.PUSH);
    refreshScope.setText("Refresh variables");
    refreshScope.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    refreshScope.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent ev) {
            Logger.debug("Refreshing tab: " + m_table.getScopeName(), Level.GUI, this);
            RefreshSharedVariablesJob job = new RefreshSharedVariablesJob(m_table);
            CommandHelper.executeInProgress(job, true, true);
            refresh();
        }
    });

    if (!isGlobal()) {
        m_btnRemove = new Button(top, SWT.PUSH);
        m_btnRemove.setText("Remove scope");
        m_btnRemove.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        m_btnRemove.setEnabled(false);
        m_btnRemove.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent ev) {
                String text = "This action will completely remove the scope and its variables.\n\nDo you want to proceed?";
                if (MessageDialog.openConfirm(m_viewer.getControl().getShell(), "Delete shared variables",
                        text)) {
                    ISharedDataService svc = (ISharedDataService) ServiceManager.get(ISharedDataService.class);
                    svc.removeSharedScope(m_table.getScopeName());
                    m_view.removeScope(m_table.getScopeName());
                }
            }
        });
    }

    if (!monitoringMode) {
        m_btnNew.setEnabled(true);
        m_btnClear.setEnabled(true);
        if (!isGlobal())
            m_btnRemove.setEnabled(true);
    }

    setControl(top);
}

From source file:com.astra.ses.spell.gui.shared.views.SharedVariablesView.java

License:Open Source License

/***************************************************************************
 * Complete the creation of the view//  w w  w . j  av  a 2 s . c om
 **************************************************************************/
@Override
public void createPartControl(Composite parent) {
    setPartName("Shared Variables");

    Composite top = new Composite(parent, SWT.NONE);
    top.setLayout(new GridLayout(3, true));

    m_updateAll = new Button(top, SWT.PUSH);
    m_updateAll.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    m_updateAll.setText("Update all");
    m_updateAll.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent ev) {
            RefreshSharedVariablesJob job = new RefreshSharedVariablesJob();
            CommandHelper.executeInProgress(job, true, true);
            update();
        }
    });

    m_clearAll = new Button(top, SWT.PUSH);
    m_clearAll.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    m_clearAll.setText("Clear all");
    m_clearAll.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent ev) {
            String text = "This action will remove all scopes and variables.\n\nDo you want to proceed?";
            if (MessageDialog.openConfirm(getSite().getShell(), "Delete shared variables", text)) {
                ClearSharedVariablesJob job = new ClearSharedVariablesJob();
                CommandHelper.executeInProgress(job, true, true);
                update();
            }
        }
    });

    m_addScope = new Button(top, SWT.PUSH);
    m_addScope.setText("Add new scope");
    m_addScope.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    m_addScope.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent ev) {
            SharedVariableDialog dialog = new SharedVariableDialog(getSite().getShell());
            if (dialog.open() == IDialogConstants.OK_ID) {
                ISharedDataService svc = (ISharedDataService) ServiceManager.get(ISharedDataService.class);
                svc.addSharedScope(dialog.getScope());
                createScope(dialog.getScope());
            }
        }
    });

    m_tabs = new TabFolder(top, SWT.BORDER);
    GridData tdata = new GridData(GridData.FILL_BOTH);
    tdata.horizontalSpan = 3;
    m_tabs.setLayoutData(tdata);
    m_tabs.setLayout(new GridLayout(1, true));

    IContextProxy proxy = (IContextProxy) ServiceManager.get(IContextProxy.class);
    if (proxy.isConnected()) {
        RefreshSharedVariablesJob job = new RefreshSharedVariablesJob();
        CommandHelper.executeInProgress(job, true, true);
        update();
    }

    proxy.addCommListener(this);
    GuiNotifications.get().addListener(this, ICoreContextOperationListener.class);

    boolean ready = (m_ctxProxy.isConnected() && !m_monitoringMode);
    m_updateAll.setEnabled(m_ctxProxy.isConnected());
    m_addScope.setEnabled(ready);
    m_clearAll.setEnabled(ready);
}

From source file:com.astra.ses.spell.gui.views.controls.master.ExecutorComposite.java

License:Open Source License

/***************************************************************************
 * //from   ww w.j a  v  a  2  s.  c o m
 **************************************************************************/
private void doTakeControl(String[] procIds) {
    for (String procId : procIds) {
        // If we want to steal control
        IProcedure proc = s_procMgr.getRemoteProcedure(procId);
        IExecutionInformation info = proc.getRuntimeInformation();
        IProcedureClient cClient = info.getControllingClient();

        boolean attachControl = false;

        if (cClient != null) {
            boolean proceed = MessageDialog.openConfirm(getShell(), "Steal Procedure Control",
                    "The procedure is begin controlled already. Do you want to steal the control?");
            if (proceed) {
                RemoveProcedureControlJob job = new RemoveProcedureControlJob(procId);
                CommandHelper.executeInProgress(job, true, true);
                if (job.result.equals(CommandResult.CANCELLED))
                    continue;
                attachControl = true;
            }
        } else {
            attachControl = true;
        }

        if (attachControl) {
            Logger.debug("Taking control of " + procId, Level.PROC, this);
            ControlRemoteProcedureJob job = new ControlRemoteProcedureJob(procId);
            CommandHelper.executeInProgress(job, true, true);
            if (job.result == CommandResult.FAILED) {
                MessageDialog.openError(getShell(), "Attach error", job.message);
            } else if (job.result == CommandResult.CANCELLED) {
                break;
            }
        }
    }
}

From source file:com.astra.ses.spell.gui.views.controls.master.executors.ExecutorComposite.java

License:Open Source License

/***************************************************************************
 * /*from   ww  w .ja v a2  s.  co m*/
 **************************************************************************/
private void doTakeControl(String[] procIds, boolean useAsRun) {
    List<String> toControl = processMultipleAttach(procIds, "control");
    for (String procId : toControl) {
        // If we want to steal control
        IProcedure proc = s_procMgr.getRemoteProcedure(procId);
        IExecutionInformation info = proc.getRuntimeInformation();
        IProcedureClient cClient = info.getControllingClient();

        boolean attachControl = false;

        if (cClient != null) {
            boolean proceed = MessageDialog.openConfirm(getShell(), "Steal Procedure Control",
                    "The procedure is begin controlled already. Do you want to steal the control?");
            if (proceed) {
                RemoveProcedureControlJob job = new RemoveProcedureControlJob(procId);
                CommandHelper.executeInProgress(job, true, true);
                if (job.result.equals(CommandResult.CANCELLED))
                    continue;
                attachControl = true;
            }
        } else {
            attachControl = true;
        }

        if (attachControl) {
            Logger.debug("Taking control of " + procId, Level.PROC, this);
            ControlRemoteProcedureJob job = new ControlRemoteProcedureJob(procId, useAsRun);
            CommandHelper.executeInProgress(job, true, true);
            if (job.result == CommandResult.FAILED) {
                MessageDialog.openError(getShell(), "Attach error", job.message);
            } else if (job.result == CommandResult.CANCELLED) {
                break;
            }
        }
    }
}

From source file:com.astra.ses.spell.gui.views.controls.master.executors.ExecutorComposite.java

License:Open Source License

/***************************************************************************
 * /*from  www  . j a  v a  2 s  . c  om*/
 **************************************************************************/
private void doReleaseControl(String[] procIds, boolean background) {
    for (String procId : procIds) {
        if (background) {
            Logger.debug("Putting in background: " + procId, Level.PROC, this);
        } else {
            Logger.debug("Releasing control of " + procId, Level.PROC, this);
        }
        if (background) {
            if (!MessageDialog.openConfirm(getShell(), "Background mode",

                    "Are you sure to put this procedure in background?\n\n"
                            + "Warning: once in background mode, the procedure will continue running without controlling client!")) {
                return;
            }
        }
        ReleaseProcedureJob job = new ReleaseProcedureJob(procId, background);
        CommandHelper.executeInProgress(job, true, true);
        if (job.result == CommandResult.FAILED) {
            MessageDialog.openError(getShell(), "Detach error", job.message);
        } else if (job.result == CommandResult.CANCELLED) {
            break;
        }
    }
}

From source file:com.astra.ses.spell.gui.views.controls.master.recovery.RecoveryComposite.java

License:Open Source License

/***************************************************************************
 * // w w  w. j  a  v a  2 s .co  m
 **************************************************************************/
private boolean doRecoverProcedure(ProcedureRecoveryInfo[] procs) {
    String message = "Do you really want to recover the procedure(s):\n";
    for (ProcedureRecoveryInfo proc : procs) {
        message += "    - " + proc.getName() + "\n";
    }
    if (MessageDialog.openConfirm(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Recover",
            message)) {
        // Ensure that all are uncontrolled.
        for (ProcedureRecoveryInfo proc : procs) {
            Logger.debug("Recovering procedure " + proc.getOriginalInstanceId(), Level.PROC, this);
            RecoverProcedureJob job = new RecoverProcedureJob(proc);
            CommandHelper.executeInProgress(job, true, true);
            if (job.result == CommandResult.FAILED) {
                MessageDialog.openError(getShell(), "Recover error", job.message);
            } else if (job.result == CommandResult.CANCELLED) {
                break;
            }
        }
        return true;
    }
    return false;
}

From source file:com.astra.ses.spell.gui.views.controls.master.recovery.RecoveryComposite.java

License:Open Source License

/***************************************************************************
 * //from   w ww .j a  va 2  s  .  c  o m
 **************************************************************************/
private boolean doDeleteFiles(ProcedureRecoveryInfo[] procs) {
    String message = "Do you really want to delete the recovery files for the procedure(s):\n";
    for (ProcedureRecoveryInfo proc : procs) {
        message += "    - " + proc.getName() + "\n";
    }
    if (MessageDialog.openConfirm(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            "Delete files", message)) {
        // Ensure that all are uncontrolled.
        Logger.debug("Deleting recovery file(s)", Level.PROC, this);
        DeleteRecoverFileJob job = new DeleteRecoverFileJob(procs);
        CommandHelper.executeInProgress(job, true, true);
        if (job.result == CommandResult.FAILED) {
            MessageDialog.openError(getShell(), "Delete error", job.message);
        } else if (job.result == CommandResult.CANCELLED) {
            return false;
        }
        return true;
    }
    return false;
}

From source file:com.astra.ses.spell.gui.views.WatchVariablesView.java

License:Open Source License

/***************************************************************************
 * Make actions to apply over the different pages on demand
 **************************************************************************/
private void makeActions() {
    String baseLocation = "platform:/plugin/" + Fragment.FRAGMENT_ID;

    m_refreshAction = new Action() {
        public void run() {
            try {
                showBusy(true);//from w w w . j ava  2s  . c  o  m
                IPage current = getCurrentPage();
                if (current.getClass().equals(WatchVariablesPage.class)) {
                    WatchVariablesPage page = (WatchVariablesPage) current;
                    page.refresh();
                }
            } finally {
                showBusy(false);
            }
        }
    };
    m_refreshAction.setText("Refresh variables");
    m_refreshAction.setToolTipText("Refresh variables");
    m_refreshAction.setImageDescriptor(Activator.getImageDescriptor(baseLocation + "/icons/16x16/refresh.png"));

    m_subscribeAction = new Action() {
        public void run() {
            try {
                showBusy(true);
                IPage current = getCurrentPage();
                if (current.getClass().equals(WatchVariablesPage.class)) {
                    WatchVariablesPage page = (WatchVariablesPage) current;
                    page.subscribeSelected();
                }
            } finally {
                showBusy(false);
            }
        }
    };
    m_subscribeAction.setText("Watch variables");
    m_subscribeAction.setToolTipText("Watch variables");
    m_subscribeAction
            .setImageDescriptor(Activator.getImageDescriptor(baseLocation + "/icons/16x16/zoom_in.png"));

    m_unsubscribeAction = new Action() {
        public void run() {
            try {
                showBusy(true);
                IPage current = getCurrentPage();
                if (current.getClass().equals(WatchVariablesPage.class)) {
                    WatchVariablesPage page = (WatchVariablesPage) current;
                    page.unsubscribeSelected();
                }
            } finally {
                showBusy(false);
            }
        }
    };
    m_unsubscribeAction.setText("Stop watching variables");
    m_unsubscribeAction.setToolTipText("Stop watching variables");
    m_unsubscribeAction
            .setImageDescriptor(Activator.getImageDescriptor(baseLocation + "/icons/16x16/zoom_out.png"));

    m_unsubscribeAllAction = new Action() {
        public void run() {
            try {
                showBusy(true);
                IPage current = getCurrentPage();
                if (current.getClass().equals(WatchVariablesPage.class)) {
                    WatchVariablesPage page = (WatchVariablesPage) current;
                    boolean proceed = MessageDialog.openConfirm(getSite().getShell(), "Remove all watches",
                            "Do you really want to remove all variable watches?");
                    if (proceed) {
                        page.unsubscribeAll();
                    }
                }
            } finally {
                showBusy(false);
            }
        }
    };
    m_unsubscribeAllAction.setText("Stop watching all variables");
    m_unsubscribeAllAction.setToolTipText("Stop watching all variables");
    m_unsubscribeAllAction
            .setImageDescriptor(Activator.getImageDescriptor(baseLocation + "/icons/16x16/cancel.png"));
}

From source file:com.astra.ses.spell.gui.watchvariables.views.WatchVariablesView.java

License:Open Source License

/***************************************************************************
 * Make actions to apply over the different pages on demand
 **************************************************************************/
private void makeActions() {
    String baseLocation = "platform:/plugin/" + Activator.PLUGIN_ID;

    m_refreshAction = new Action() {
        public void run() {
            try {
                showBusy(true);/*  www .  ja  v  a 2s. com*/
                IPage current = getCurrentPage();
                if (current.getClass().equals(WatchVariablesPage.class)) {
                    WatchVariablesPage page = (WatchVariablesPage) current;
                    page.updateModel();
                }
            } finally {
                showBusy(false);
            }
        }
    };
    m_refreshAction.setText("Refresh variables");
    m_refreshAction.setToolTipText("Refresh variables");
    m_refreshAction.setImageDescriptor(Activator.getImageDescriptor(baseLocation + "/icons/16x16/refresh.png"));

    m_subscribeAction = new Action() {
        public void run() {
            try {
                showBusy(true);
                IPage current = getCurrentPage();
                if (current.getClass().equals(WatchVariablesPage.class)) {
                    WatchVariablesPage page = (WatchVariablesPage) current;
                    page.subscribeSelected();
                }
            } finally {
                showBusy(false);
            }
        }
    };
    m_subscribeAction.setText("Watch variables");
    m_subscribeAction.setToolTipText("Watch variables");
    m_subscribeAction
            .setImageDescriptor(Activator.getImageDescriptor(baseLocation + "/icons/16x16/zoom_in.png"));

    m_unsubscribeAction = new Action() {
        public void run() {
            try {
                showBusy(true);
                IPage current = getCurrentPage();
                if (current.getClass().equals(WatchVariablesPage.class)) {
                    WatchVariablesPage page = (WatchVariablesPage) current;
                    page.unsubscribeSelected();
                }
            } finally {
                showBusy(false);
            }
        }
    };
    m_unsubscribeAction.setText("Stop watching variables");
    m_unsubscribeAction.setToolTipText("Stop watching variables");
    m_unsubscribeAction
            .setImageDescriptor(Activator.getImageDescriptor(baseLocation + "/icons/16x16/zoom_out.png"));

    m_unsubscribeAllAction = new Action() {
        public void run() {
            try {
                showBusy(true);
                IPage current = getCurrentPage();
                if (current.getClass().equals(WatchVariablesPage.class)) {
                    WatchVariablesPage page = (WatchVariablesPage) current;
                    boolean proceed = MessageDialog.openConfirm(getSite().getShell(), "Remove all watches",
                            "Do you really want to remove all variable watches?");
                    if (proceed) {
                        page.unsubscribeAll();
                    }
                }
            } finally {
                showBusy(false);
            }
        }
    };
    m_unsubscribeAllAction.setText("Stop watching all variables");
    m_unsubscribeAllAction.setToolTipText("Stop watching all variables");
    m_unsubscribeAllAction
            .setImageDescriptor(Activator.getImageDescriptor(baseLocation + "/icons/16x16/cancel.png"));
}