Search in sources :

Example 51 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project erlide_eclipse by erlang.

the class ColoringPreferencePage method createSyntaxPage.

private Control createSyntaxPage(final Composite parent) {
    final Composite colorComposite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    colorComposite.setLayout(layout);
    final Link link = new Link(colorComposite, SWT.NONE);
    link.setText(PreferencesMessages.ErlEditorColoringConfigurationBlock_link);
    link.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            PreferencesUtil.createPreferenceDialogOn(parent.getShell(), e.text, null, null);
        }
    });
    final GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
    gridData.widthHint = 150;
    gridData.horizontalSpan = 2;
    link.setLayoutData(gridData);
    addFiller(colorComposite, 1);
    Label label;
    label = new Label(colorComposite, SWT.LEFT);
    label.setText(PreferencesMessages.ErlEditorPreferencePage_coloring_element);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    final Composite editorComposite = new Composite(colorComposite, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    editorComposite.setLayout(layout);
    GridData gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
    editorComposite.setLayoutData(gd);
    fListViewer = new TreeViewer(editorComposite, SWT.SINGLE | SWT.BORDER);
    final Tree tree = fListViewer.getTree();
    final GridData gdTree = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
    gdTree.widthHint = 100;
    tree.setLayoutData(gdTree);
    fListViewer.setLabelProvider(new ColorListLabelProvider());
    fListViewer.setContentProvider(new ColorListContentProvider());
    fListViewer.setInput(fColors);
    fListViewer.setSelection(new StructuredSelection(fErlangCategory));
    fListViewer.setComparator(new ViewerComparator() {

        @Override
        public int category(final Object element) {
            // don't sort the top level categories
            if (fErlangCategory.equals(element)) {
            }
            // return 1;
            return 0;
        }
    });
    gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, true);
    gd.heightHint = convertHeightInCharsToPixels(9);
    int maxWidth = 0;
    for (final TokenHighlight item : fColors.keySet()) {
        maxWidth = Math.max(maxWidth, convertWidthInCharsToPixels(item.getName().length()));
    }
    final ScrollBar vBar = ((Scrollable) fListViewer.getControl()).getVerticalBar();
    if (vBar != null) {
        // scrollbars and tree
        maxWidth += vBar.getSize().x * 3;
    }
    // indentation guess
    gd.widthHint = maxWidth;
    fListViewer.getControl().setLayoutData(gd);
    fListViewer.expandAll();
    final Composite stylesComposite = new Composite(editorComposite, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 2;
    stylesComposite.setLayout(layout);
    stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    fEnableCheckbox = new Button(stylesComposite, SWT.CHECK);
    fEnableCheckbox.setText(PreferencesMessages.ErlEditorPreferencePage_enable);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalSpan = 2;
    fEnableCheckbox.setLayoutData(gd);
    // TODO hide this until reworking the dialog
    fEnableCheckbox.setVisible(false);
    fColorEditorLabel = new Label(stylesComposite, SWT.LEFT);
    fColorEditorLabel.setText(PreferencesMessages.ErlEditorPreferencePage_color);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalIndent = 20;
    fColorEditorLabel.setLayoutData(gd);
    fSyntaxForegroundColorEditor = new ColorSelector(stylesComposite);
    final Button foregroundColorButton = fSyntaxForegroundColorEditor.getButton();
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    foregroundColorButton.setLayoutData(gd);
    new Label(stylesComposite, SWT.NONE);
    fBoldCheckBox = new Button(stylesComposite, SWT.CHECK);
    fBoldCheckBox.setText(PreferencesMessages.ErlEditorPreferencePage_bold);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalIndent = 20;
    gd.horizontalSpan = 2;
    fBoldCheckBox.setLayoutData(gd);
    fItalicCheckBox = new Button(stylesComposite, SWT.CHECK);
    fItalicCheckBox.setText(PreferencesMessages.ErlEditorPreferencePage_italic);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalIndent = 20;
    gd.horizontalSpan = 2;
    fItalicCheckBox.setLayoutData(gd);
    fStrikethroughCheckBox = new Button(stylesComposite, SWT.CHECK);
    fStrikethroughCheckBox.setText(PreferencesMessages.ErlEditorPreferencePage_strikeout);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalIndent = 20;
    gd.horizontalSpan = 2;
    fStrikethroughCheckBox.setLayoutData(gd);
    fUnderlineCheckBox = new Button(stylesComposite, SWT.CHECK);
    fUnderlineCheckBox.setText(PreferencesMessages.ErlEditorPreferencePage_underline);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.horizontalIndent = 20;
    gd.horizontalSpan = 2;
    fUnderlineCheckBox.setLayoutData(gd);
    final String content = ColoringPreferencePage.loadPreviewContentFromFile(getClass(), // $NON-NLS-1$
    "ColorSettingPreviewCode.txt");
    fPreviewViewer = ErlangSourceViewer.createErlangPreviewer(colorComposite, fColorManager, fOverlayStore, fColors, content);
    final Control previewer = fPreviewViewer.getControl();
    gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = convertWidthInCharsToPixels(20);
    gd.heightHint = convertHeightInCharsToPixels(5);
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    previewer.setLayoutData(gd);
    fListViewer.addSelectionChangedListener(event -> handleSyntaxColorListSelection());
    foregroundColorButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
        // do nothing
        }

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final TokenHighlight item = getHighlight();
            final HighlightStyle data = item.getStyle(fOverlayStore);
            if (data == null) {
                return;
            }
            data.setColor(fSyntaxForegroundColorEditor.getColorValue());
            storeHighlight(fOverlayStore, item, data);
            fPreviewViewer.invalidateTextPresentation();
        }
    });
    fBoldCheckBox.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
        // do nothing
        }

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final TokenHighlight item = getHighlight();
            final HighlightStyle data = item.getStyle(fOverlayStore);
            if (data == null) {
                return;
            }
            data.setStyle(SWT.BOLD, fBoldCheckBox.getSelection());
            storeHighlight(fOverlayStore, item, data);
            fPreviewViewer.invalidateTextPresentation();
        }
    });
    fItalicCheckBox.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
        // do nothing
        }

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final TokenHighlight item = getHighlight();
            final HighlightStyle data = item.getStyle(fOverlayStore);
            if (data == null) {
                return;
            }
            data.setStyle(SWT.ITALIC, fItalicCheckBox.getSelection());
            storeHighlight(fOverlayStore, item, data);
            fPreviewViewer.invalidateTextPresentation();
        }
    });
    fStrikethroughCheckBox.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
        // do nothing
        }

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final TokenHighlight item = getHighlight();
            final HighlightStyle data = item.getStyle(fOverlayStore);
            if (data == null) {
                return;
            }
            data.setStyle(TextAttribute.STRIKETHROUGH, fStrikethroughCheckBox.getSelection());
            storeHighlight(fOverlayStore, item, data);
            fPreviewViewer.invalidateTextPresentation();
        }
    });
    fUnderlineCheckBox.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
        // do nothing
        }

        @Override
        public void widgetSelected(final SelectionEvent e) {
            final TokenHighlight item = getHighlight();
            final HighlightStyle data = item.getStyle(fOverlayStore);
            if (data == null) {
                return;
            }
            data.setStyle(TextAttribute.UNDERLINE, fUnderlineCheckBox.getSelection());
            storeHighlight(fOverlayStore, item, data);
            fPreviewViewer.invalidateTextPresentation();
        }
    });
    fEnableCheckbox.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
        // do nothing
        }

        @Override
        public void widgetSelected(final SelectionEvent e) {
            fEnableCheckbox.setSelection(true);
        // final TokenHighlight item = getHighlight();
        // if (item instanceof SemanticHighlightingColorListItem) {
        // final boolean enable = fEnableCheckbox.getSelection();
        // getPreferenceStore().setValue(
        // ((SemanticHighlightingColorListItem) item)
        // .getEnableKey(), enable);
        // fEnableCheckbox.setSelection(enable);
        // fSyntaxForegroundColorEditor.getButton().setEnabled(enable);
        // fColorEditorLabel.setEnabled(enable);
        // fBoldCheckBox.setEnabled(enable);
        // fItalicCheckBox.setEnabled(enable);
        // fStrikethroughCheckBox.setEnabled(enable);
        // fUnderlineCheckBox.setEnabled(enable);
        // }
        }
    });
    colorComposite.layout(false);
    handleSyntaxColorListSelection();
    fPreviewViewer.invalidateTextPresentation();
    return colorComposite;
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Scrollable(org.eclipse.swt.widgets.Scrollable) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) HighlightStyle(org.erlide.ui.prefs.HighlightStyle) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TokenHighlight(org.erlide.ui.prefs.TokenHighlight) GridData(org.eclipse.swt.layout.GridData) ColorSelector(org.eclipse.jface.preference.ColorSelector) Link(org.eclipse.swt.widgets.Link) ScrollBar(org.eclipse.swt.widgets.ScrollBar) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 52 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project archi by archimatetool.

