Example usage for org.eclipse.jface.viewers TableViewer TableViewer

List of usage examples for org.eclipse.jface.viewers TableViewer TableViewer

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers TableViewer TableViewer.

Prototype

public TableViewer(Composite parent, int style) 

Source Link

Document

Creates a table viewer on a newly-created table control under the given parent.

Usage

From source file:com.alibaba.antx.config.gui.dialog.SettingsDialog.java

License:Open Source License

private void createFilesGroup(Composite composite) {
    composite.setLayout(new FormLayout());

    // /*w  w  w.ja v  a  2s .c o  m*/
    filesViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION);

    filesViewer.setLabelProvider(new ITableLabelProvider() {
        public Image getColumnImage(Object element, int columnIndex) {
            if (((File) element).isDirectory()) {
                return Resources.getImageDescriptor("icon.folder").createImage();
            } else {
                return Resources.getImageDescriptor("icon.jar").createImage();
            }
        }

        public String getColumnText(Object element, int columnIndex) {
            return ((File) element).getAbsolutePath();
        }

        public void addListener(ILabelProviderListener listener) {
        }

        public void dispose() {
        }

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

        public void removeListener(ILabelProviderListener listener) {
        }
    });

    filesViewer.setContentProvider(new IStructuredContentProvider() {
        public Object[] getElements(Object inputElement) {
            return ((Collection) inputElement).toArray();
        }

        public void dispose() {
        }

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

    filesViewer.setComparator(new ViewerComparator());
    filesViewer.setInput(files);

    // ?
    Button addFolder = new Button(composite, SWT.NULL);
    Button addFile = new Button(composite, SWT.NULL);
    Button remove = new Button(composite, SWT.NULL);

    addFolder.setText(Resources.getText("dialog.settings.addFolder"));
    addFolder.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            addFolder();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });

    addFile.setText(Resources.getText("dialog.settings.addFile"));
    addFile.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            addFile();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });

    remove.setText(Resources.getText("dialog.settings.remove"));
    remove.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            remove();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });

    // layout
    FormData data;

    data = new FormData(400, 300);
    data.top = new FormAttachment(0, 20);
    data.left = new FormAttachment(0, 20);
    data.right = new FormAttachment(80, 0);
    data.bottom = new FormAttachment(100, -20);
    filesViewer.getControl().setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(0, 20);
    data.left = new FormAttachment(filesViewer.getControl(), 20);
    data.right = new FormAttachment(100, -20);
    addFolder.setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(addFolder, 5);
    data.left = new FormAttachment(filesViewer.getControl(), 20);
    data.right = new FormAttachment(100, -20);
    addFile.setLayoutData(data);

    data = new FormData();
    data.top = new FormAttachment(addFile, 20);
    data.left = new FormAttachment(filesViewer.getControl(), 20);
    data.right = new FormAttachment(100, -20);
    remove.setLayoutData(data);
}

From source file:com.amalto.workbench.dialogs.AnnotationLanguageLabelsDialog.java

