Search in sources :

Example 51 with IStructuredContentProvider

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

the class UserPropertiesSection method createTableControl.

private void createTableControl(Composite parent) {
    // Table Composite
    Composite tableComp = createTableComposite(parent, SWT.NULL);
    TableColumnLayout tableLayout = (TableColumnLayout) tableComp.getLayout();
    // Table Viewer
    fTableViewer = new TableViewer(tableComp, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
    // Font
    UIUtils.setFontFromPreferences(fTableViewer.getTable(), IPreferenceConstants.PROPERTIES_TABLE_FONT, true);
    // 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);
    addDragSupport();
    addDropSupport();
    // Help ID on table
    PlatformUI.getWorkbench().getHelpSystem().setHelp(fTableViewer.getTable(), HELP_ID);
    // Columns
    TableViewerColumn columnBlank = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
    tableLayout.setColumnData(columnBlank.getColumn(), new ColumnWeightData(3, false));
    columnBlank.getColumn().setWidth(38);
    TableViewerColumn columnKey = new TableViewerColumn(fTableViewer, SWT.NONE, 1);
    columnKey.getColumn().setText(Messages.UserPropertiesSection_0);
    tableLayout.setColumnData(columnKey.getColumn(), new ColumnWeightData(20, true));
    columnKey.setEditingSupport(new KeyEditingSupport(fTableViewer));
    // Click on Key Table Header
    columnKey.getColumn().addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            sortKeys();
        }
    });
    TableViewerColumn columnValue = new TableViewerColumn(fTableViewer, SWT.NONE, 2);
    columnValue.getColumn().setText(Messages.UserPropertiesSection_1);
    tableLayout.setColumnData(columnValue.getColumn(), new ColumnWeightData(77, true));
    columnValue.setEditingSupport(new ValueEditingSupport(fTableViewer));
    // 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 ((IProperties) inputElement).getProperties().toArray();
        }
    });
    // Label Provider
    fTableViewer.setLabelProvider(new LabelCellProvider());
    // Enable tooltips
    ColumnViewerToolTipSupport.enableFor(fTableViewer);
    // Toolbar
    ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.VERTICAL);
    getWidgetFactory().adapt(toolBar);
    GridDataFactory.fillDefaults().align(SWT.END, SWT.TOP).applyTo(toolBar);
    ToolBarManager toolBarmanager = new ToolBarManager(toolBar);
    // New Property
    fActionNewProperty = new Action(Messages.UserPropertiesSection_2) {

        @Override
        public void run() {
            if (isAlive(fPropertiesElement)) {
                // complete any current editing
                fTableViewer.applyEditorValue();
                int index = -1;
                IProperty selected = (IProperty) ((IStructuredSelection) fTableViewer.getSelection()).getFirstElement();
                if (selected != null) {
                    index = fPropertiesElement.getProperties().indexOf(selected) + 1;
                }
                IProperty property = IArchimateFactory.eINSTANCE.createProperty();
                executeCommand(new NewPropertyCommand(fPropertiesElement.getProperties(), property, index));
                fTableViewer.editElement(property, 1);
            }
        }

        @Override
        public String getToolTipText() {
            return getText();
        }

        @Override
        public ImageDescriptor getImageDescriptor() {
            return IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_PLUS);
        }
    };
    // New Multiple Properties
    fActionNewMultipleProperty = new Action(Messages.UserPropertiesSection_3) {

        @Override
        public void run() {
            if (isAlive(fPropertiesElement)) {
                MultipleAddDialog dialog = new MultipleAddDialog(fPage.getSite().getShell());
                if (dialog.open() == Window.OK) {
                    executeCommand(dialog.getCommand());
                }
            }
        }

        @Override
        public String getToolTipText() {
            return getText();
        }

        @Override
        public ImageDescriptor getImageDescriptor() {
            return IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_MUTIPLE);
        }
    };
    // Remove Property
    fActionRemoveProperty = new Action(Messages.UserPropertiesSection_4) {

        @Override
        public void run() {
            if (isAlive(fPropertiesElement)) {
                CompoundCommand compoundCmd = new EObjectNonNotifyingCompoundCommand(fPropertiesElement) {

                    @Override
                    public String getLabel() {
                        return getCommands().size() > 1 ? Messages.UserPropertiesSection_5 : Messages.UserPropertiesSection_6;
                    }
                };
                for (Object o : ((IStructuredSelection) fTableViewer.getSelection()).toList()) {
                    Command cmd = new RemovePropertyCommand(fPropertiesElement.getProperties(), (IProperty) o);
                    compoundCmd.add(cmd);
                }
                executeCommand(compoundCmd);
            }
        }

        @Override
        public String getToolTipText() {
            return getText();
        }

        @Override
        public ImageDescriptor getImageDescriptor() {
            return IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_SMALL_X);
        }
    };
    fActionRemoveProperty.setEnabled(false);
    // Manage
    fActionShowKeyEditor = new Action(Messages.UserPropertiesSection_7) {

        @Override
        public void run() {
            if (isAlive(fPropertiesElement)) {
                UserPropertiesManagerDialog dialog = new UserPropertiesManagerDialog(fPage.getSite().getShell(), getArchimateModel());
                dialog.open();
            }
        }

        @Override
        public String getToolTipText() {
            return getText();
        }

        @Override
        public ImageDescriptor getImageDescriptor() {
            return IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_COG);
        }
    };
    toolBarmanager.add(fActionNewProperty);
    toolBarmanager.add(fActionNewMultipleProperty);
    toolBarmanager.add(fActionRemoveProperty);
    toolBarmanager.add(fActionShowKeyEditor);
    toolBarmanager.update(true);
    /*
         * Selection Listener
         */
    fTableViewer.addSelectionChangedListener((e) -> {
        fActionRemoveProperty.setEnabled(!e.getSelection().isEmpty());
    });
    /*
         * 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 Property
        if (item == null) {
            fActionNewProperty.run();
        } else // Double-clicked in column 0 with item
        if (item.getData() instanceof IProperty) {
            Rectangle rect = item.getBounds(0);
            if (rect.contains(pt)) {
                handleDoubleClick((IProperty) item.getData());
            }
        }
    });
    /*
         * Edit table row on key press
         */
    fTableViewer.getTable().addKeyListener(KeyListener.keyPressedAdapter(e -> {
        if (e.keyCode == SWT.CR) {
            Object selected = fTableViewer.getStructuredSelection().getFirstElement();
            if (selected != null) {
                fTableViewer.editElement(selected, 1);
            }
        }
    }));
    hookContextMenu();
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) EObjectNonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.EObjectNonNotifyingCompoundCommand) Arrays(java.util.Arrays) Notification(org.eclipse.emf.common.notify.Notification) DND(org.eclipse.swt.dnd.DND) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) CellEditor(org.eclipse.jface.viewers.CellEditor) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) Point(org.eclipse.swt.graphics.Point) IArchimateModel(com.archimatetool.model.IArchimateModel) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) Matcher(java.util.regex.Matcher) Composite(org.eclipse.swt.widgets.Composite) PartInitException(org.eclipse.ui.PartInitException) ColorConstants(org.eclipse.draw2d.ColorConstants) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Separator(org.eclipse.jface.action.Separator) PlatformUI(org.eclipse.ui.PlatformUI) UpdatingTableColumnLayout(com.archimatetool.editor.ui.components.UpdatingTableColumnLayout) MenuManager(org.eclipse.jface.action.MenuManager) Set(java.util.Set) LightweightEContentAdapter(com.archimatetool.model.util.LightweightEContentAdapter) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) Transfer(org.eclipse.swt.dnd.Transfer) Window(org.eclipse.jface.window.Window) StringUtils(com.archimatetool.editor.utils.StringUtils) SWT(org.eclipse.swt.SWT) ColumnViewer(org.eclipse.jface.viewers.ColumnViewer) ECollections(org.eclipse.emf.common.util.ECollections) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) UIUtils(com.archimatetool.editor.ui.UIUtils) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ArrayList(java.util.ArrayList) IProperties(com.archimatetool.model.IProperties) Listener(org.eclipse.swt.widgets.Listener) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) GridData(org.eclipse.swt.layout.GridData) TableItem(org.eclipse.swt.widgets.TableItem) IArchimatePackage(com.archimatetool.model.IArchimatePackage) TableViewerEditor(org.eclipse.jface.viewers.TableViewerEditor) Shell(org.eclipse.swt.widgets.Shell) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) IActionBars(org.eclipse.ui.IActionBars) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) Color(org.eclipse.swt.graphics.Color) IMenuManager(org.eclipse.jface.action.IMenuManager) IArchiImages(com.archimatetool.editor.ui.IArchiImages) GridLayout(org.eclipse.swt.layout.GridLayout) EObjectNonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.EObjectNonNotifyingCompoundCommand) ColumnViewerEditor(org.eclipse.jface.viewers.ColumnViewerEditor) TableViewer(org.eclipse.jface.viewers.TableViewer) IPreferenceConstants(com.archimatetool.editor.preferences.IPreferenceConstants) IAction(org.eclipse.jface.action.IAction) ToolBar(org.eclipse.swt.widgets.ToolBar) HTMLUtils(com.archimatetool.editor.utils.HTMLUtils) ViewerCell(org.eclipse.jface.viewers.ViewerCell) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ColumnViewerToolTipSupport(org.eclipse.jface.viewers.ColumnViewerToolTipSupport) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) Button(org.eclipse.swt.widgets.Button) IArchimateFactory(com.archimatetool.model.IArchimateFactory) ExtendedTitleAreaDialog(com.archimatetool.editor.ui.components.ExtendedTitleAreaDialog) EObject(org.eclipse.emf.ecore.EObject) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) List(java.util.List) IProperty(com.archimatetool.model.IProperty) Command(org.eclipse.gef.commands.Command) ISelection(org.eclipse.jface.viewers.ISelection) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) StringComboBoxCellEditor(com.archimatetool.editor.ui.components.StringComboBoxCellEditor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IMenuListener(org.eclipse.jface.action.IMenuListener) BasicEList(org.eclipse.emf.common.util.BasicEList) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) Table(org.eclipse.swt.widgets.Table) Event(org.eclipse.swt.widgets.Event) HashSet(java.util.HashSet) ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) Iterator(java.util.Iterator) Viewer(org.eclipse.jface.viewers.Viewer) MalformedURLException(java.net.MalformedURLException) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) GlobalActionDisablementHandler(com.archimatetool.editor.ui.components.GlobalActionDisablementHandler) Action(org.eclipse.jface.action.Action) EditingSupport(org.eclipse.jface.viewers.EditingSupport) EList(org.eclipse.emf.common.util.EList) ToolBarManager(org.eclipse.jface.action.ToolBarManager) KeyListener(org.eclipse.swt.events.KeyListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) Comparator(java.util.Comparator) LabelProvider(org.eclipse.jface.viewers.LabelProvider) Control(org.eclipse.swt.widgets.Control) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) Listener(org.eclipse.swt.widgets.Listener) IMenuListener(org.eclipse.jface.action.IMenuListener) DragSourceListener(org.eclipse.swt.dnd.DragSourceListener) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) KeyListener(org.eclipse.swt.events.KeyListener) TableItem(org.eclipse.swt.widgets.TableItem) Rectangle(org.eclipse.swt.graphics.Rectangle) ColumnViewer(org.eclipse.jface.viewers.ColumnViewer) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) IProperties(com.archimatetool.model.IProperties) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ToolBarManager(org.eclipse.jface.action.ToolBarManager) EObjectNonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.EObjectNonNotifyingCompoundCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) UpdatingTableColumnLayout(com.archimatetool.editor.ui.components.UpdatingTableColumnLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) IProperty(com.archimatetool.model.IProperty) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Composite(org.eclipse.swt.widgets.Composite) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) Point(org.eclipse.swt.graphics.Point) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) EObjectNonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.EObjectNonNotifyingCompoundCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) ToolBar(org.eclipse.swt.widgets.ToolBar) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) Event(org.eclipse.swt.widgets.Event) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) EObject(org.eclipse.emf.ecore.EObject) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 52 with IStructuredContentProvider

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

