Search in sources :

Example 36 with MessageDialogWithToggle

use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project tdi-studio-se by Talend.

the class GEFDeleteAction method createDeleteCommand.

@Override
public Command createDeleteCommand(List objects) {
    objects = filterSameObject(objectsToDelete);
    if (objects.isEmpty()) {
        return null;
    }
    if (!(objects.get(0) instanceof EditPart)) {
        return null;
    }
    EditPart object = (EditPart) objects.get(0);
    // for TUP-1015
    boolean isConnAttachedJLTriggerComp = false;
    ConnectionPart connectionPart = null;
    if (object instanceof ConnectionPart) {
        connectionPart = (ConnectionPart) object;
    } else if (object instanceof ConnLabelEditPart) {
        connectionPart = (ConnectionPart) object.getParent();
    }
    if (connectionPart != null) {
        Node srcNode = null;
        Object srcModel = connectionPart.getSource().getModel();
        if (srcModel instanceof Node) {
            srcNode = (Node) srcModel;
        }
        Node tarNode = null;
        Object tarModel = connectionPart.getTarget().getModel();
        if (tarModel instanceof Node) {
            tarNode = (Node) tarModel;
        }
        if (srcNode == null || tarNode == null) {
            return null;
        }
        IProcess process = srcNode.getProcess();
        if (AbstractProcessProvider.isExtensionProcessForJoblet(process)) {
            IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
            if (service != null && (service.isTriggerNode(srcNode) || service.isTriggerNode(tarNode))) {
                isConnAttachedJLTriggerComp = true;
            }
        }
    }
    IPreferenceStore preferenceStore = DesignerPlugin.getDefault().getPreferenceStore();
    String preKey = TalendDesignerPrefConstants.NOT_SHOW_WARNING_WHEN_DELETE_LINK_WITH_JOBLETTRIGGERLINKCOMPONENT;
    if (isConnAttachedJLTriggerComp && !preferenceStore.getBoolean(preKey)) {
        MessageDialogWithToggle jlTriggerConfirmDialog = new MessageDialogWithToggle(null, //$NON-NLS-1$
        Messages.getString("GEFDeleteAction.deleteConnectionDialog.title"), // accept the default window icon
        null, Messages.getString("GEFDeleteAction.deleteConnectionDialog.msg"), MessageDialog.WARNING, new String[] { //$NON-NLS-1$
        IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0, //$NON-NLS-1$
        Messages.getString("GEFDeleteAction.deleteConnectionDialog.toggleMsg"), preferenceStore.getDefaultBoolean(preKey));
        jlTriggerConfirmDialog.setPrefStore(preferenceStore);
        jlTriggerConfirmDialog.setPrefKey(preKey);
        if (jlTriggerConfirmDialog.open() != IDialogConstants.YES_ID) {
            return null;
        }
        preferenceStore.setValue(preKey, jlTriggerConfirmDialog.getToggleState());
    }
    List nodeParts = new ArrayList();
    List noteParts = new ArrayList();
    List others = new ArrayList(objects);
    for (Object o : objects) {
        if (o instanceof NodePart) {
            others.remove(o);
            Node model = (Node) ((NodePart) o).getModel();
            if (model.getJobletNode() != null) {
                continue;
            }
            if (model.getJunitNode() != null) {
                continue;
            }
            nodeParts.add(o);
        } else if (o instanceof NoteEditPart) {
            noteParts.add(o);
            others.remove(o);
        } else if (o instanceof SubjobContainerPart) {
            others.remove(o);
            SubjobContainerPart subjob = (SubjobContainerPart) o;
            for (Iterator iterator = subjob.getChildren().iterator(); iterator.hasNext(); ) {
                NodeContainerPart nodeContainerPart = (NodeContainerPart) iterator.next();
                if (nodeContainerPart instanceof JobletContainerPart) {
                    JobletContainer jobletCon = (JobletContainer) ((JobletContainerPart) nodeContainerPart).getModel();
                    JobletContainerFigure jobletFigure = (JobletContainerFigure) ((JobletContainerPart) nodeContainerPart).getFigure();
                    if (!jobletCon.isCollapsed()) {
                        jobletFigure.doCollapse();
                    }
                }
                NodePart nodePart = nodeContainerPart.getNodePart();
                if (nodePart != null) {
                    Node model = (Node) nodePart.getModel();
                    if (model.getJunitNode() != null) {
                        continue;
                    }
                    nodeParts.add(nodePart);
                }
            }
        }
    }
    if (others.size() == 0) {
        // so notes & nodes only
        CompoundCommand cpdCmd = new CompoundCommand();
        //$NON-NLS-1$
        cpdCmd.setLabel(Messages.getString("GEFDeleteAction.DeleteItems"));
        if (nodeParts.size() != 0) {
            GroupRequest deleteReq = new GroupRequest(RequestConstants.REQ_DELETE);
            deleteReq.setEditParts(nodeParts);
            cpdCmd.add(((NodePart) nodeParts.get(0)).getCommand(deleteReq));
        }
        if (noteParts.size() != 0) {
            GroupRequest deleteReq = new GroupRequest(RequestConstants.REQ_DELETE);
            deleteReq.setEditParts(noteParts);
            cpdCmd.add(((NoteEditPart) noteParts.get(0)).getCommand(deleteReq));
        }
        return cpdCmd;
    } else {
        GroupRequest deleteReq = new GroupRequest(RequestConstants.REQ_DELETE);
        deleteReq.setEditParts(objects);
        Command cmd = object.getCommand(deleteReq);
        return cmd;
    }
}
Also used : NodeContainerPart(org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart) JobletContainer(org.talend.designer.core.ui.editor.jobletcontainer.JobletContainer) Node(org.talend.designer.core.ui.editor.nodes.Node) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) EditPart(org.eclipse.gef.EditPart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart) ArrayList(java.util.ArrayList) NoteEditPart(org.talend.designer.core.ui.editor.notes.NoteEditPart) JobletContainerPart(org.talend.designer.core.ui.editor.jobletcontainer.JobletContainerPart) ConnectionPart(org.talend.designer.core.ui.editor.connections.ConnectionPart) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) IJobletProviderService(org.talend.core.ui.IJobletProviderService) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) GroupRequest(org.eclipse.gef.requests.GroupRequest) Iterator(java.util.Iterator) JobletContainerFigure(org.talend.designer.core.ui.editor.jobletcontainer.JobletContainerFigure) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) ArrayList(java.util.ArrayList) List(java.util.List) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) NodePart(org.talend.designer.core.ui.editor.nodes.NodePart) ConnLabelEditPart(org.talend.designer.core.ui.editor.connections.ConnLabelEditPart) IProcess(org.talend.core.model.process.IProcess)