License:Open Source License

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;/*  w w w .  jav a  2  s.  c o m*/
    // layout.verticalSpacing = 10;

    languagesCombo = new Combo(composite, SWT.READ_ONLY | SWT.DROP_DOWN | SWT.SINGLE);
    languagesCombo.setLayoutData(new GridData(SWT.BEGINNING, SWT.NONE, false, false, 1, 1));
    Set<String> languages = Util.lang2iso.keySet();
    for (Iterator iter = languages.iterator(); iter.hasNext();) {
        String language = (String) iter.next();
        languagesCombo.add(language);
    }
    languagesCombo.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
        }
    });
    languagesCombo.select(0);

    labelText = new Text(composite, SWT.BORDER | SWT.SINGLE);
    labelText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    ((GridData) labelText.getLayoutData()).minimumWidth = 150;
    labelText.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
        }

        public void keyReleased(KeyEvent e) {
            if ((e.stateMask == 0) && (e.character == SWT.CR)) {
                String isoCode = Util.lang2iso.get(languagesCombo.getText());
                descriptionsMap.put(isoCode, labelText.getText());
                descriptionsViewer.refresh();
            }
        }
    });

    Button addLabelButton = new Button(composite, SWT.PUSH);
    addLabelButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
    addLabelButton.setImage(ImageCache.getCreatedImage(EImage.ADD_OBJ.getPath()));
    addLabelButton.setToolTipText(Messages.AnnotationLanguageLabelsDialog_Add);
    addLabelButton.addSelectionListener(new SelectionListener() {

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

        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            String code = Util.lang2iso.get(languagesCombo.getText());
            descriptionsMap.put(code, labelText.getText());
            descriptionsViewer.refresh();
        };
    });

    final String LANGUAGE = Messages.AnnotationLanguageLabelsDialog_Language;
    final String LABEL = Messages.AnnotationLanguageLabelsDialog_Label;

    descriptionsViewer = new TableViewer(composite,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    descriptionsViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    ((GridData) descriptionsViewer.getControl().getLayoutData()).heightHint = 100;
    // Set up the underlying table
    Table table = descriptionsViewer.getTable();
    // table.setLayoutData(new GridData(GridData.FILL_BOTH));

    new TableColumn(table, SWT.LEFT).setText(LANGUAGE);
    new TableColumn(table, SWT.CENTER).setText(LABEL);
    table.getColumn(0).setWidth(150);
    table.getColumn(1).setWidth(150);
    for (int i = 2, n = table.getColumnCount(); i < n; i++) {
        table.getColumn(i).pack();
    }

    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    Button delLabelButton = new Button(composite, SWT.PUSH);
    delLabelButton.setLayoutData(new GridData(SWT.NONE, SWT.NONE, false, false, 1, 1));
    delLabelButton.setImage(ImageCache.getCreatedImage(EImage.DELETE_OBJ.getPath()));
    delLabelButton.setToolTipText(Messages.AnnotationLanguageLabelsDialog_Del);
    delLabelButton.addSelectionListener(new SelectionListener() {

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

        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            deleteItem();
        };
    });
    // Create the cell editors --> We actually discard those later: not natural for an user
    CellEditor[] editors = new CellEditor[2];
    editors[0] = new ComboBoxCellEditor(table, Util.lang2iso.keySet().toArray(new String[] {}), SWT.READ_ONLY);
    editors[1] = new TextCellEditor(table);
    descriptionsViewer.setCellEditors(editors);

    // set the content provider
    descriptionsViewer.setContentProvider(new IStructuredContentProvider() {

        public void dispose() {
        }

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

        public Object[] getElements(Object inputElement) {
            // System.out.println("getElements() ");
            LinkedHashMap<String, String> descs = (LinkedHashMap<String, String>) inputElement;
            Set<String> languages = descs.keySet();
            ArrayList<DescriptionLine> lines = new ArrayList<DescriptionLine>();
            for (Iterator iter = languages.iterator(); iter.hasNext();) {
                String language = ((String) iter.next());
                DescriptionLine line = new DescriptionLine(Util.iso2lang.get(language), descs.get(language));
                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
    descriptionsViewer.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.getLanguage();
            case 1:
                return line.getLabel();
            }
            return "";//$NON-NLS-1$
        }

        public Image getColumnImage(Object element, int columnIndex) {
            return null;
        }
    });

    // Set the column properties
    descriptionsViewer.setColumnProperties(new String[] { LANGUAGE, LABEL });

    // set the Cell Modifier
    descriptionsViewer.setCellModifier(new ICellModifier() {

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

        public void modify(Object element, String property, Object value) {
            TableItem item = (TableItem) element;
            int columnIndex = Arrays.asList(descriptionsViewer.getColumnProperties()).indexOf(property);
            DescriptionLine line = (DescriptionLine) item.getData();
            if (columnIndex == 0) {
                String[] attrs = Util.lang2iso.keySet().toArray(new String[] {});
                int orgIndx = Arrays.asList(attrs).indexOf(line.getLanguage());
                if (orgIndx != Integer.parseInt(value.toString())) {
                    String newLang = attrs[Integer.parseInt(value.toString())];
                    if (descriptionsMap.containsKey(Util.lang2iso.get(newLang))) {
                        MessageDialog.openInformation(null, Messages.Warnning,
                                Messages.AnnotationLanguageLabelsDialog_InforContent);
                        return;
                    }
                    descriptionsMap.remove(Util.lang2iso.get(line.getLanguage()));
                    line.setLanguage(newLang);
                    descriptionsMap.put(Util.lang2iso.get(newLang), line.getLabel());
                }
            } else // column label
            {
                line.setLabel(value.toString());
                descriptionsMap.put(Util.lang2iso.get(line.getLanguage()), line.getLabel());
            }

            descriptionsViewer.update(line, null);
        }

        public Object getValue(Object element, String property) {
            int columnIndex = Arrays.asList(descriptionsViewer.getColumnProperties()).indexOf(property);
            DescriptionLine line = (DescriptionLine) element;
            if (columnIndex == 0) {
                String[] attrs = Util.lang2iso.keySet().toArray(new String[] {});
                return Arrays.asList(attrs).indexOf(line.getLanguage());
            } else {
                if (LANGUAGE.equals(property)) {
                    return line.getLanguage();
                }
                if (LABEL.equals(property)) {
                    return line.getLabel();
                }
            }

            return null;
        }
    });

    // Listen for changes in the selection of the viewer to display additional parameters
    descriptionsViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
        }
    });

    // display for Delete Key events to delete an instance
    descriptionsViewer.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) && (descriptionsViewer.getSelection() != null)) {
                deleteItem();
            }
        }
    });

    descriptionsViewer.setInput(descriptionsMap);
    descriptionsViewer.refresh();

    labelText.setFocus();

    return composite;
}