the class ExportJasperReportsWizardPage2 method createControl.

@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    container.setLayout(new GridLayout());
    setControl(container);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(container, HELP_ID);
    Composite fieldContainer = new Composite(container, SWT.NULL);
    fieldContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fieldContainer.setLayout(new GridLayout(2, false));
    // Template Combo
    Label label = new Label(fieldContainer, SWT.NONE);
    label.setText(Messages.ExportJasperReportsWizardPage2_4);
    fComboTemplateViewer = new ComboViewer(new Combo(fieldContainer, SWT.READ_ONLY | SWT.BORDER));
    fComboTemplateViewer.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fComboTemplateViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            Template template = (Template) ((IStructuredSelection) event.getSelection()).getFirstElement();
            if (template.location == null) {
                // Custom...
                handleCustomDialog();
            } else {
                fLastSelectedTemplate = template;
            }
        }
    });
    fComboTemplateViewer.setContentProvider(new IStructuredContentProvider() {

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

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return fTemplates.toArray();
        }
    });
    fComboTemplateViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((Template) element).name;
        }
    });
    // $NON-NLS-1$
    fComboTemplateViewer.setInput("");
    fComboTemplateViewer.setSelection(new StructuredSelection(fTemplates.get(0)));
    // Locale Combo
    label = new Label(fieldContainer, SWT.NONE);
    label.setText(Messages.ExportJasperReportsWizardPage2_6);
    fComboLocale = new ComboViewer(new Combo(fieldContainer, SWT.READ_ONLY | SWT.BORDER));
    fComboLocale.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fComboLocale.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            Locale locale = (Locale) ((IStructuredSelection) event.getSelection()).getFirstElement();
            fSelectedLocale = locale;
        }
    });
    fComboLocale.setContentProvider(new IStructuredContentProvider() {

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

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            Locale[] locales = Locale.getAvailableLocales();
            Comparator<Locale> localeComparator = new Comparator<Locale>() {

                @Override
                public int compare(Locale locale1, Locale locale2) {
                    return locale1.toString().compareTo(locale2.toString());
                }
            };
            Arrays.sort(locales, localeComparator);
            return locales;
        }
    });
    fComboLocale.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((Locale) element).toLanguageTag();
        }
    });
    // $NON-NLS-1$
    fComboLocale.setInput("");
    fComboLocale.setSelection(new StructuredSelection(fSelectedLocale));
}
Also used : Locale(java.util.Locale) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Combo(org.eclipse.swt.widgets.Combo) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Comparator(java.util.Comparator) GridLayout(org.eclipse.swt.layout.GridLayout) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 53 with IStructuredContentProvider