the class P2PluginDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    // Help
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
    setTitle(Messages.P2PluginDialog_1);
    setMessage(Messages.P2PluginDialog_2);
    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    container.setLayoutData(new GridData(GridData.FILL_BOTH));
    container.setLayout(new GridLayout(1, false));
    Composite tableComp = new Composite(container, SWT.NONE);
    TableColumnLayout layout = new TableColumnLayout();
    tableComp.setLayout(layout);
    GridData gd = new GridData(GridData.FILL_BOTH);
    tableComp.setLayoutData(gd);
    viewer = new TableViewer(tableComp, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    viewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    // Mac Silicon Item height
    UIUtils.fixMacSiliconItemHeight(viewer.getTable());
    viewer.getTable().setHeaderVisible(true);
    TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
    layout.setColumnData(column.getColumn(), new ColumnWeightData(25, false));
    column.getColumn().setText(Messages.P2PluginDialog_3);
    column = new TableViewerColumn(viewer, SWT.NONE);
    layout.setColumnData(column.getColumn(), new ColumnWeightData(25, false));
    column.getColumn().setText(Messages.P2PluginDialog_4);
    column = new TableViewerColumn(viewer, SWT.NONE);
    layout.setColumnData(column.getColumn(), new ColumnWeightData(25, false));
    column.getColumn().setText(Messages.P2PluginDialog_5);
    column = new TableViewerColumn(viewer, SWT.NONE);
    layout.setColumnData(column.getColumn(), new ColumnWeightData(25, false));
    column.getColumn().setText(Messages.P2PluginDialog_6);
    viewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public Object[] getElements(Object inputElement) {
            try {
                return P2Handler.getInstance().getInstalledFeatures().toArray();
            } catch (ProvisionException ex) {
                ex.printStackTrace();
            }
            return new Object[0];
        }
    });
    class LabelCellProvider extends LabelProvider implements ITableLabelProvider {

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

        @Override
        public String getColumnText(Object element, int columnIndex) {
            if (element instanceof IInstallableUnit) {
                IInstallableUnit iu = (IInstallableUnit) element;
                switch(columnIndex) {
                    case 0:
                        return iu.getProperty(IInstallableUnit.PROP_NAME, null);
                    case 1:
                        return iu.getVersion().toString();
                    case 2:
                        return iu.getId();
                    case 3:
                        return iu.getProperty(IInstallableUnit.PROP_PROVIDER, null);
                    default:
                        break;
                }
            }
            return element.toString();
        }
    }
    viewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            IInstallableUnit u1 = (IInstallableUnit) e1;
            IInstallableUnit u2 = (IInstallableUnit) e2;
            return u1.getProperty(IInstallableUnit.PROP_NAME, null).compareToIgnoreCase(u2.getProperty(IInstallableUnit.PROP_NAME, null));
        }
    });
    viewer.setLabelProvider(new LabelCellProvider());
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            getButton(UNINSTALL).setEnabled(!event.getSelection().isEmpty());
        }
    });
    // anything will do //$NON-NLS-1$
    viewer.setInput("");
    return area;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) TableViewer(org.eclipse.jface.viewers.TableViewer) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 53 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project archi by archimatetool.