From source file:com.amalto.workbench.dialogs.AnnotationOrderedListsDialog.java

License:Open Source License

@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;/* w  ww .j av a  2  s. c om*/
    layout.makeColumnsEqualWidth = false;
    // layout.verticalSpacing = 10;

    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));
        xpathButton.setText("...");//$NON-NLS-1$
        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();
            }
            return "";//$NON-NLS-1$
        }

        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;
}

From source file:com.amalto.workbench.dialogs.datacontainer.UpdateAutoIncrementDialog.java

License:Open Source License

private void createTable(Composite mainComp) {
    int style = SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.FULL_SELECTION;
    resultsViewer = new TableViewer(mainComp, style);
    resultsViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    resultsViewer.getTable().setHeaderVisible(true);
    resultsViewer.getTable().setLinesVisible(true);
    resultsViewer.setContentProvider(getContentProvider());

    TableViewerColumn column = new TableViewerColumn(resultsViewer, SWT.NONE);
    column.getColumn().setText(Messages.UpdateAutoIncrementDialog_entity);
    column.getColumn().setResizable(true);
    column.getColumn().setWidth(300);/*  w ww  .j  a v  a2 s  . c  o m*/
    column.setLabelProvider(new CustomedLabelProvider(0));
    column.setEditingSupport(null);

    column = new TableViewerColumn(resultsViewer, SWT.NONE);
    column.getColumn().setText(Messages.UpdateAutoIncrementDialog_value);
    column.getColumn().setResizable(true);
    column.getColumn().setWidth(100);
    column.setLabelProvider(new CustomedLabelProvider(1));
    column.setEditingSupport(new EditingSupport(resultsViewer) {

        @Override
        protected CellEditor getCellEditor(Object element) {
            return new VerificableTextCellEditor(resultsViewer.getTable());
        }

        @Override
        protected boolean canEdit(Object element) {
            return true;
        }

        @Override
        protected Object getValue(Object element) {
            Line line = (Line) element;
            return line.keyValues.get(1).value;
        }

        @Override
        protected void setValue(Object element, Object value) {
            Line line = (Line) element;
            line.keyValues.get(1).value = value.toString();
            resultsViewer.refresh();
        }

    });

    resultsViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) resultsViewer.getSelection();
            resetBtn.setEnabled(!selection.isEmpty());
        }
    });

    List<Line> lines = getInput();

    resultsViewer.setInput(lines);
}

From source file:com.amalto.workbench.dialogs.MenuEntryDialog.java

License:Open Source License