use of org.eclipse.jface.viewers.IStructuredContentProvider in project xtext-eclipse by eclipse.

the class TypeChooser method choose.

public JvmDeclaredType choose(final List<JvmDeclaredType> candidateTypes, Iterable<TypeUsage> usages, final XtextResource resource) {
    XtextEditor activeXtextEditor = EditorUtils.getActiveXtextEditor();
    if (activeXtextEditor == null)
        return null;
    revealInEditor(activeXtextEditor, usages, resource);
    Shell shell = Display.getDefault().getActiveShell();
    IStructuredContentProvider contentProvider = new ContentProvider();
    Dialog dialog = new Dialog(shell, new LabelProvider(labelProvider), contentProvider);
    dialog.setInput(candidateTypes);
    dialog.setInitialSelections((Object[]) new JvmDeclaredType[] { candidateTypes.get(0) });
    int result = dialog.open();
    if (originalSelection != null)
        activeXtextEditor.getSelectionProvider().setSelection(originalSelection);
    if (result == Window.OK && dialog.getResult().length > 0)
        return (JvmDeclaredType) dialog.getResult()[0];
    else
        return null;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) ListDialog(org.eclipse.ui.dialogs.ListDialog) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) AbstractLabelProvider(org.eclipse.xtext.ui.label.AbstractLabelProvider) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider)