the class UserPropertiesManagerDialog method createTableControl.

private void createTableControl(Composite parent) {
    Composite tableComp = new Composite(parent, SWT.BORDER);
    TableColumnLayout tableLayout = new TableColumnLayout();
    tableComp.setLayout(tableLayout);
    tableComp.setLayoutData(new GridData(GridData.FILL_BOTH));
    fTableViewer = new TableViewer(tableComp, SWT.MULTI | SWT.FULL_SELECTION);
    fTableViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    // Mac Silicon Item height
    UIUtils.fixMacSiliconItemHeight(fTableViewer.getTable());
    // Edit cell on double-click and add Tab key traversal
    TableViewerEditor.create(fTableViewer, new ColumnViewerEditorActivationStrategy(fTableViewer) {

        @Override
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return super.isEditorActivationEvent(event) || (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION);
        }
    }, ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEEP_EDITOR_ON_DOUBLE_CLICK | ColumnViewerEditor.KEYBOARD_ACTIVATION);
    fTableViewer.getTable().setHeaderVisible(true);
    fTableViewer.getTable().setLinesVisible(true);
    fTableViewer.setComparator(new ViewerComparator());
    // Columns
    TableViewerColumn columnOldKey = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
    columnOldKey.getColumn().setText(Messages.UserPropertiesManagerDialog_6);
    tableLayout.setColumnData(columnOldKey.getColumn(), new ColumnWeightData(40, true));
    TableViewerColumn columnNewKey = new TableViewerColumn(fTableViewer, SWT.NONE, 1);
    columnNewKey.getColumn().setText(Messages.UserPropertiesManagerDialog_7);
    tableLayout.setColumnData(columnNewKey.getColumn(), new ColumnWeightData(40, true));
    columnNewKey.setEditingSupport(new KeyEditingSupport(fTableViewer));
    TableViewerColumn columnUsedNumber = new TableViewerColumn(fTableViewer, SWT.NONE, 2);
    // $NON-NLS-1$
    columnUsedNumber.getColumn().setText("# " + Messages.UserPropertiesManagerDialog_8);
    tableLayout.setColumnData(columnUsedNumber.getColumn(), new ColumnWeightData(20, true));
    // Content Provider
    fTableViewer.setContentProvider(new IStructuredContentProvider() {

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

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return fKeysTable.entrySet().toArray();
        }
    });
    // Label Provider
    fTableViewer.setLabelProvider(new LabelCellProvider());
    fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            fActionDelete.setEnabled(!event.getSelection().isEmpty());
            fButtonDelete.setEnabled(!event.getSelection().isEmpty());
            fActionRename.setEnabled(!event.getSelection().isEmpty());
            fButtonRename.setEnabled(!event.getSelection().isEmpty());
        }
    });
    // anything will do //$NON-NLS-1$
    fTableViewer.setInput("");
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TableViewer(org.eclipse.jface.viewers.TableViewer) ColumnViewer(org.eclipse.jface.viewers.ColumnViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) EObject(org.eclipse.emf.ecore.EObject) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 54 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project archi by archimatetool.