@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;//  ww  w  .j av a 2  s. c  o  m
    // layout.verticalSpacing = 10;

    Label idLabel = new Label(composite, SWT.NONE);
    idLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    idLabel.setText(Messages.MenuEntryDialog_Id);
    if (this.isChanged) {
        idText = new Text(composite, SWT.NONE);
    } else {
        idText = new Text(composite, SWT.NONE | SWT.READ_ONLY);
    }

    idText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    ((GridData) idText.getLayoutData()).widthHint = 300;
    idText.setDoubleClickEnabled(false);

    Label contextLabel = new Label(composite, SWT.NONE);
    contextLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    contextLabel.setText(Messages.MenuEntryDialog_Context);

    contextText = new Text(composite, SWT.NONE);
    contextText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    contextText.setDoubleClickEnabled(false);

    Label applicationNameLabel = new Label(composite, SWT.NONE);
    applicationNameLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    applicationNameLabel.setText(Messages.MenuEntryDialog_Application);

    applicationNameText = new Text(composite, SWT.NONE);
    applicationNameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    Label iconPathLabel = new Label(composite, SWT.NONE);
    iconPathLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    iconPathLabel.setText(Messages.MenuEntryDialog_IconPath);
    iconPathText = new FileSelectWidget(composite, "", new String[] { "*.png", "*.gif", "*.jpg" }, "", true);//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ //$NON-NLS-5$

    // Labels
    descriptionsComposite = new Composite(composite, SWT.BORDER);
    descriptionsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
    descriptionsComposite.setLayout(new GridLayout(3, false));

    Label descriptionsLabel = new Label(descriptionsComposite, SWT.NULL);
    descriptionsLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
    descriptionsLabel.setText(Messages.MenuEntryDialog_MenuEntryLabels);

    languagesCombo = new Combo(descriptionsComposite, SWT.READ_ONLY | SWT.DROP_DOWN | SWT.SINGLE);
    languagesCombo.setLayoutData(new GridData(SWT.BEGINNING, SWT.NONE, false, false, 1, 1));
    Set<String> languages = Util.lang2iso.keySet();
    for (Object element : languages) {
        String language = (String) element;
        languagesCombo.add(language);
    }
    languagesCombo.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
        }
    });
    languagesCombo.select(0);

    labelText = new Text(descriptionsComposite, SWT.BORDER | SWT.SINGLE);
    labelText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    labelText.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
        }

        public void keyReleased(KeyEvent e) {
            if ((e.stateMask == 0) && (e.character == SWT.CR)) {
                String isoCode = Util.lang2iso.get(languagesCombo.getText());
                descriptionsMap.put(isoCode, labelText.getText());
                descriptionsViewer.refresh();
            }
        }
    });

    Button addLabelButton = new Button(descriptionsComposite, SWT.PUSH);
    addLabelButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
    addLabelButton.setImage(ImageCache.getCreatedImage(EImage.ADD_OBJ.getPath()));
    addLabelButton.setToolTipText(Messages.MenuEntryDialog_Add);
    addLabelButton.addSelectionListener(new SelectionListener() {

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

        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            String isoCode = Util.lang2iso.get(languagesCombo.getText());
            descriptionsMap.put(isoCode, labelText.getText());
            descriptionsViewer.refresh();
        };
    });

    final String LANGUAGE = Messages.MenuEntryDialog_Language;
    final String LABEL = Messages.MenuEntryDialog_Label;

    descriptionsViewer = new TableViewer(descriptionsComposite,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    descriptionsViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
    ((GridData) descriptionsViewer.getControl().getLayoutData()).heightHint = 100;
    // Set up the underlying table
    Table table = descriptionsViewer.getTable();
    // table.setLayoutData(new GridData(GridData.FILL_BOTH));

    new TableColumn(table, SWT.LEFT).setText(LANGUAGE);
    new TableColumn(table, SWT.CENTER).setText(LABEL);
    table.getColumn(0).setWidth(150);
    table.getColumn(1).setWidth(150);
    for (int i = 2, 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[2];
    editors[0] = new TextCellEditor(table);
    editors[1] = new TextCellEditor(table);
    descriptionsViewer.setCellEditors(editors);

    // set the content provider
    descriptionsViewer.setContentProvider(new IStructuredContentProvider() {

        public void dispose() {
        }

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

        public Object[] getElements(Object inputElement) {
            // System.out.println("getElements() ");
            LinkedHashMap<String, String> descs = (LinkedHashMap<String, String>) inputElement;
            Set<String> languages = descs.keySet();
            ArrayList<DescriptionLine> lines = new ArrayList<DescriptionLine>();
            for (Object element : languages) {
                String language = (String) element;
                DescriptionLine line = new DescriptionLine(Util.iso2lang.get(language), descs.get(language));
                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
    descriptionsViewer.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.getLanguage();
            case 1:
                return line.getLabel();
            }
            return "";//$NON-NLS-1$
        }

        public Image getColumnImage(Object element, int columnIndex) {
            return null;
        }
    });

    // Set the column properties
    descriptionsViewer.setColumnProperties(new String[] { LANGUAGE, LABEL });

    // set the Cell Modifier
    descriptionsViewer.setCellModifier(new ICellModifier() {

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

        public void modify(Object element, String property, Object value) {
            // System.out.println("modify() "+element.getClass().getName()+": "+property+": "+value);
            // DescriptionLine line =
            // (DescriptionLine)((IStructuredSelection)instancesViewer.getSelection()).getFirstElement();
            // deactivated: editing in places is not natural for users
        }

        public Object getValue(Object element, String property) {
            // System.out.println("getValue() "+property);
            DescriptionLine line = (DescriptionLine) element;
            if (LANGUAGE.equals(property)) {
                return line.getLanguage();
            }
            if (LABEL.equals(property)) {
                return line.getLabel();
            }
            return null;
        }
    });

    // Listen for changes in the selection of the viewer to display additional parameters
    descriptionsViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
        }
    });

    // display for Delete Key events to delete an instance
    descriptionsViewer.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) && (descriptionsViewer.getSelection() != null)) {
                DescriptionLine line = (DescriptionLine) ((IStructuredSelection) descriptionsViewer
                        .getSelection()).getFirstElement();
                String isoCode = Util.lang2iso.get(line.getLanguage());
                LinkedHashMap<String, String> descs = (LinkedHashMap<String, String>) descriptionsViewer
                        .getInput();
                descs.remove(isoCode);
                descriptionsViewer.refresh();
            }
        }
    });

    descriptionsViewer.refresh();

    if (wsMenuEntry != null) {
        idText.setText(wsMenuEntry.getId() == null ? "" : wsMenuEntry.getId());//$NON-NLS-1$
        contextText.setText(wsMenuEntry.getContext() == null ? "" : wsMenuEntry.getContext());//$NON-NLS-1$
        applicationNameText.setText(wsMenuEntry.getApplication() == null ? "" : wsMenuEntry.getApplication());//$NON-NLS-1$
        iconPathText.setFilename(wsMenuEntry.getIcon() == null ? "" : wsMenuEntry.getIcon());//$NON-NLS-1$
        descriptionsViewer.setInput(descriptionsMap);
    }

    idText.setFocus();

    return composite;
}