Example 54 with IStructuredContentProvider

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

the class JavaImageTab method createControl.

@Override
public void createControl(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);
    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);
    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;
            if (conn == null || conn.getImages() == null) {
                return new Object[0];
            } else {
                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();
            selectedConnection = conn;
            imageCmb.setInput(conn);
            updateLaunchConfigurationDialog();
        }
    });
    imageCmb.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = event.getStructuredSelection();
            IDockerImage img = (IDockerImage) sel.getFirstElement();
            selectedImage = img;
            updateLaunchConfigurationDialog();
        }
    });
    Group dirGroup = new Group(composite, SWT.NONE);
    dirGroup.setText(Messages.JavaImageTab_additional_dirs);
    dirGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    dirGroup.setLayout(new GridLayout(2, false));
    directoryList = new List(dirGroup, SWT.SINGLE | SWT.V_SCROLL);
    directoryList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2));
    directoryList.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            removeButton.setEnabled(true);
        }
    });
    addButton = createPushButton(dirGroup, Messages.JavaImageTab_button_add, null);
    addButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    addButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog dialog = new DirectoryDialog(getShell());
            String directory = dialog.open();
            if (directory != null && !listContains(directoryList, directory)) {
                directoryList.add(directory);
                updateLaunchConfigurationDialog();
            }
        }
    });
    removeButton = createPushButton(dirGroup, Messages.JavaImageTab_button_remove, null);
    removeButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true));
    removeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int i = directoryList.getSelectionIndex();
            if (i >= 0) {
                directoryList.remove(i);
                updateLaunchConfigurationDialog();
            }
            if (directoryList.getItemCount() == 0) {
                removeButton.setEnabled(false);
            }
        }
    });
    removeButton.setEnabled(false);
    setControl(composite);
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Arrays(java.util.Arrays) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) CoreException(org.eclipse.core.runtime.CoreException) ComboViewer(org.eclipse.jface.viewers.ComboViewer) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) AbstractLaunchConfigurationTab(org.eclipse.debug.ui.AbstractLaunchConfigurationTab) Composite(org.eclipse.swt.widgets.Composite) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) DockerException(org.eclipse.linuxtools.docker.core.DockerException) GridData(org.eclipse.swt.layout.GridData) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Button(org.eclipse.swt.widgets.Button) DockerConnectionManager(org.eclipse.linuxtools.docker.core.DockerConnectionManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Group(org.eclipse.swt.widgets.Group) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) SWT(org.eclipse.swt.SWT) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) List(org.eclipse.swt.widgets.List) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) 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) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(org.eclipse.swt.widgets.List) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 55 with IStructuredContentProvider

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

