Search in sources :

Example 21 with MessageDialogWithToggle

use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project mdw-designer by CenturyLinkCloud.

the class JavaSourceHyperlink method getJavaElement.

/**
 * find the source element in the project
 *
 * @param type
 * @return the source element
 * @throws JavaModelException
 * @throws CoreException
 */
protected Object getJavaElement(String type) throws JavaModelException, CoreException {
    Object element = null;
    if (project == null) {
        cantFindSourceWarning();
        return null;
    }
    if (element == null) {
        QualifiedName qName = new QualifiedName(MdwPlugin.getPluginId(), "MdwSourceLookupAllJavaProjects");
        String setting = project.getProject().getPersistentProperty(qName);
        boolean check = (setting != null && Boolean.valueOf(setting));
        if (!check) {
            String msg = "Can't locate source code for:\n" + getTypeName() + (project == null ? "" : " in project " + project.getProject().getName());
            String toggleMessage = "Look in all workspace Java projects for this deployment.";
            MessageDialogWithToggle dialog = MessageDialogWithToggle.openInformation(MdwPlugin.getShell(), "Java Source Lookup", msg, toggleMessage, false, null, null);
            check = dialog.getToggleState();
            project.getProject().setPersistentProperty(qName, String.valueOf(check));
        }
        if (check) {
            IJavaModel javaModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
            for (IJavaProject javaProj : javaModel.getJavaProjects()) {
                Object javaElem = getJavaElement(javaProj, type);
                if (javaElem != null) {
                    element = javaElem;
                    break;
                }
            }
        }
    }
    return element;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) QualifiedName(org.eclipse.core.runtime.QualifiedName) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) IJavaModel(org.eclipse.jdt.core.IJavaModel)

Example 22 with MessageDialogWithToggle

use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project bndtools by bndtools.

the class RepositoryBundleSelectionPart method createSection.