From source file:com.amalto.workbench.dialogs.VariableDefinitionDialog.java

License:Open Source License

protected Control createDialogArea(Composite parent) {

    parent.getShell().setText(title);// w  w  w .ja  v a2s  .  c o  m

    Composite composite = (Composite) super.createDialogArea(parent);

    GridLayout layout = (GridLayout) composite.getLayout();
    layout.numColumns = 2;

    descriptionsViewer = new TableViewer(composite,
            SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    descriptionsViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    ((GridData) descriptionsViewer.getControl().getLayoutData()).heightHint = 100;
    // Set up the underlying table
    Table table = descriptionsViewer.getTable();
    final String columnTitle = Messages.VariableDefinitionDialog_AvailableVariables;
    new TableColumn(table, SWT.CENTER).setText(columnTitle);
    table.getColumn(0).setWidth(350);

    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    CellEditor[] editors = new CellEditor[1];
    editors[0] = new TextCellEditor(table);
    descriptionsViewer.setCellEditors(editors);

    descriptionsViewer.setContentProvider(new IStructuredContentProvider() {

        public void dispose() {
        }

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

        public Object[] getElements(Object inputElement) {
            ArrayList<String> descs = (ArrayList<String>) inputElement;
            return descs.toArray();
        }
    });

    // set the label provider
    descriptionsViewer.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) {
            // return element.toString().toLowerCase();
            return element.toString();
        }

        public Image getColumnImage(Object element, int columnIndex) {
            return null;
        }
    });

    descriptionsViewer.setColumnProperties(new String[] { columnTitle });

    descriptionsViewer.setCellModifier(new ICellModifier() {

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

        public void modify(Object element, String property, Object value) {
        }

        public Object getValue(Object element, String property) {
            return element.toString();
        }
    });

    descriptionsViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            outPut = (String) selection.getFirstElement();
            getButton(IDialogConstants.OK_ID).setEnabled(true);
        }
    });

    descriptionsViewer.setInput(inputList);
    descriptionsViewer.refresh();

    return composite;
}