Example 37 with MessageDialogWithToggle

use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project tdi-studio-se by Talend.

the class ApplicationWorkbenchWindowAdvisor method preWindowShellClose.

public boolean preWindowShellClose() {
    if (PlatformUI.getWorkbench().getWorkbenchWindowCount() > 1) {
        return true;
    }
    // the user has asked to close the last window, while will cause the
    // workbench to close in due course - prompt the user for confirmation
    IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore();
    boolean promptOnExit = store.getBoolean(IDEInternalPreferences.EXIT_PROMPT_ON_CLOSE_LAST_WINDOW);
    if (promptOnExit) {
        String message;
        // String productName = null;
        //
        // if (productName == null) {
        // // message = IDEWorkbenchMessages.PromptOnExitDialog_message0;
        // message = Messages.getString("ApplicationWorkbenchWindowAdvisor.PromptOnExitDialog_message0");
        // }
        // else {
        // // message = NLS.bind(IDEWorkbenchMessages.PromptOnExitDialog_message1, productName);
        // message = Messages.getString("ApplicationWorkbenchWindowAdvisor.PromptOnExitDialog_message1",
        // new Object[] { productName });
        // }
        //$NON-NLS-1$
        message = Messages.getString("ApplicationWorkbenchWindowAdvisor.PromptOnExitDialog_message0");
        MessageDialogWithToggle dlg = MessageDialogWithToggle.openOkCancelConfirm(getWindowConfigurer().getWindow().getShell(), //$NON-NLS-1$
        Messages.getString("ApplicationWorkbenchWindowAdvisor.PromptOnExitDialog_shellTitle"), //$NON-NLS-1$
        message, Messages.getString("ApplicationWorkbenchWindowAdvisor.PromptOnExitDialog_choice"), false, null, //$NON-NLS-1$
        null);
        if (dlg.getReturnCode() != IDialogConstants.OK_ID) {
            return false;
        }
        if (dlg.getToggleState()) {
            store.setValue(IDEInternalPreferences.EXIT_PROMPT_ON_CLOSE_LAST_WINDOW, false);
            IDEWorkbenchPlugin.getDefault().savePluginPreferences();
        }
    }
    return true;
}
Also used : MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 38 with MessageDialogWithToggle

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