void createSection(Section section, FormToolkit toolkit) {
    // Toolbar buttons
    ToolBar toolbar = new ToolBar(section, SWT.FLAT);
    section.setTextClient(toolbar);
    fillToolBar(toolbar);
    Composite composite = toolkit.createComposite(section);
    section.setClient(composite);
    table = toolkit.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL);
    viewer = new TableViewer(table);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(getLabelProvider());
    // Listeners
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ToolItem remove = getRemoveItemTool();
            if (remove != null)
                remove.setEnabled(isRemovable(event.getSelection()));
        }
    });
    ViewerDropAdapter dropAdapter = new ViewerDropAdapter(viewer) {

        @Override
        public void dragEnter(DropTargetEvent event) {
            super.dragEnter(event);
            event.detail = DND.DROP_COPY;
        }

        @Override
        public boolean validateDrop(Object target, int operation, TransferData transferType) {
            if (FileTransfer.getInstance().isSupportedType(transferType))
                return true;
            if (ResourceTransfer.getInstance().isSupportedType(transferType))
                return true;
            if (URLTransfer.getInstance().isSupportedType(transferType))
                return true;
            ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
            if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
                return false;
            }
            Iterator<?> iterator = ((IStructuredSelection) selection).iterator();
            while (iterator.hasNext()) {
                if (!selectionIsDroppable(iterator.next())) {
                    return false;
                }
            }
            return true;
        }

        private boolean selectionIsDroppable(Object element) {
            return element instanceof RepositoryBundle || element instanceof RepositoryBundleVersion || element instanceof ProjectBundle || element instanceof RepositoryResourceElement;
        }

        @Override
        public boolean performDrop(Object data) {
            TransferData transfer = getCurrentEvent().currentDataType;
            if (URLTransfer.getInstance().isSupportedType(transfer)) {
                String urlStr = (String) URLTransfer.getInstance().nativeToJava(transfer);
                return handleURLDrop(urlStr);
            } else if (data instanceof String[]) {
                return handleFileNameDrop((String[]) data);
            } else if (data instanceof IResource[]) {
                return handleResourceDrop((IResource[]) data);
            } else {
                return handleSelectionDrop();
            }
        }

        private boolean handleResourceDrop(IResource[] resources) {
            File[] files = new File[resources.length];
            for (int i = 0; i < resources.length; i++) {
                files[i] = resources[i].getLocation().toFile();
            }
            return handleFileDrop(files);
        }

        private boolean handleFileNameDrop(String[] paths) {
            File[] files = new File[paths.length];
            for (int i = 0; i < paths.length; i++) {
                files[i] = new File(paths[i]);
            }
            return handleFileDrop(files);
        }

        private boolean handleFileDrop(File[] files) {
            if (files.length > 0) {
                BndPreferences prefs = new BndPreferences();
                boolean hideWarning = prefs.getHideWarningExternalFile();
                if (!hideWarning) {
                    MessageDialogWithToggle dialog = MessageDialogWithToggle.openWarning(getSection().getShell(), "Add External Files", "External files cannot be directly added to a project, they must be added to a local repository first.", "Do not show this warning again.", false, null, null);
                    if (Window.CANCEL == dialog.getReturnCode())
                        return false;
                    if (dialog.getToggleState()) {
                        prefs.setHideWarningExternalFile(true);
                    }
                }
                AddFilesToRepositoryWizard wizard = new AddFilesToRepositoryWizard(null, files);
                WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
                if (Window.OK == dialog.open()) {
                    List<Pair<String, String>> addingBundles = wizard.getSelectedBundles();
                    List<VersionedClause> addingClauses = new ArrayList<VersionedClause>(addingBundles.size());
                    for (Pair<String, String> addingBundle : addingBundles) {
                        Attrs attribs = new Attrs();
                        attribs.put(Constants.VERSION_ATTRIBUTE, addingBundle.getSecond());
                        addingClauses.add(new VersionedClause(addingBundle.getFirst(), attribs));
                    }
                    handleAdd(addingClauses);
                }
                return true;
            }
            return false;
        }

        private boolean handleSelectionDrop() {
            ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
            if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
                return false;
            }
            List<VersionedClause> adding = new LinkedList<VersionedClause>();
            Iterator<?> iterator = ((IStructuredSelection) selection).iterator();
            while (iterator.hasNext()) {
                Object item = iterator.next();
                if (item instanceof RepositoryBundle) {
                    VersionedClause newClause = RepositoryBundleUtils.convertRepoBundle((RepositoryBundle) item);
                    adding.add(newClause);
                } else if (item instanceof RepositoryBundleVersion) {
                    RepositoryBundleVersion bundleVersion = (RepositoryBundleVersion) item;
                    VersionedClause newClause = RepositoryBundleUtils.convertRepoBundleVersion(bundleVersion, phase);
                    adding.add(newClause);
                } else if (item instanceof RepositoryResourceElement) {
                    RepositoryResourceElement elt = (RepositoryResourceElement) item;
                    VersionedClause newClause = RepositoryBundleUtils.convertRepoBundleVersion(elt.getRepositoryBundleVersion(), phase);
                    adding.add(newClause);
                }
            }
            handleAdd(adding);
            return true;
        }

        private boolean handleURLDrop(String urlStr) {
            try {
                URI uri = new URI(sanitizeUrl(urlStr));
                AddJpmDependenciesWizard wizard = new AddJpmDependenciesWizard(uri);
                WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
                if (dialog.open() == Window.OK) {
                    Set<ResourceDescriptor> resources = wizard.getResult();
                    List<VersionedClause> newBundles = new ArrayList<VersionedClause>(resources.size());
                    for (ResourceDescriptor resource : resources) {
                        Attrs attrs = new Attrs();
                        attrs.put(Constants.VERSION_ATTRIBUTE, resource.version != null ? resource.version.toString() : Version.emptyVersion.toString());
                        VersionedClause clause = new VersionedClause(resource.bsn, attrs);
                        newBundles.add(clause);
                    }
                    handleAdd(newBundles);
                    return true;
                }
                return false;
            } catch (URISyntaxException e) {
                MessageDialog.openError(getSection().getShell(), "Error", "The dropped URL was invalid: " + urlStr);
                return false;
            }
        }

        private String sanitizeUrl(String urlStr) {
            int newline = urlStr.indexOf('\n');
            if (newline > -1)
                return urlStr.substring(0, newline).trim();
            return urlStr;
        }

        private void handleAdd(Collection<VersionedClause> newClauses) {
            if (newClauses == null || newClauses.isEmpty())
                return;
            List<VersionedClause> toAdd = new LinkedList<VersionedClause>();
            for (VersionedClause newClause : newClauses) {
                boolean found = false;
                for (ListIterator<VersionedClause> iter = bundles.listIterator(); iter.hasNext(); ) {
                    VersionedClause existing = iter.next();
                    if (newClause.getName().equals(existing.getName())) {
                        int index = iter.previousIndex();
                        iter.set(newClause);
                        viewer.replace(newClause, index);
                        found = true;
                        break;
                    }
                }
                if (!found)
                    toAdd.add(newClause);
            }
            bundles.addAll(toAdd);
            viewer.add(toAdd.toArray());
            markDirty();
        }
    };
    dropAdapter.setFeedbackEnabled(false);
    dropAdapter.setExpandEnabled(false);
    viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance(), ResourceTransfer.getInstance(), URLTransfer.getInstance() }, dropAdapter);
    table.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.character == SWT.DEL) {
                doRemove();
            } else if (e.character == '+') {
                doAdd();
            }
        }
    });
    // Layout
    GridLayout layout = new GridLayout(1, false);
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = 50;
    gd.heightHint = getTableHeightHint();
    table.setLayoutData(gd);
}
Also used : RepositoryBundle(bndtools.model.repo.RepositoryBundle) RepositoryBundleVersion(bndtools.model.repo.RepositoryBundleVersion) BndPreferences(bndtools.preferences.BndPreferences) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) KeyAdapter(org.eclipse.swt.events.KeyAdapter) ArrayList(java.util.ArrayList) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ProjectBundle(bndtools.model.repo.ProjectBundle) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) LinkedList(java.util.LinkedList) Collection(java.util.Collection) File(java.io.File) AddFilesToRepositoryWizard(bndtools.wizards.workspace.AddFilesToRepositoryWizard) Attrs(aQute.bnd.header.Attrs) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) TransferData(org.eclipse.swt.dnd.TransferData) ISelection(org.eclipse.jface.viewers.ISelection) ToolItem(org.eclipse.swt.widgets.ToolItem) Pair(bndtools.types.Pair) Composite(org.eclipse.swt.widgets.Composite) ViewerDropAdapter(org.eclipse.jface.viewers.ViewerDropAdapter) RepositoryResourceElement(bndtools.model.repo.RepositoryResourceElement) ToolBar(org.eclipse.swt.widgets.ToolBar) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) AddJpmDependenciesWizard(org.bndtools.core.ui.wizards.jpm.AddJpmDependenciesWizard) TableViewer(org.eclipse.jface.viewers.TableViewer) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IResource(org.eclipse.core.resources.IResource) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Example 23 with MessageDialogWithToggle

