Search in sources :

Example 16 with IStructuredContentProvider

use of org.eclipse.jface.viewers.IStructuredContentProvider in project eclipse.platform.text by eclipse.

the class SpellingConfigurationBlock method createProviderViewer.

private ComboViewer createProviderViewer() {
    /* list viewer */
    final ComboViewer viewer = new ComboViewer(fProviderCombo);
    viewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void dispose() {
        }

        @Override
        public void inputChanged(Viewer v, Object oldInput, Object newInput) {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return fProviderDescriptors.values().toArray();
        }
    });
    viewer.setLabelProvider(new LabelProvider() {

        @Override
        public Image getImage(Object element) {
            return null;
        }

        @Override
        public String getText(Object element) {
            return ((SpellingEngineDescriptor) element).getLabel();
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            if (sel.isEmpty())
                return;
            if (fCurrentBlock != null && fStatusMonitor.getStatus() != null && fStatusMonitor.getStatus().matches(IStatus.ERROR))
                if (isPerformRevert()) {
                    ISafeRunnable runnable = new ISafeRunnable() {

                        @Override
                        public void run() throws Exception {
                            fCurrentBlock.performRevert();
                        }

                        @Override
                        public void handleException(Throwable x) {
                        }
                    };
                    SafeRunner.run(runnable);
                } else {
                    revertSelection();
                    return;
                }
            fStore.setValue(SpellingService.PREFERENCE_SPELLING_ENGINE, ((SpellingEngineDescriptor) sel.getFirstElement()).getId());
            updateListDependencies();
        }

        private boolean isPerformRevert() {
            Shell shell = viewer.getControl().getShell();
            MessageDialog dialog = new MessageDialog(shell, TextEditorMessages.SpellingConfigurationBlock_error_title, null, TextEditorMessages.SpellingConfigurationBlock_error_message, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1);
            return dialog.open() == 0;
        }

        private void revertSelection() {
            try {
                viewer.removeSelectionChangedListener(this);
                SpellingEngineDescriptor desc = EditorsUI.getSpellingService().getActiveSpellingEngineDescriptor(fStore);
                if (desc != null)
                    viewer.setSelection(new StructuredSelection(desc), true);
            } finally {
                viewer.addSelectionChangedListener(this);
            }
        }
    });
    viewer.setInput(fProviderDescriptors);
    viewer.refresh();
    return viewer;
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) SpellingEngineDescriptor(org.eclipse.ui.texteditor.spelling.SpellingEngineDescriptor) Shell(org.eclipse.swt.widgets.Shell) ComboViewer(org.eclipse.jface.viewers.ComboViewer) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 17 with IStructuredContentProvider

use of org.eclipse.jface.viewers.IStructuredContentProvider in project linuxtools by eclipse.

the class STDataViewersCSVExporter method export.

