Search in sources :

Example 6 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 7 with MessageDialogWithToggle

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

the class JavaCamelJobScriptsExportWSWizardPage method finish.

@Override
public boolean finish() {
    String version = getSelectedJobVersion();
    String destinationKar = getDestinationValue();
    JavaCamelJobScriptsExportWSAction action = null;
    IRunnableWithProgress actionMS = null;
    Map<ExportChoice, Object> exportChoiceMap = getExportChoiceMap();
    boolean needMavenScript = exportChoiceMap.containsKey(ExportChoice.needMavenScript) && exportChoiceMap.get(ExportChoice.needMavenScript) == Boolean.TRUE;
    if (needMavenScript && destinationKar.regionMatches(true, destinationKar.length() - 4, ".kar", 0, 4)) {
        destinationKar = destinationKar.substring(0, destinationKar.length() - 3) + "zip";
    }
    if (new File(destinationKar).exists()) {
        boolean yes = MessageDialog.openQuestion(getShell(), Messages.getString("JavaCamelJobScriptsExportWSWizardPage.OverwriteKarTitle"), Messages.getString("JavaCamelJobScriptsExportWSWizardPage.OverwriteKarMessage"));
        if (!yes) {
            return false;
        }
    }
    if (exportTypeCombo.getText().equals(EXPORTTYPE_SPRING_BOOT)) {
        Bundle bundle = Platform.getBundle(PluginChecker.EXPORT_ROUTE_PLUGIN_ID);
        try {
            if (bundle != null) {
                // Get m2e preferences
                boolean mvnOffline = Platform.getPreferencesService().getBoolean(M2E_CORE, M2_OFFLINE, false, null);
                if (mvnOffline) {
                    // Change mvn to online ONLY if maven is offline needs run this part
                    IPreferenceStore camelStore = CamelDesignerPlugin.getDefault().getPreferenceStore();
                    // camelStore.setValue(TOGGLE_MAVEN_ONLINE, MessageDialogWithToggle.NEVER); //for bebug
                    if (!MessageDialogWithToggle.ALWAYS.equals(camelStore.getString(TOGGLE_MVN_ONLINE))) {
                        MessageDialogWithToggle dlg = MessageDialogWithToggle.openOkCancelConfirm(getShell(), Messages.getString("JavaCamelJobScriptsExportWSWizardPage.MavenConfirm"), Messages.getString("JavaCamelJobScriptsExportWSWizardPage.MavenMesssage"), Messages.getString("JavaCamelJobScriptsExportWSWizardPage.ShowItAgain"), false, camelStore, TOGGLE_MVN_ONLINE);
                        if (dlg.getReturnCode() != IDialogConstants.OK_ID) {
                            return false;
                        }
                    }
                    InstanceScope.INSTANCE.getNode(M2E_CORE).putBoolean(M2_OFFLINE, false);
                }
                Class<?> javaCamelJobScriptsExportMicroServiceAction = bundle.loadClass("org.talend.resources.export.maven.action.JavaCamelJobScriptsExportMicroServiceAction");
                Constructor<?> constructor = javaCamelJobScriptsExportMicroServiceAction.getConstructor(Map.class, List.class, String.class, String.class, String.class);
                actionMS = (IRunnableWithProgress) constructor.newInstance(exportChoiceMap, Arrays.asList(getCheckNodes()), version, destinationKar, "");
                try {
                    getContainer().run(false, true, actionMS);
                } catch (Exception e) {
                    MessageBoxExceptionHandler.process(e.getCause(), getShell());
                    return false;
                } finally {
                    if (mvnOffline) {
                        // restore maven status
                        InstanceScope.INSTANCE.getNode(M2E_CORE).putBoolean(M2_OFFLINE, mvnOffline);
                    }
                }
            }
        } catch (Exception e) {
            MessageBoxExceptionHandler.process(e.getCause(), getShell());
            e.printStackTrace();
        }
    } else {
        if (needMavenScript) {
            action = new JavaCamelJobScriptsExportWithMavenAction(exportChoiceMap, nodes[0], version, destinationKar, false);
        } else {
            action = new JavaCamelJobScriptsExportWSAction(nodes[0], version, destinationKar, false);
        }
        try {
            getContainer().run(false, true, action);
        } catch (InvocationTargetException e) {
            MessageBoxExceptionHandler.process(e.getCause(), getShell());
            return false;
        } catch (InterruptedException e) {
            return false;
        }
        manager = action.getManager();
        // save output directory
        manager.setDestinationPath(destinationKar);
        saveWidgetValues();
    }
    return true;
}
Also used : Bundle(org.osgi.framework.Bundle) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice) JavaCamelJobScriptsExportWSAction(org.talend.camel.designer.ui.wizards.actions.JavaCamelJobScriptsExportWSAction) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) JavaCamelJobScriptsExportWithMavenAction(org.talend.camel.designer.ui.wizards.actions.JavaCamelJobScriptsExportWithMavenAction) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) File(java.io.File)

Aggregations

MessageDialogWithToggle (org.eclipse.jface.dialogs.MessageDialogWithToggle)7 ArrayList (java.util.ArrayList)3 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)3 QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)2 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)2 File (java.io.File)2 List (java.util.List)2 Job (org.eclipse.core.runtime.jobs.Job)2 Shell (org.eclipse.swt.widgets.Shell)2 VersionedClause (aQute.bnd.build.model.clauses.VersionedClause)1 Attrs (aQute.bnd.header.Attrs)1 ResourceDescriptor (aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)1 ProjectBundle (bndtools.model.repo.ProjectBundle)1 RepositoryBundle (bndtools.model.repo.RepositoryBundle)1 RepositoryBundleVersion (bndtools.model.repo.RepositoryBundleVersion)1 RepositoryResourceElement (bndtools.model.repo.RepositoryResourceElement)1 BndPreferences (bndtools.preferences.BndPreferences)1 Pair (bndtools.types.Pair)1 AddFilesToRepositoryWizard (bndtools.wizards.workspace.AddFilesToRepositoryWizard)1 AutoPilot (com.ximpleware.AutoPilot)1