use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project pentaho-kettle by pentaho.

the class GUIResource method messageDialogWithToggle.

/**
 * Generic popup with a toggle option
 */
public Object[] messageDialogWithToggle(Shell shell, String dialogTitle, Image image, String message, int dialogImageType, String[] buttonLabels, int defaultIndex, String toggleMessage, boolean toggleState) {
    int imageType = 0;
    if (dialogImageType == Const.WARNING) {
        imageType = MessageDialog.WARNING;
    }
    MessageDialogWithToggle md = new MessageDialogWithToggle(shell, dialogTitle, image, message, imageType, buttonLabels, defaultIndex, toggleMessage, toggleState);
    int idx = md.open();
    return new Object[] { idx, md.getToggleState() };
}
Also used : MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) Point(org.eclipse.swt.graphics.Point)

Example 24 with MessageDialogWithToggle

use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project pentaho-kettle by pentaho.

the class GroupByDialog method ok.

private void ok() {
    if (Utils.isEmpty(wStepname.getText())) {
        return;
    }
    int sizegroup = wGroup.nrNonEmpty();
    int nrfields = wAgg.nrNonEmpty();
    input.setPrefix(wPrefix.getText());
    input.setDirectory(wSortDir.getText());
    input.setLineNrInGroupField(wLineNrField.getText());
    input.setAlwaysGivingBackOneRow(wAlwaysAddResult.getSelection());
    input.setPassAllRows(wAllRows.getSelection());
    input.allocate(sizegroup, nrfields);
    // CHECKSTYLE:Indentation:OFF
    for (int i = 0; i < sizegroup; i++) {
        TableItem item = wGroup.getNonEmpty(i);
        input.getGroupField()[i] = item.getText(1);
    }
    // CHECKSTYLE:Indentation:OFF
    for (int i = 0; i < nrfields; i++) {
        TableItem item = wAgg.getNonEmpty(i);
        input.getAggregateField()[i] = item.getText(1);
        input.getSubjectField()[i] = item.getText(2);
        input.getAggregateType()[i] = GroupByMeta.getType(item.getText(3));
        input.getValueField()[i] = item.getText(4);
    }
    stepname = wStepname.getText();
    if (sizegroup > 0 && "Y".equalsIgnoreCase(props.getCustomParameter(STRING_SORT_WARNING_PARAMETER, "Y"))) {
        MessageDialogWithToggle md = new MessageDialogWithToggle(shell, BaseMessages.getString(PKG, "GroupByDialog.GroupByWarningDialog.DialogTitle"), null, BaseMessages.getString(PKG, "GroupByDialog.GroupByWarningDialog.DialogMessage", Const.CR) + Const.CR, MessageDialog.WARNING, new String[] { BaseMessages.getString(PKG, "GroupByDialog.GroupByWarningDialog.Option1") }, 0, BaseMessages.getString(PKG, "GroupByDialog.GroupByWarningDialog.Option2"), "N".equalsIgnoreCase(props.getCustomParameter(STRING_SORT_WARNING_PARAMETER, "Y")));
        MessageDialogWithToggle.setDefaultImage(GUIResource.getInstance().getImageSpoon());
        md.open();
        props.setCustomParameter(STRING_SORT_WARNING_PARAMETER, md.getToggleState() ? "N" : "Y");
        props.saveProps();
    }
    dispose();
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle)