public void export(IProgressMonitor monitor) {
    // monitoring
    this.monitor = monitor;
    monitor.beginTask("Exporting to CSV (file: " + getFilePath() + ")", IProgressMonitor.UNKNOWN);
    // save this configuration
    saveState();
    // init the printStream
    initPrintStream(filePath);
    // get the viewer's parameters
    monitor.subTask("collecting viewer's parameters...");
    collectViewerParameters();
    // start dumping to csv file
    dumpColumnHeaders();
    if (input != null) {
        if (contentProvider instanceof ITreeContentProvider) {
            ITreeContentProvider treeContentProvider = (ITreeContentProvider) contentProvider;
            Object[] topElements = treeContentProvider.getElements(input);
            if (topElements != null) {
                // monitoring
                int work = topElements.length;
                for (Object element : topElements) {
                    if (treeContentProvider.hasChildren(element)) {
                        work += treeContentProvider.getChildren(element).length;
                    }
                }
                monitor.beginTask("Exporting to CSV (file: " + getFilePath() + ")", work);
                monitor.subTask("exporting tree data...");
                // monitoring stuff
                int tempWork = 0;
                int workFloor = topElements.length / 100;
                if (workFloor == 0) {
                    workFloor = 1;
                }
                // exporting tree
                Arrays.sort(topElements, comparator);
                for (int i = 0; i < topElements.length; i++) {
                    dumpTreeData(treeContentProvider, topElements[i], "", i == topElements.length - 1, true);
                    // monitoring
                    tempWork++;
                    if (tempWork >= workFloor) {
                        if (monitor.isCanceled()) {
                            ps.close();
                            return;
                        }
                        monitor.worked(tempWork);
                        tempWork = 0;
                    }
                }
                // monitoring
                monitor.worked(tempWork);
            }
        } else if (contentProvider instanceof IStructuredContentProvider) {
            IStructuredContentProvider structContentProvider = (IStructuredContentProvider) contentProvider;
            Object[] topElements = structContentProvider.getElements(input);
            if (topElements != null) {
                // monitoring
                monitor.beginTask("Exporting to CSV (file: " + getFilePath() + ")", topElements.length);
                monitor.subTask("exporting table data...");
                // monitoring stuff
                int tempWork = 0;
                int workFloor = topElements.length / 100;
                if (workFloor == 0) {
                    workFloor = 1;
                }
                // exporting table
                Arrays.sort(topElements, comparator);
                for (int n = 0; n < topElements.length; n++) {
                    if (n < topElements.length - 1) {
                        dumpNodeData(topElements[n], csvChildMarker);
                    } else {
                        dumpNodeData(topElements[n], csvLastChildMarker);
                    }
                    // monitoring
                    tempWork++;
                    if (tempWork >= workFloor) {
                        if (monitor.isCanceled()) {
                            ps.close();
                            return;
                        }
                        monitor.worked(tempWork);
                        tempWork = 0;
                    }
                }
                // monitoring
                monitor.worked(tempWork);
            }
        }
    }
    // close the stream
    ps.close();
    // end monitoring
    monitor.done();
    IFile c = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(getFilePath()));
    if (c != null) {
        try {
            c.refreshLocal(1, new NullProgressMonitor());
        } catch (CoreException e) {
            STDataViewersActivator.getDefault().getLog().log(e.getStatus());
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider)

Example 18 with IStructuredContentProvider

use of org.eclipse.jface.viewers.IStructuredContentProvider in project linuxtools by eclipse.

the class STDataViewersHideShowColumnsDialog method createCheckboxTable.

private CheckboxTableViewer createCheckboxTable(Composite parent, GridData layoutData) {
    CheckboxTableViewer tableViewer = CheckboxTableViewer.newCheckList(parent, SWT.SINGLE | SWT.HIDE_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    tableViewer.getControl().setLayoutData(layoutData);
    tableViewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public Object[] getElements(Object inputElement) {
            if (inputElement instanceof Item[]) {
                Item[] columns = (Item[]) inputElement;
                int[] order = stViewer.getColumnOrder();
                Item[] elements = new Item[columns.length];
                // sort the columns according to their actual display order
                for (int i = columns.length; i-- > 0; ) {
                    elements[i] = columns[order[i]];
                }
                return elements;
            }
            return new Object[] {};
        }

        @Override
        public void dispose() {
        }

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    tableViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof Item) {
                Item column = (Item) element;
                if (manager.getWidth(stViewer.getColumnIndex(column)) == 0) {
                    return column.getText() + " (width = 0)";
                }
                return column.getText();
            }
            return element.toString();
        }
    });
    return tableViewer;
}
Also used : Item(org.eclipse.swt.widgets.Item) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) AbstractSTViewer(org.eclipse.linuxtools.dataviewers.abstractviewers.AbstractSTViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 19 with IStructuredContentProvider

use of org.eclipse.jface.viewers.IStructuredContentProvider in project linuxtools by eclipse.

the class ImageSelectionDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    composite.setLayout(layout);
    composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    Label connLbl = new Label(composite, SWT.NONE);
    connLbl.setText(Messages.ImageSelectionDialog_connection_label);
    ComboViewer connCmb = new ComboViewer(composite, SWT.READ_ONLY);
    connCmb.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
    connCmb.setContentProvider(new IStructuredContentProvider() {

        @Override
        public Object[] getElements(Object inputElement) {
            for (IDockerConnection conn : DockerConnectionManager.getInstance().getAllConnections()) {
                try {
                    ((DockerConnection) conn).open(false);
                } catch (DockerException e) {
                }
            }
            return DockerConnectionManager.getInstance().getAllConnections().stream().filter(c -> c.isOpen()).toArray(size -> new IDockerConnection[size]);
        }
    });
    // $NON-NLS-1$
    connCmb.setInput("place_holder");
    Label imageLbl = new Label(composite, SWT.NONE);
    imageLbl.setText(Messages.ImageSelectionDialog_image_label);
    ComboViewer imageCmb = new ComboViewer(composite, SWT.READ_ONLY);
    imageCmb.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
    imageCmb.setContentProvider(new IStructuredContentProvider() {

        @Override
        public Object[] getElements(Object inputElement) {
            IDockerConnection conn = (IDockerConnection) inputElement;
            return conn.getImages().stream().filter(// $NON-NLS-1$
            i -> !i.repoTags().get(0).equals("<none>:<none>")).toArray(size -> new IDockerImage[size]);
        }
    });
    imageCmb.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            IDockerImage img = (IDockerImage) element;
            return img.repoTags().get(0);
        }
    });
    imageCmb.setInput(null);
    connCmb.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = event.getStructuredSelection();
            IDockerConnection conn = (IDockerConnection) sel.getFirstElement();
            connection = conn;
            imageCmb.setInput(conn);
        }
    });
    imageCmb.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = event.getStructuredSelection();
            IDockerImage img = (IDockerImage) sel.getFirstElement();
            image = img;
            getOkButton().setEnabled(true);
        }
    });
    return composite;
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Shell(org.eclipse.swt.widgets.Shell) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) DockerConnectionManager(org.eclipse.linuxtools.docker.core.DockerConnectionManager) SelectionDialog(org.eclipse.ui.dialogs.SelectionDialog) Display(org.eclipse.swt.widgets.Display) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ComboViewer(org.eclipse.jface.viewers.ComboViewer) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) Composite(org.eclipse.swt.widgets.Composite) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) DockerException(org.eclipse.linuxtools.docker.core.DockerException) SWT(org.eclipse.swt.SWT) GridData(org.eclipse.swt.layout.GridData) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Label(org.eclipse.swt.widgets.Label) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage)

