Search in sources :

Example 1 with MessageDialogWithToggle

use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project cubrid-manager by CUBRID.

the class ApplicationWorkbenchWindowAdvisor method preWindowShellClose.

/**
	 * Performs arbitrary actions as the window's shell is being closed
	 * directly, and possibly veto the close.
	 *
	 * @return <code>true</code> to allow the window to close, and
	 *         <code>false</code> to prevent the window from closing
	 * @see org.eclipse.ui.IWorkbenchWindow#close
	 * @see WorkbenchAdvisor#preShutdown()
	 */
public boolean preWindowShellClose() {
    Shell shell = getWindowConfigurer().getWindow().getShell();
    GeneralPreference.setMaximizeWindowOnStartUp(shell.getMaximized());
    if (timer != null) {
        timer.cancel();
        HeartBeatTaskManager.getInstance().cancel();
    }
    /*Close the information window*/
    InfoWindowManager.dispose();
    /*All opened queryEditor*/
    List<QueryEditorPart> editorPartList = QueryEditorUtil.getAllQueryEditorPart();
    boolean isNeedSaveQueryEditor = isNeedSaveQueryEditor(editorPartList);
    boolean hasJobRunning = false;
    final JobFamily jobFamily = new JobFamily();
    jobFamily.setServerName(JobFamily.ALL_SERVER);
    Job[] jobs = Job.getJobManager().find(jobFamily);
    if (jobs.length > 0) {
        hasJobRunning = true;
    }
    boolean isExit = false;
    if (hasJobRunning) {
        isExit = CommonUITool.openConfirmBox(getWindowConfigurer().getWindow().getShell(), Messages.msgExistConfirmWithJob);
        if (isExit) {
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    try {
                        Job.getJobManager().cancel(jobFamily);
                    } catch (Exception e) {
                        LOGGER.error("Stopping background jobs was failed.", e);
                    }
                }
            });
            if (isNeedSaveQueryEditor) {
                processSaveQueryEditor();
            }
        }
    } else {
        if (isNeedSaveQueryEditor) {
            processSaveQueryEditor();
            return true;
        } else {
            if (GeneralPreference.isAlwaysExit()) {
                return true;
            }
            MessageDialogWithToggle dialog = MessageDialogWithToggle.openOkCancelConfirm(getWindowConfigurer().getWindow().getShell(), com.cubrid.common.ui.common.Messages.titleExitConfirm, Messages.msgExistConfirm, com.cubrid.common.ui.common.Messages.msgToggleExitConfirm, false, CommonUIPlugin.getDefault().getPreferenceStore(), GeneralPreference.IS_ALWAYS_EXIT);
            isExit = dialog.getReturnCode() == 0 ? true : false;
        }
    }
    if (isExit) {
        for (List<IEditorReference> list : perspectiveEditorMap.values()) {
            IEditorReference[] references = new IEditorReference[list.size()];
            list.toArray(references);
            getWindowConfigurer().getWindow().getActivePage().closeEditors(references, false);
        }
    }
    return isExit;
}
Also used : JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) Shell(org.eclipse.swt.widgets.Shell) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) IEditorReference(org.eclipse.ui.IEditorReference) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) Job(org.eclipse.core.runtime.jobs.Job)

Example 2 with MessageDialogWithToggle

use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project cubrid-manager by CUBRID.

the class ApplicationWorkbenchWindowAdvisor method preWindowShellClose.

/**
	 * Performs arbitrary actions as the window's shell is being closed
	 * directly, and possibly veto the close.
	 * 
	 * @return <code>true</code> to allow the window to close, and
	 *         <code>false</code> to prevent the window from closing
	 * @see org.eclipse.ui.IWorkbenchWindow#close
	 * @see WorkbenchAdvisor#preShutdown()
	 */