Example 25 with MessageDialogWithToggle

use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project pentaho-kettle by pentaho.

the class UniqueRowsDialog method ok.

private void ok() {
    if (Utils.isEmpty(wStepname.getText())) {
        return;
    }
    int nrfields = wFields.nrNonEmpty();
    input.allocate(nrfields);
    // CHECKSTYLE:Indentation:OFF
    for (int i = 0; i < nrfields; i++) {
        TableItem item = wFields.getNonEmpty(i);
        input.getCompareFields()[i] = item.getText(1);
        input.getCaseInsensitive()[i] = "Y".equalsIgnoreCase(item.getText(2));
    }
    input.setCountField(wCountField.getText());
    input.setCountRows(wCount.getSelection());
    input.setRejectDuplicateRow(wRejectDuplicateRow.getSelection());
    input.setErrorDescription(wErrorDesc.getText());
    // return value
    stepname = wStepname.getText();
    if ("Y".equalsIgnoreCase(props.getCustomParameter(STRING_SORT_WARNING_PARAMETER, "Y"))) {
        MessageDialogWithToggle md = new MessageDialogWithToggle(shell, BaseMessages.getString(PKG, "UniqueRowsDialog.InputNeedSort.DialogTitle"), null, BaseMessages.getString(PKG, "UniqueRowsDialog.InputNeedSort.DialogMessage", Const.CR) + Const.CR, MessageDialog.WARNING, new String[] { BaseMessages.getString(PKG, "UniqueRowsDialog.InputNeedSort.Option1") }, 0, BaseMessages.getString(PKG, "UniqueRowsDialog.InputNeedSort.Option2"), "N".equalsIgnoreCase(props.getCustomParameter(STRING_SORT_WARNING_PARAMETER, "Y")));
        MessageDialogWithToggle.setDefaultImage(GUIResource.getInstance().getImageSpoon());
        md.open();
        props.setCustomParameter(STRING_SORT_WARNING_PARAMETER, md.getToggleState() ? "N" : "Y");
        props.saveProps();
    }
    // Remove any error hops coming out of UniqueRows when Reject Duplicate Rows checkbox is unselected.
    if (wRejectDuplicateRow.getSelection() == false) {
        List<TransHopMeta> hops = this.transMeta.getTransHops();
        IntStream.range(0, hops.size()).filter(hopInd -> {
            TransHopMeta hop = hops.get(hopInd);
            return (hop.isErrorHop() && hop.getFromStep().getName().equals(this.input.getParentStepMeta().getName()));
        }).forEach(hopInd -> this.transMeta.removeTransHop(hopInd));
    }
    dispose();
}
Also used : IntStream(java.util.stream.IntStream) KettleException(org.pentaho.di.core.exception.KettleException) StepDialogInterface(org.pentaho.di.trans.step.StepDialogInterface) GUIResource(org.pentaho.di.ui.core.gui.GUIResource) HashMap(java.util.HashMap) TextVar(org.pentaho.di.ui.core.widget.TextVar) Event(org.eclipse.swt.widgets.Event) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ArrayList(java.util.ArrayList) TransMeta(org.pentaho.di.trans.TransMeta) Const(org.pentaho.di.core.Const) Listener(org.eclipse.swt.widgets.Listener) Map(java.util.Map) TableView(org.pentaho.di.ui.core.widget.TableView) BaseStepDialog(org.pentaho.di.ui.trans.step.BaseStepDialog) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) UniqueRowsMeta(org.pentaho.di.trans.steps.uniquerows.UniqueRowsMeta) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) BaseMessages(org.pentaho.di.i18n.BaseMessages) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) StepMeta(org.pentaho.di.trans.step.StepMeta) Text(org.eclipse.swt.widgets.Text) Shell(org.eclipse.swt.widgets.Shell) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) FormLayout(org.eclipse.swt.layout.FormLayout) ShellEvent(org.eclipse.swt.events.ShellEvent) FormData(org.eclipse.swt.layout.FormData) Set(java.util.Set) FormAttachment(org.eclipse.swt.layout.FormAttachment) Display(org.eclipse.swt.widgets.Display) Utils(org.pentaho.di.core.util.Utils) ShellAdapter(org.eclipse.swt.events.ShellAdapter) Group(org.eclipse.swt.widgets.Group) List(java.util.List) TransHopMeta(org.pentaho.di.trans.TransHopMeta) ModifyListener(org.eclipse.swt.events.ModifyListener) SWT(org.eclipse.swt.SWT) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Label(org.eclipse.swt.widgets.Label) ColumnInfo(org.pentaho.di.ui.core.widget.ColumnInfo) TableItem(org.eclipse.swt.widgets.TableItem) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) TransHopMeta(org.pentaho.di.trans.TransHopMeta)

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