From source file:com.amalto.workbench.editors.DataClusterComposite.java

License:Open Source License

protected void createSearchResultPart(Composite composite) {
    int style = SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION;
    resultsViewer = new TableViewer(composite, style);
    initTable(resultsViewer.getTable());

    resultsViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    // ((GridData) resultsViewer.getControl().getLayoutData()).heightHint = DEFAULT_VIEWER_HEIGHT;
    resultsViewer.setContentProvider(new ArrayContentProvider());
    resultsViewer.setLabelProvider(new ClusterTableLabelProvider());
}

From source file:com.amazonaws.eclipse.explorer.identitymanagement.AbstractGroupTable.java

License:Apache License

public AbstractGroupTable(AmazonIdentityManagement iam, Composite parent, FormToolkit toolkit) {
    super(parent, SWT.NONE);

    this.setLayoutData(new GridData(GridData.FILL_BOTH));
    TableColumnLayout tableColumnLayout = new TableColumnLayout();
    this.setLayout(tableColumnLayout);

    contentProvider = new GroupTableContentProvider();
    GroupTableLabelProvider labelProvider = new GroupTableLabelProvider();

    viewer = new TableViewer(this, SWT.BORDER | SWT.MULTI);
    viewer.getTable().setLinesVisible(true);
    viewer.getTable().setHeaderVisible(true);
    viewer.setLabelProvider(labelProvider);
    viewer.setContentProvider(contentProvider);
    createColumns(tableColumnLayout, viewer.getTable());
    this.iam = iam;
    refresh();/* w  ww.ja v a2 s.c om*/
}

From source file:com.amazonaws.eclipse.explorer.identitymanagement.AbstractPolicyTable.java

License:Apache License

protected AbstractPolicyTable(AmazonIdentityManagement iam, Composite parent, FormToolkit toolkit) {
    super(parent, SWT.NONE);

    this.iam = iam;

    TableColumnLayout tableColumnLayout = new TableColumnLayout();
    this.setLayout(tableColumnLayout);
    this.setLayoutData(new GridData(GridData.FILL_BOTH));

    contentProvider = new TableContentProvider();
    TableLabelProvider labelProvider = new TableLabelProvider();

    viewer = new TableViewer(this, SWT.SINGLE | SWT.BORDER);
    viewer.getTable().setLinesVisible(true);
    viewer.getTable().setHeaderVisible(true);
    viewer.setLabelProvider(labelProvider);
    viewer.setContentProvider(contentProvider);
    createColumns(tableColumnLayout, viewer.getTable());

}

From source file:com.amazonaws.eclipse.explorer.identitymanagement.AbstractUserTable.java

License:Apache License

public AbstractUserTable(AmazonIdentityManagement iam, Composite parent, FormToolkit toolkit,
        EditorInput userEditorInput) {//from   w w  w . j a  v  a2 s .  co  m
    super(parent, SWT.NONE);
    this.userEditorInput = userEditorInput;
    this.iam = iam;

    this.setLayoutData(new GridData(GridData.FILL_BOTH));
    TableColumnLayout tableColumnLayout = new TableColumnLayout();
    this.setLayout(tableColumnLayout);

    contentProvider = new UserTableContentProvider();
    userTableLabelProvider labelProvider = new userTableLabelProvider();

    viewer = new TableViewer(this, SWT.BORDER | SWT.MULTI);
    viewer.getTable().setLinesVisible(true);
    viewer.getTable().setHeaderVisible(true);
    viewer.setLabelProvider(labelProvider);
    viewer.setContentProvider(contentProvider);

    createColumns(tableColumnLayout, viewer.getTable());
    refresh();
}