the class ProfilesManagerDialog method createTableControl.

/**
 * Create the Table
 */
private void createTableControl(Composite parent) {
    Composite tableComp = new Composite(parent, SWT.BORDER);
    TableColumnLayout tableLayout = new TableColumnLayout();
    tableComp.setLayout(tableLayout);
    GridDataFactory.create(GridData.FILL_BOTH).applyTo(tableComp);
    fTableViewer = new TableViewer(tableComp, SWT.MULTI | SWT.FULL_SELECTION);
    GridDataFactory.create(GridData.FILL_BOTH).applyTo(fTableViewer.getControl());
    // Mac Silicon Item height
    UIUtils.fixMacSiliconItemHeight(fTableViewer.getTable());
    // Edit cell on single-click and add Tab key traversal
    TableViewerEditor.create(fTableViewer, new ColumnViewerEditorActivationStrategy(fTableViewer), ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEEP_EDITOR_ON_DOUBLE_CLICK | ColumnViewerEditor.KEYBOARD_ACTIVATION);
    fTableViewer.getTable().setHeaderVisible(true);
    fTableViewer.getTable().setLinesVisible(true);
    fTableViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            return ((IProfile) e1).getName().compareToIgnoreCase(((IProfile) e2).getName());
        }
    });
    // Columns
    // Icon
    TableViewerColumn columnIcon = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
    tableLayout.setColumnData(columnIcon.getColumn(), new ColumnWeightData(5, true));
    // Name
    TableViewerColumn columnName = new TableViewerColumn(fTableViewer, SWT.NONE, 1);
    columnName.getColumn().setText(Messages.ProfilesManagerDialog_7);
    tableLayout.setColumnData(columnName.getColumn(), new ColumnWeightData(50, true));
    columnName.setEditingSupport(new NameEditingSupport(fTableViewer));
    // Restricted to Concept Type
    TableViewerColumn columnConceptType = new TableViewerColumn(fTableViewer, SWT.NONE, 2);
    columnConceptType.getColumn().setText(Messages.ProfilesManagerDialog_8);
    tableLayout.setColumnData(columnConceptType.getColumn(), new ColumnWeightData(35, true));
    columnConceptType.setEditingSupport(new ConceptTypeEditingSupport(fTableViewer));
    // Usage
    TableViewerColumn columnUsage = new TableViewerColumn(fTableViewer, SWT.NONE, 3);
    columnUsage.getColumn().setText(Messages.ProfilesManagerDialog_9);
    tableLayout.setColumnData(columnUsage.getColumn(), new ColumnWeightData(10, true));
    // Content Provider
    fTableViewer.setContentProvider(new IStructuredContentProvider() {

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

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return fProfilesTemp.values().toArray();
        }
    });
    // Label Provider
    fTableViewer.setLabelProvider(new LabelCellProvider());
    fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = event.getStructuredSelection();
            boolean enabled = !selection.isEmpty();
            // Disable/enable some actions
            fActionDelete.setEnabled(enabled);
            fButtonDelete.setEnabled(enabled);
            fActionChooseImage.setEnabled(enabled);
            fActionClearImage.setEnabled(false);
            // Image buttons/actions depend on some factors...
            for (Object o : selection) {
                IProfile profile = (IProfile) o;
                // If any selected Profile can't have an image then this is disabled
                if (!canHaveImage(profile)) {
                    fActionChooseImage.setEnabled(false);
                }
                // Enable clear image only if there is one image to clear in the selection
                if (profile.getImagePath() != null) {
                    fActionClearImage.setEnabled(true);
                }
            }
            fImageButton.setEnabled(fActionChooseImage.isEnabled() || fActionClearImage.isEnabled());
            // Update Image Preview
            updateImagePreview();
        }
    });
    /*
         * Table Double-click
         */
    fTableViewer.getTable().addListener(SWT.MouseDoubleClick, (e) -> {
        // Get Table item
        Point pt = new Point(e.x, e.y);
        TableItem item = fTableViewer.getTable().getItem(pt);
        // Double-click into empty table creates new Profile
        if (item == null) {
            createNewProfile();
        }
    });
    // anything will do //$NON-NLS-1$
    fTableViewer.setInput("");
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TableItem(org.eclipse.swt.widgets.TableItem) TableViewer(org.eclipse.jface.viewers.TableViewer) ColumnViewer(org.eclipse.jface.viewers.ColumnViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Point(org.eclipse.swt.graphics.Point) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) IProfile(com.archimatetool.model.IProfile) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 55 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project translationstudio8 by heartsome.