public boolean preWindowShellClose() {
    Shell shell = getWindowConfigurer().getWindow().getShell();
    GeneralPreference.setMaximizeWindowOnStartUp(shell.getMaximized());
    if (timer != null) {
        timer.cancel();
        HeartBeatTaskManager.getInstance().cancel();
    }
    /*Close the information window*/
    InfoWindowManager.dispose();
    /*All opened queryEditor*/
    List<QueryEditorPart> editorPartList = QueryEditorUtil.getAllQueryEditorPart();
    boolean isNeedSaveQueryEditor = isNeedSaveQueryEditor(editorPartList);
    boolean hasJobRunning = false;
    final JobFamily jobFamily = new JobFamily();
    jobFamily.setServerName(JobFamily.ALL_SERVER);
    Job[] jobs = Job.getJobManager().find(jobFamily);
    if (jobs.length > 0) {
        hasJobRunning = true;
    }
    boolean isExit = false;
    if (hasJobRunning) {
        isExit = CommonUITool.openConfirmBox(getWindowConfigurer().getWindow().getShell(), Messages.msgExistConfirmWithJob);
        if (isExit) {
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    try {
                        Job.getJobManager().cancel(jobFamily);
                    } catch (Exception e) {
                        LOGGER.error("Stopping background jobs was failed.", e);
                    }
                }
            });
            if (isNeedSaveQueryEditor) {
                processSaveQueryEditor();
            }
        }
    } else {
        if (isNeedSaveQueryEditor) {
            processSaveQueryEditor();
            return true;
        } else {
            if (GeneralPreference.isAlwaysExit()) {
                return true;
            }
            MessageDialogWithToggle dialog = MessageDialogWithToggle.openOkCancelConfirm(getWindowConfigurer().getWindow().getShell(), com.cubrid.common.ui.common.Messages.titleExitConfirm, Messages.msgExistConfirm, com.cubrid.common.ui.common.Messages.msgToggleExitConfirm, false, CommonUIPlugin.getDefault().getPreferenceStore(), GeneralPreference.IS_ALWAYS_EXIT);
            isExit = dialog.getReturnCode() == 0 ? true : false;
        }
    }
    return isExit;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) Job(org.eclipse.core.runtime.jobs.Job)

Example 3 with MessageDialogWithToggle

use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project eclipse.platform.text by eclipse.

the class AbstractDecoratedTextEditor method validateEditorInputDerived.

/**
 * Validates the editor input for derived state.
 * If the given input is derived then this method
 * can show a dialog asking whether to edit the
 * derived file.
 *
 * @return <code>true</code> if the input is OK for editing, <code>false</code> otherwise
 * @since 3.3
 */