Example 20 with IStructuredContentProvider

use of org.eclipse.jface.viewers.IStructuredContentProvider in project tmdm-studio-se by Talend.

the class AnnotationOrderedListsDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    // Should not really be here but well,....
    parent.getShell().setText(this.title);
    Composite composite = (Composite) super.createDialogArea(parent);
    GridLayout layout = (GridLayout) composite.getLayout();
    layout.numColumns = 3;
    layout.makeColumnsEqualWidth = false;
    if (actionType == AnnotationWrite_ActionType || actionType == AnnotationHidden_ActionType) {
        textControl = new CCombo(composite, SWT.BORDER | SWT.READ_ONLY);
        // roles=Util.getCachedXObjectsNameSet(this.xObject, TreeObject.ROLE);
        roles = getAllRolesStr();
        ((CCombo) textControl).setItems(roles.toArray(new String[roles.size()]));
    } else if (actionType == AnnotationLookupField_ActionType || actionType == AnnotationPrimaKeyInfo_ActionType) {
        textControl = new CCombo(composite, SWT.BORDER | SWT.READ_ONLY);
        // roles=Util.getCachedXObjectsNameSet(this.xObject, TreeObject.ROLE);
        roles = getConceptElements();
        ((CCombo) textControl).setItems(roles.toArray(new String[roles.size()]));
    } else {
        if (actionType == AnnotationOrderedListsDialog.AnnotationSchematron_ActionType) {
            textControl = new Text(composite, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
        } else {
            textControl = new Text(composite, SWT.BORDER | SWT.SINGLE);
        }
    }
    if (actionType == AnnotationOrderedListsDialog.AnnotationForeignKeyInfo_ActionType) {
        textControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    } else {
        if (actionType == AnnotationOrderedListsDialog.AnnotationSchematron_ActionType) {
            textControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 7));
        } else {
            textControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
        }
    }
    ((GridData) textControl.getLayoutData()).minimumWidth = 400;
    textControl.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
        }

        public void keyReleased(KeyEvent e) {
            if ((e.stateMask == 0) && (e.character == SWT.CR)) {
                xPaths.add(AnnotationOrderedListsDialog.getControlText(textControl));
                viewer.refresh();
                fireXPathsChanges();
            }
        }
    });
    if (actionType == AnnotationOrderedListsDialog.AnnotationForeignKeyInfo_ActionType) {
        Button xpathButton = new Button(composite, SWT.PUSH | SWT.CENTER);
        xpathButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
        // $NON-NLS-1$
        xpathButton.setText("...");
        xpathButton.setToolTipText(Messages.AnnotationOrderedListsDialog_SelectXpath);
        xpathButton.addSelectionListener(new SelectionListener() {

            public void widgetDefaultSelected(SelectionEvent e) {
            }

            public void widgetSelected(SelectionEvent e) {
                XpathSelectDialog dlg = getNewXpathSelectDialog(parentPage, dataModelName);
                dlg.setLock(lock);
                dlg.setBlockOnOpen(true);
                dlg.open();
                if (dlg.getReturnCode() == Window.OK) {
                    ((Text) textControl).setText(dlg.getXpath());
                    dlg.close();
                }
            }
        });
    }
    Button addLabelButton = new Button(composite, SWT.PUSH);
    addLabelButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
    // addLabelButton.setText("Set");
    addLabelButton.setImage(ImageCache.getCreatedImage(EImage.ADD_OBJ.getPath()));
    addLabelButton.setToolTipText(Messages.AnnotationOrderedListsDialog_Add);
    addLabelButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
        }

        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            boolean exist = false;
            for (String string : xPaths) {
                if (string.equals(getControlText(textControl))) {
                    exist = true;
                }
            }
            if (!exist && getControlText(textControl) != null && getControlText(textControl) != "") {
                xPaths.add(getControlText(textControl));
            }
            viewer.refresh();
            fireXPathsChanges();
        }
    });
    final String COLUMN = columnName;
    viewer = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    ((GridData) viewer.getControl().getLayoutData()).heightHint = 100;
    // Set up the underlying table
    Table table = viewer.getTable();
    // table.setLayoutData(new GridData(GridData.FILL_BOTH));
    new TableColumn(table, SWT.CENTER).setText(COLUMN);
    table.getColumn(0).setWidth(500);
    for (int i = 1, n = table.getColumnCount(); i < n; i++) {
        table.getColumn(i).pack();
    }
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    // Create the cell editors --> We actually discard those later: not natural for an user
    CellEditor[] editors = new CellEditor[1];
    if (actionType == AnnotationOrderedListsDialog.AnnotationWrite_ActionType || actionType == AnnotationOrderedListsDialog.AnnotationHidden_ActionType || actionType == AnnotationLookupField_ActionType || actionType == AnnotationPrimaKeyInfo_ActionType) {
        editors[0] = new ComboBoxCellEditor(table, roles.toArray(new String[] {}), SWT.READ_ONLY);
    } else {
        editors[0] = new TextCellEditor(table);
    }
    viewer.setCellEditors(editors);
    // set the content provider
    viewer.setContentProvider(new IStructuredContentProvider() {

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        public Object[] getElements(Object inputElement) {
            @SuppressWarnings("unchecked") ArrayList<String> xPaths = (ArrayList<String>) inputElement;
            ArrayList<DescriptionLine> lines = new ArrayList<DescriptionLine>();
            for (String xPath : xPaths) {
                DescriptionLine line = new DescriptionLine(xPath);
                lines.add(line);
            }
            // we return an instance line made of a Sring and a boolean
            return lines.toArray(new DescriptionLine[lines.size()]);
        }
    });
    // set the label provider
    viewer.setLabelProvider(new ITableLabelProvider() {

        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        public void dispose() {
        }

        public void addListener(ILabelProviderListener listener) {
        }

        public void removeListener(ILabelProviderListener listener) {
        }

        public String getColumnText(Object element, int columnIndex) {
            // System.out.println("getColumnText() "+columnIndex);
            DescriptionLine line = (DescriptionLine) element;
            switch(columnIndex) {
                case 0:
                    return line.getLabel();
            }
            // $NON-NLS-1$
            return "";
        }

        public Image getColumnImage(Object element, int columnIndex) {
            return null;
        }
    });
    // Set the column properties
    viewer.setColumnProperties(new String[] { COLUMN });
    // set the Cell Modifier
    viewer.setCellModifier(new ICellModifier() {

        public boolean canModify(Object element, String property) {
            // if (INSTANCE_ACCESS.equals(property)) return true; Deactivated
            return true;
        // return false;
        }

        public void modify(Object element, String property, Object value) {
            TableItem item = (TableItem) element;
            DescriptionLine line = (DescriptionLine) item.getData();
            String orgValue = line.getLabel();
            if (actionType != AnnotationWrite_ActionType && actionType != AnnotationHidden_ActionType && actionType != AnnotationLookupField_ActionType && actionType != AnnotationPrimaKeyInfo_ActionType) {
                int targetPos = xPaths.indexOf(value.toString());
                if (targetPos < 0) {
                    line.setLabel(value.toString());
                    int index = xPaths.indexOf(orgValue);
                    xPaths.remove(index);
                    xPaths.add(index, value.toString());
                    viewer.update(line, null);
                } else if (targetPos >= 0 && !value.toString().equals(orgValue)) {
                    MessageDialog.openInformation(null, Messages.Warning, Messages.AnnotationOrderedListsDialog_ValueAlreadyExists);
                }
            } else {
                String[] attrs = roles.toArray(new String[] {});
                int index = Integer.parseInt(value.toString());
                if (index == -1) {
                    return;
                }
                value = attrs[index];
                int pos = xPaths.indexOf(value.toString());
                if (pos >= 0 && !(orgValue.equals(value))) {
                    MessageDialog.openInformation(null, Messages.Warning, Messages.AnnotationOrderedListsDialog_);
                    return;
                } else if (pos < 0) {
                    line.setLabel(value.toString());
                    xPaths.set(index, value.toString());
                    viewer.update(line, null);
                }
            }
            fireXPathsChanges();
        }

        public Object getValue(Object element, String property) {
            DescriptionLine line = (DescriptionLine) element;
            String value = line.getLabel();
            if (actionType == AnnotationWrite_ActionType || actionType == AnnotationHidden_ActionType || actionType == AnnotationLookupField_ActionType || actionType == AnnotationPrimaKeyInfo_ActionType) {
                String[] attrs = roles.toArray(new String[] {});
                return Arrays.asList(attrs).indexOf(value);
            } else {
                return value;
            }
        }
    });
    // Listen for changes in the selection of the viewer to display additional parameters
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            DescriptionLine line = (DescriptionLine) ((IStructuredSelection) viewer.getSelection()).getFirstElement();
            if (line != null) {
                if (textControl instanceof CCombo) {
                    ((CCombo) textControl).setText(line.getLabel());
                }
                if (textControl instanceof Text) {
                    ((Text) textControl).setText(line.getLabel());
                }
            }
        }
    });
    // display for Delete Key events to delete an instance
    viewer.getTable().addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
        }

        public void keyReleased(KeyEvent e) {
            // System.out.println("Table keyReleased() ");
            if ((e.stateMask == 0) && (e.character == SWT.DEL) && (viewer.getSelection() != null)) {
                DescriptionLine line = (DescriptionLine) ((IStructuredSelection) viewer.getSelection()).getFirstElement();
                @SuppressWarnings("unchecked") ArrayList<String> xPaths = (ArrayList<String>) viewer.getInput();
                xPaths.remove(line.getLabel());
                viewer.refresh();
            }
        }
    });
    viewer.setInput(xPaths);
    viewer.refresh();
    Composite rightButtonsComposite = new Composite(composite, SWT.NULL);
    rightButtonsComposite.setLayout(new GridLayout(1, true));
    rightButtonsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
    Button upButton = new Button(rightButtonsComposite, SWT.PUSH | SWT.CENTER);
    upButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
    upButton.setImage(ImageCache.getCreatedImage(EImage.PREV_NAV.getPath()));
    upButton.setToolTipText(Messages.AnnotationOrderedListsDialog_MoveUpTheItem);
    upButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
        }

        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            DescriptionLine line = (DescriptionLine) ((IStructuredSelection) viewer.getSelection()).getFirstElement();
            if (line == null) {
                return;
            }
            int i = 0;
            for (String xPath : xPaths) {
                if (xPath.equals(line.getLabel())) {
                    if (i > 0) {
                        xPaths.remove(i);
                        xPaths.add(i - 1, xPath);
                        viewer.refresh();
                        viewer.getTable().setSelection(i - 1);
                        viewer.getTable().showSelection();
                        fireXPathsChanges();
                    }
                    return;
                }
                i++;
            }
        }
    });
    Button downButton = new Button(rightButtonsComposite, SWT.PUSH | SWT.CENTER);
    downButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
    downButton.setImage(ImageCache.getCreatedImage(EImage.NEXT_NAV.getPath()));
    downButton.setToolTipText(Messages.AnnotationOrderedListsDialog_MoveDownTheItem);
    downButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
        }

        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            DescriptionLine line = (DescriptionLine) ((IStructuredSelection) viewer.getSelection()).getFirstElement();
            if (line == null) {
                return;
            }
            int i = 0;
            for (String xPath : xPaths) {
                if (xPath.equals(line.getLabel())) {
                    if (i < xPaths.size() - 1) {
                        xPaths.remove(i);
                        xPaths.add(i + 1, xPath);
                        viewer.refresh();
                        viewer.getTable().setSelection(i + 1);
                        viewer.getTable().showSelection();
                        fireXPathsChanges();
                    }
                    return;
                }
                i++;
            }
        }
    });
    Button delButton = new Button(rightButtonsComposite, SWT.PUSH | SWT.CENTER);
    delButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
    delButton.setImage(ImageCache.getCreatedImage(EImage.DELETE_OBJ.getPath()));
    delButton.setToolTipText(Messages.AnnotationOrderedListsDialog_DelTheItem);
    delButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
        }

        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            DescriptionLine line = (DescriptionLine) ((IStructuredSelection) viewer.getSelection()).getFirstElement();
            if (line != null) {
                @SuppressWarnings("unchecked") ArrayList<String> xPaths = (ArrayList<String>) viewer.getInput();
                xPaths.remove(line.getLabel());
                viewer.refresh();
                fireXPathsChanges();
            }
        }
    });
    textControl.setFocus();
    if (actionType != AnnotationOrderedListsDialog.AnnotationForeignKeyInfo_ActionType && actionType != AnnotationOrderedListsDialog.AnnotationTargetSystems_ActionType && actionType != AnnotationOrderedListsDialog.AnnotationSchematron_ActionType && actionType != AnnotationOrderedListsDialog.AnnotationLookupField_ActionType && actionType != AnnotationOrderedListsDialog.AnnotationPrimaKeyInfo_ActionType) {
        checkBox = new Button(composite, SWT.CHECK);
        checkBox.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true, 2, 1));
        checkBox.addSelectionListener(new SelectionListener() {

            public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
            }

            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                recursive = checkBox.getSelection();
            }
        });
        checkBox.setSelection(recursive);
        checkBox.setText(Messages.AnnotationOrderedListsDialog_SetRoleRecursively);
    // Label label = new Label(composite, SWT.LEFT);
    // label.setText("set role recursively");
    // label.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true,
    // 1, 1));
    }
    if (actionType == AnnotationForeignKeyInfo_ActionType) {
        createFKInfoFormatComp(composite);
        addDoubleClickListener();
    }
    return composite;
}
Also used : CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) TableViewer(org.eclipse.jface.viewers.TableViewer) ElementFKInfoFormatViewer(com.amalto.workbench.widgets.composites.ElementFKInfoFormatViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EImage(com.amalto.workbench.image.EImage) Image(org.eclipse.swt.graphics.Image) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ICellModifier(org.eclipse.jface.viewers.ICellModifier) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) Text(org.eclipse.swt.widgets.Text) TableColumn(org.eclipse.swt.widgets.TableColumn) CCombo(org.eclipse.swt.custom.CCombo) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) KeyListener(org.eclipse.swt.events.KeyListener) TreeObject(com.amalto.workbench.models.TreeObject) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)89 Viewer (org.eclipse.jface.viewers.Viewer)69 Composite (org.eclipse.swt.widgets.Composite)52 GridData (org.eclipse.swt.layout.GridData)49 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)40 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)39 TableViewer (org.eclipse.jface.viewers.TableViewer)37 GridLayout (org.eclipse.swt.layout.GridLayout)37 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)36 Label (org.eclipse.swt.widgets.Label)29 LabelProvider (org.eclipse.jface.viewers.LabelProvider)26 Button (org.eclipse.swt.widgets.Button)26 SelectionEvent (org.eclipse.swt.events.SelectionEvent)25 Image (org.eclipse.swt.graphics.Image)25 ArrayList (java.util.ArrayList)23 Table (org.eclipse.swt.widgets.Table)23 ComboViewer (org.eclipse.jface.viewers.ComboViewer)19 ILabelProviderListener (org.eclipse.jface.viewers.ILabelProviderListener)18 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)17 Text (org.eclipse.swt.widgets.Text)17