the class ProjectSettingDialog method selectSavedItem.

/**
	 * Selects the saved item in the tree of preference pages. If it cannot do this it saves the first one.
	 */
protected void selectSavedItem() {
    IPreferenceNode node = findNodeMatching(getSelectedNodePreference());
    if (node == null) {
        IPreferenceNode[] nodes = preferenceManager.getRootSubNodes();
        ViewerComparator comparator = getTreeViewer().getComparator();
        if (comparator != null) {
            comparator.sort(null, nodes);
        }
        for (int i = 0; i < nodes.length; i++) {
            IPreferenceNode selectedNode = nodes[i];
            if (selectedNode != null) {
                node = selectedNode;
                break;
            }
        }
    }
    if (node != null) {
        getTreeViewer().setSelection(new StructuredSelection(node), true);
        // Keep focus in tree. See bugs 2692, 2621, and 6775.
        getTreeViewer().getControl().setFocus();
        boolean expanded = getTreeViewer().getExpandedState(node);
        getTreeViewer().setExpandedState(node, !expanded);
    }
}
Also used : ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IPreferenceNode(org.eclipse.jface.preference.IPreferenceNode)

Aggregations

ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)110 Viewer (org.eclipse.jface.viewers.Viewer)64 Composite (org.eclipse.swt.widgets.Composite)59 TableViewer (org.eclipse.jface.viewers.TableViewer)50 GridData (org.eclipse.swt.layout.GridData)50 GridLayout (org.eclipse.swt.layout.GridLayout)34 Label (org.eclipse.swt.widgets.Label)29 LabelProvider (org.eclipse.jface.viewers.LabelProvider)23 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)22 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)22 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)22 SelectionEvent (org.eclipse.swt.events.SelectionEvent)21 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)19 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)18 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)17 Button (org.eclipse.swt.widgets.Button)17 TreeViewer (org.eclipse.jface.viewers.TreeViewer)16 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)15 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)15