private boolean validateEditorInputDerived() {
    if (fIsDerivedStateValidated)
        return fIsEditingDerivedFileAllowed;
    if (getDocumentProvider() instanceof IDocumentProviderExtension) {
        IDocumentProviderExtension extension = (IDocumentProviderExtension) getDocumentProvider();
        IStatus status = extension.getStatus(getEditorInput());
        String pluginId = status.getPlugin();
        boolean isDerivedStatus = status.getCode() == IFileBufferStatusCodes.DERIVED_FILE && (FileBuffers.PLUGIN_ID.equals(pluginId) || EditorsUI.PLUGIN_ID.equals(pluginId));
        if (!isDerivedStatus)
            return true;
    }
    final String warnKey = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_WARN_IF_INPUT_DERIVED;
    IPreferenceStore store = getPreferenceStore();
    if (!store.getBoolean(warnKey))
        return true;
    MessageDialogWithToggle toggleDialog = MessageDialogWithToggle.openYesNoQuestion(getSite().getShell(), TextEditorMessages.AbstractDecoratedTextEditor_warning_derived_title, TextEditorMessages.AbstractDecoratedTextEditor_warning_derived_message, TextEditorMessages.AbstractDecoratedTextEditor_warning_derived_dontShowAgain, false, null, null);
    EditorsUI.getPreferenceStore().setValue(warnKey, !toggleDialog.getToggleState());
    fIsDerivedStateValidated = true;
    return fIsEditingDerivedFileAllowed = toggleDialog.getReturnCode() == IDialogConstants.YES_ID;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 4 with MessageDialogWithToggle

use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project knime-core by knime.

the class LoadWorkflowRunnable method postLoadCheckForMetaNodeUpdates.

static void postLoadCheckForMetaNodeUpdates(final WorkflowEditor editor, final WorkflowManager parent, final List<NodeID> links) {
    StringBuilder m = new StringBuilder("The workflow contains ");
    if (links.size() == 1) {
        m.append("one metanode link (\"");
        m.append(parent.findNodeContainer(links.get(0)).getNameWithID());
        m.append("\").");
    } else {
        m.append(links.size()).append(" metanode links.");
    }
    m.append("\n\n").append("Do you want to check for updates now?");
    final String message = m.toString();
    final AtomicBoolean result = new AtomicBoolean(false);
    final IPreferenceStore corePrefStore = KNIMEUIPlugin.getDefault().getPreferenceStore();
    final String pKey = PreferenceConstants.P_META_NODE_LINK_UPDATE_ON_LOAD;
    String pref = corePrefStore.getString(pKey);
    boolean showInfoMsg = true;
    if (MessageDialogWithToggle.ALWAYS.equals(pref)) {
        result.set(true);
        showInfoMsg = false;
    } else if (MessageDialogWithToggle.NEVER.equals(pref)) {
        result.set(false);
    } else {
        final Display display = Display.getDefault();
        display.syncExec(new Runnable() {

            @Override
            public void run() {
                Shell activeShell = display.getActiveShell();
                MessageDialogWithToggle dlg = MessageDialogWithToggle.openYesNoCancelQuestion(activeShell, "Metanode Link Update", message, "Remember my decision", false, corePrefStore, pKey);
                switch(dlg.getReturnCode()) {
                    case IDialogConstants.YES_ID:
                        result.set(true);
                        break;
                    default:
                        result.set(false);
                }
            }
        });
    }
    if (result.get()) {
        new CheckUpdateMetaNodeLinkAllAction(editor, showInfoMsg).run();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Shell(org.eclipse.swt.widgets.Shell) CheckUpdateMetaNodeLinkAllAction(org.knime.workbench.editor2.actions.CheckUpdateMetaNodeLinkAllAction) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Display(org.eclipse.swt.widgets.Display)

Example 5 with MessageDialogWithToggle

use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project knime-core by knime.

the class VerifyingCompoundCommand method execute.

/**
 * Overrides the execute method of <code>CompoundCommand</code> to add a
 * verification dialog with the given message.
 *
 * @see org.eclipse.gef.commands.Command#execute()
 */
@Override
public void execute() {
    // before showing the confirmation dialog, mark the node part figures
    for (NodeContainerEditPart nodePart : m_nodeParts) {
        nodePart.mark();
    }
    try {
        // the following code has mainly been copied from
        // IDEWorkbenchWindowAdvisor#preWindowShellClose
        IPreferenceStore store = KNIMEUIPlugin.getDefault().getPreferenceStore();
        if (!store.contains(PreferenceConstants.P_CONFIRM_DELETE) || store.getBoolean(PreferenceConstants.P_CONFIRM_DELETE)) {
            MessageDialogWithToggle dialog = MessageDialogWithToggle.openOkCancelConfirm(Display.getDefault().getActiveShell(), "Confirm ...", m_dialogDisplayText, "Do not ask again", false, null, null);
            if (dialog.getReturnCode() != IDialogConstants.OK_ID) {
                return;
            }
            if (dialog.getToggleState()) {
                store.setValue(PreferenceConstants.P_CONFIRM_DELETE, false);
                KNIMEUIPlugin.getDefault().savePluginPreferences();
            }
        }
        // in all other cases execute the commands
        LOGGER.debug("Executing <" + size() + "> commands.");
        super.execute();
    } finally {
        for (NodeContainerEditPart nodePart : m_nodeParts) {
            nodePart.unmark();
        }
    }
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Aggregations

MessageDialogWithToggle (org.eclipse.jface.dialogs.MessageDialogWithToggle)65 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)16 TableItem (org.eclipse.swt.widgets.TableItem)8 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)6 Point (org.pentaho.di.core.gui.Point)6 ArrayList (java.util.ArrayList)5 Shell (org.eclipse.swt.widgets.Shell)5 IOException (java.io.IOException)4 IProject (org.eclipse.core.resources.IProject)4 File (java.io.File)3 Display (org.eclipse.swt.widgets.Display)3 MessageBox (org.eclipse.swt.widgets.MessageBox)3 BackingStoreException (org.osgi.service.prefs.BackingStoreException)3 QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)2 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)2 List (java.util.List)2 Job (org.eclipse.core.runtime.jobs.Job)2 IPerspectiveDescriptor (org.eclipse.ui.IPerspectiveDescriptor)2 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)2 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)2