the class LineNumberColumn method ensureQuickDiffProvider.

/**
 * Ensures that quick diff information is displayed and the quick diff provider is the one with
 * the specified id. If a different quick diff provider is in use, the user may be asked whether
 * he wants to switch.
 *
 * @param diffProviderId the quick diff provider id to use
 * @return <code>true</code> if quick diff could be enabled for the given id,
 *         <code>false</code> otherwise
 */
private boolean ensureQuickDiffProvider(String diffProviderId) {
    if (!isShowingChangeInformation())
        // FIXME pass provider id
        installChangeRulerModel(fDelegate);
    IAnnotationModel annotationModel = fViewer.getAnnotationModel();
    IAnnotationModel oldDiffer = getDiffer();
    if (oldDiffer == null && annotationModel != null)
        // quick diff is enabled, but no differ? not working for whatever reason
        return false;
    if (annotationModel == null)
        annotationModel = new AnnotationModel();
    if (!(annotationModel instanceof IAnnotationModelExtension))
        return false;
    QuickDiff util = new QuickDiff();
    Object oldDifferId = util.getConfiguredQuickDiffProvider(oldDiffer);
    if (oldDifferId.equals(diffProviderId)) {
        if (oldDiffer instanceof ILineDifferExtension)
            ((ILineDifferExtension) oldDiffer).resume();
        return true;
    }
    // Check whether the desired provider is available at all
    IAnnotationModel newDiffer = util.createQuickDiffAnnotationModel(getEditor(), diffProviderId);
    if (util.getConfiguredQuickDiffProvider(newDiffer).equals(oldDifferId)) {
        if (oldDiffer instanceof ILineDifferExtension)
            ((ILineDifferExtension) oldDiffer).resume();
        return true;
    }
    // quick diff is showing with the wrong provider - ask the user whether he wants to switch
    IPreferenceStore store = EditorsUI.getPreferenceStore();
    if (oldDiffer != null && !store.getString(REVISION_ASK_BEFORE_QUICKDIFF_SWITCH_KEY).equals(MessageDialogWithToggle.ALWAYS)) {
        MessageDialogWithToggle toggleDialog = MessageDialogWithToggle.openOkCancelConfirm(fViewer.getTextWidget().getShell(), RulerMessages.AbstractDecoratedTextEditor_revision_quickdiff_switch_title, RulerMessages.AbstractDecoratedTextEditor_revision_quickdiff_switch_message, RulerMessages.AbstractDecoratedTextEditor_revision_quickdiff_switch_rememberquestion, true, store, REVISION_ASK_BEFORE_QUICKDIFF_SWITCH_KEY);
        if (toggleDialog.getReturnCode() != Window.OK)
            return false;
    }
    IAnnotationModelExtension modelExtension = (IAnnotationModelExtension) annotationModel;
    modelExtension.removeAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID);
    modelExtension.addAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID, newDiffer);
    if (fDelegate instanceof IChangeRulerColumn)
        // picks up the new model attachment
        ((IChangeRulerColumn) fDelegate).setModel(annotationModel);
    return true;
}
Also used : QuickDiff(org.eclipse.ui.texteditor.quickdiff.QuickDiff) IChangeRulerColumn(org.eclipse.jface.text.source.IChangeRulerColumn) ILineDifferExtension(org.eclipse.jface.text.source.ILineDifferExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 39 with MessageDialogWithToggle

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

the class IntroPage method showMissingBrowserWarning.

private void showMissingBrowserWarning(final IWebBrowser browser) {
    IPersistentPreferenceStore prefStore = (IPersistentPreferenceStore) KNIMEUIPlugin.getDefault().getPreferenceStore();
    boolean omitWarnings = prefStore.getBoolean(PreferenceConstants.P_OMIT_MISSING_BROWSER_WARNING);
    if (!omitWarnings) {
        MessageDialogWithToggle dialog = MessageDialogWithToggle.openWarning(Display.getDefault().getActiveShell(), "Missing browser integration", "KNIME is unable to display web pages in an internal browser. This may be caused by missing " + "system libraries. Please visit https://www.knime.com/faq#q6 for details.\n" + "Some web pages may open in an external browser.", "Do not show again", false, prefStore, PreferenceConstants.P_OMIT_MISSING_BROWSER_WARNING);
        if (dialog.getToggleState()) {
            prefStore.setValue(PreferenceConstants.P_OMIT_MISSING_BROWSER_WARNING, true);
            try {
                prefStore.save();
            } catch (IOException ex) {
            // too bad, ignore it
            }
        }
    }
}
Also used : MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) IOException(java.io.IOException) IPersistentPreferenceStore(org.eclipse.jface.preference.IPersistentPreferenceStore)