the class FileSystemSelectionArea method createContents.

/**
 * Create the contents of the receiver in composite.
 * @param composite Parent composite for created components.
 */
public void createContents(Composite composite) {
    fileSystemTitle = new Label(composite, SWT.NONE);
    fileSystemTitle.setText(ResourceSelectorWidgetMessages.fileSystemSelectionText);
    fileSystemTitle.setFont(composite.getFont());
    fileSystems = new ComboViewer(composite, SWT.READ_ONLY);
    fileSystems.getControl().setFont(composite.getFont());
    fileSystems.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((FileSystemElement) element).getSchemeLabel();
        }
    });
    fileSystems.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void dispose() {
        // Nothing to do
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return getSchemes();
        }

        @Override
        public void inputChanged(org.eclipse.jface.viewers.Viewer viewer, Object oldInput, Object newInput) {
        // Nothing to do
        }
    });
    fileSystems.setInput(this);
    Iterator<FileSystemElement> fsEltItr = fsElements.iterator();
    boolean foundDefault = false;
    while (fsEltItr.hasNext()) {
        FileSystemElement fsElt = fsEltItr.next();
        if (fsElt.getIsDefault()) {
            if (foundDefault) {
                ProfileLaunchPlugin.log(IStatus.WARNING, ResourceSelectorWidgetMessages.FileSystemSelectionArea_found_multiple_default_extensions + fsElt.getScheme());
                // use only the first one we found marked as default
                continue;
            }
            fileSystems.setSelection(new StructuredSelection(fsElt));
            foundDefault = true;
        }
    }
}
Also used : Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ComboViewer(org.eclipse.jface.viewers.ComboViewer) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Aggregations

IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)99 Viewer (org.eclipse.jface.viewers.Viewer)77 Composite (org.eclipse.swt.widgets.Composite)58 GridData (org.eclipse.swt.layout.GridData)54 TableViewer (org.eclipse.jface.viewers.TableViewer)45 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)43 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)42 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)40 GridLayout (org.eclipse.swt.layout.GridLayout)40 LabelProvider (org.eclipse.jface.viewers.LabelProvider)32 Image (org.eclipse.swt.graphics.Image)29 Button (org.eclipse.swt.widgets.Button)28 Label (org.eclipse.swt.widgets.Label)28 SelectionEvent (org.eclipse.swt.events.SelectionEvent)26 Table (org.eclipse.swt.widgets.Table)24 ArrayList (java.util.ArrayList)23 ComboViewer (org.eclipse.jface.viewers.ComboViewer)19 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)19 ILabelProviderListener (org.eclipse.jface.viewers.ILabelProviderListener)18 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)18