Example 40 with MessageDialogWithToggle

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

the class GUIWorkflowLoadHelper method shouldLoadNightlyBuildWorkflow.

/**
 * Called from {@link #getUnknownKNIMEVersionLoadPolicy(LoadVersion, Version, boolean)} when loading a
 * workflow created by a current or old nightly build version. Requires special treatment as per AP-8642.
 */
private UnknownKNIMEVersionLoadPolicy shouldLoadNightlyBuildWorkflow(final LoadVersion workflowKNIMEVersion, final Version createdByKNIMEVersion) {
    final IPreferenceStore store = KNIMEUIPlugin.getDefault().getPreferenceStore();
    boolean confirmLoadNightlyBuild = store.getBoolean(PreferenceConstants.P_CONFIRM_LOAD_NIGHTLY_BUILD_WORKFLOW);
    if (!confirmLoadNightlyBuild) {
        return UnknownKNIMEVersionLoadPolicy.Try;
    }
    StringBuilder e = new StringBuilder("You are attempting to load a workflow created with a nightly build (");
    if (createdByKNIMEVersion != null) {
        e.append(createdByKNIMEVersion);
    } else {
        e.append("<unknown>");
    }
    e.append("-nightly). This can lead to issues with the officially released version of some nodes.\n\n");
    e.append(LOAD_FUTURE_FLOW_TEXT);
    // must not change to something else than this as MessageDialogWithToggle has some special magic to re-index
    // buttons -- see org.eclipse.jface.dialogs.MessageDialogWithToggle.createButtonsForButtonBar(Composite)
    // must use jface button label as per org.eclipse.jface.dialogs.MessageDialogWithToggle.mapButtonLabelToButtonID
    // (this is very different to the behavior of MessageDialog(NoToggle))
    String cancel = IDialogConstants.CANCEL_LABEL;
    String loadAnyway = "&Load Anyway";
    final String[] labels = new String[] { cancel, loadAnyway };
    final AtomicReference<UnknownKNIMEVersionLoadPolicy> result = new AtomicReference<>(UnknownKNIMEVersionLoadPolicy.Abort);
    m_display.syncExec(new Runnable() {

        @Override
        public void run() {
            MessageDialogWithToggle dialog = new MessageDialogWithToggle(m_display.getActiveShell(), "Loading Workflow created by a Nightly Build", null, e.toString(), MessageDialog.WARNING, labels, 0, "Always load workflows created by a Nightly Build", false);
            switch(dialog.open()) {
                // Cancel button
                case IDialogConstants.CANCEL_ID:
                case // cancel by 'esc'
                SWT.DEFAULT:
                    result.set(UnknownKNIMEVersionLoadPolicy.Abort);
                    break;
                default:
                    result.set(UnknownKNIMEVersionLoadPolicy.Try);
                    if (dialog.getToggleState()) {
                        store.setValue(PreferenceConstants.P_CONFIRM_LOAD_NIGHTLY_BUILD_WORKFLOW, false);
                        KNIMEUIPlugin.getDefault().savePluginPreferences();
                    }
            }
        }
    });
    return result.get();
}
Also used : MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) AtomicReference(java.util.concurrent.atomic.AtomicReference) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Aggregations

MessageDialogWithToggle (org.eclipse.jface.dialogs.MessageDialogWithToggle)66 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