Java Examples for org.eclipse.jface.viewers.ArrayContentProvider

The following java examples will help you to understand the usage of org.eclipse.jface.viewers.ArrayContentProvider. These source code samples are taken from different open source projects.

Example 1
Project: liferay-ide-master  File: FindBreakingChangesPage.java View source code
public void createTableView(Composite container) {
    GridData gridData = new GridData(GridData.FILL_BOTH);
    gridData.minimumWidth = 200;
    gridData.minimumHeight = 200;
    _problemsViewer = new TableViewer(container, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
    _problemsViewer.getTable().setLayoutData(gridData);
    createColumns(_problemsViewer);
    final Table table = _problemsViewer.getTable();
    table.setHeaderVisible(true);
    _problemsViewer.setContentProvider(ArrayContentProvider.getInstance());
    _problemsViewer.setComparer(null);
    _comparator = new MigratorComparator();
    _problemsViewer.setComparator(_comparator);
    MenuManager menuMgr = new MenuManager();
    IAction markDoneAction = new MarkDoneAction(_problemsViewer);
    IAction markUndoneAction = new MarkUndoneAction(_problemsViewer);
    IAction ignoreAction = new IgnoreAction(_problemsViewer);
    IAction ignoreAlways = new IgnoreAlwaysAction(_problemsViewer);
    IAction autoCorrectAction = new AutoCorrectAction(_problemsViewer);
    menuMgr.add(markDoneAction);
    menuMgr.add(markUndoneAction);
    menuMgr.add(ignoreAction);
    menuMgr.add(autoCorrectAction);
    menuMgr.add(ignoreAlways);
    Menu menu = menuMgr.createContextMenu(table);
    table.setMenu(menu);
    _problemsViewer.addDoubleClickListener(this);
}
Example 2
Project: geotools-old-master  File: CRSChooser.java View source code
private Control createStandardCRSControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    composite.setLayout(layout);
    GridData gridData = new GridData();
    Label codesLabel = new Label(composite, SWT.NONE);
    codesLabel.setText(Messages.getString("CRSChooser_label_crs"));
    codesLabel.setLayoutData(gridData);
    gridData = new GridData(SWT.FILL, SWT.FILL, false, false);
    searchText = new Text(composite, SWT.SINGLE | SWT.BORDER | SWT.SEARCH | SWT.CANCEL);
    searchText.setLayoutData(gridData);
    searchText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            fillCodesList();
        }
    });
    searchText.addListener(SWT.KeyUp, new Listener() {

        public void handleEvent(Event event) {
            if (event.keyCode == SWT.ARROW_DOWN) {
                codesList.getControl().setFocus();
            }
        }
    });
    gridData = new GridData(400, 300);
    codesList = new ListViewer(composite);
    codesList.setContentProvider(new ArrayContentProvider());
    codesList.setLabelProvider(new LabelProvider());
    codesList.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            selectedCRS = null;
            String crsCode = (String) ((IStructuredSelection) codesList.getSelection()).getFirstElement();
            if (crsCode == null)
                return;
            matcher.reset(crsCode);
            if (matcher.matches()) {
                selectedCRS = createCRS(matcher.group(1));
                if (selectedCRS != null && wktText != null) {
                    wktText.setEditable(true);
                    String wkt = null;
                    try {
                        wkt = selectedCRS.toWKT();
                    } catch (Exception e) {
                        wkt = selectedCRS.toString();
                        wktText.setEditable(false);
                    }
                    wktText.setText(wkt);
                    Preferences node = findNode(matcher.group(1));
                    if (node != null) {
                        Preferences kn = node.node(ALIASES_ID);
                        try {
                            String[] keywords = kn.keys();
                            if (keywords.length > 0) {
                                StringBuffer buffer = new StringBuffer();
                                for (String string : keywords) {
                                    //$NON-NLS-1$
                                    buffer.append(", ");
                                    buffer.append(string);
                                }
                                buffer.delete(0, 2);
                                keywordsText.setText(buffer.toString());
                            }
                        } catch (BackingStoreException e) {
                            ExceptionMonitor.show(wktText.getShell(), e);
                        }
                    } else {
                        //$NON-NLS-1$
                        keywordsText.setText("");
                    }
                }
            }
        }
    });
    codesList.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            parentPage.handleOk();
            parentPage.handleClose();
        }
    });
    codesList.getControl().setLayoutData(gridData);
    /*
         * fillCodesList() by itself resizes the Preferences Page but in the paintlistener it
         * flickers the window
         */
    fillCodesList();
    searchText.setFocus();
    return composite;
}
Example 3
Project: extFM-Tooling-master  File: SatisfiabilityDialog.java View source code
@Override
protected Control createCustomArea(Composite parent) {
    viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
    createColumns(parent, viewer);
    final Table table = viewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    viewer.setContentProvider(new ArrayContentProvider());
    // Get the content for the viewer, setInput will call getElements in the
    // contentProvider
    viewer.setInput(getFileList());
    // Layout the viewer
    GridData gridData = new GridData();
    gridData.verticalAlignment = GridData.FILL;
    gridData.horizontalSpan = 2;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    viewer.getControl().setLayoutData(gridData);
    return viewer.getControl();
}
Example 4
Project: tern.java-master  File: TernModulesBlock.java View source code
/**
	 * Create table of tern modules.
	 * 
	 * @param ancestor
	 */
private void createModulesMaster(Composite ancestor) {
    Composite parent = new Composite(ancestor, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    parent.setLayout(layout);
    Font font = ancestor.getFont();
    parent.setFont(font);
    Table table = new Table(parent, SWT.CHECK | SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.widthHint = 350;
    data.heightHint = 400;
    table.setLayoutData(data);
    table.setFont(parent.getFont());
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    tableViewer = new CheckboxTableViewer(table);
    // create name column
    TableViewerColumn nameColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    nameColumn.getColumn().setWidth(180);
    nameColumn.getColumn().setResizable(true);
    nameColumn.getColumn().setText(TernUIMessages.TernModulesBlock_moduleName);
    nameColumn.getColumn().addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            sortByName();
        }
    });
    // create version column
    TableViewerColumn versionColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    versionColumn.getColumn().setWidth(100);
    versionColumn.getColumn().setResizable(true);
    versionColumn.getColumn().setText(TernUIMessages.TernModulesBlock_moduleVersion);
    final TernModuleVersionEditingSupport versionEditiongSupport = new TernModuleVersionEditingSupport(tableViewer);
    versionColumn.setEditingSupport(versionEditiongSupport);
    tableViewer.setComparer(TERN_MODULES_COMPARER);
    tableViewer.setLabelProvider(TernModuleLabelProvider.getInstance());
    tableViewer.setContentProvider(ArrayContentProvider.getInstance());
    // when a module is checked and dependencies checkbox is checked, tern
    // module dependencies must be selected too
    addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent e) {
            if (checkUpdating) {
                return;
            }
            try {
                checkUpdating = true;
                ITernModule module = ((ITernModule) e.getElement());
                // update checked modules list
                updateCheckedModules(module, e.getChecked());
                if (e.getChecked() && isSelectDependencies()) {
                    TernModuleMetadata metadata = module.getMetadata();
                    if (metadata != null) {
                        ITernModule dependencyModule = null;
                        // loop for each dependencies and check it if needed
                        for (String moduleName : metadata.getDependencies(module.getVersion())) {
                            dependencyModule = ternModules.get(moduleName);
                            if (dependencyModule != null) {
                                // update module selection
                                if (!tableViewer.getChecked(dependencyModule)) {
                                    tableViewer.setChecked(dependencyModule, true);
                                }
                                // update checked modules list
                                updateCheckedModules(dependencyModule, true);
                                if (dependencyModule instanceof ITernModuleConfigurable) {
                                    ITernModuleConfigurable configurable = (ITernModuleConfigurable) dependencyModule;
                                    if (configurable.hasVersion()) {
                                        // update version
                                        String version = configurable.getModule(moduleName).getVersion();
                                        versionEditiongSupport.setValue(dependencyModule, version);
                                    }
                                }
                            }
                        }
                    }
                }
            } finally {
                checkUpdating = false;
            }
        }
    });
    // when a module is selected, details, dependencies, options tabs must
    // be
    // refreshed.
    addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent e) {
            if (!e.getSelection().isEmpty()) {
                ITernModule module = (ITernModule) ((IStructuredSelection) e.getSelection()).getFirstElement();
                refreshModule(module);
            } else {
                refreshModule(null);
            }
        }
    });
    restoreColumnSettings();
}
Example 5
Project: codemap-master  File: SelectionView.java View source code
@Override
public void createPartControl(Composite parent) {
    // the PageBook allows simple switching between two viewers
    pagebook = new PageBook(parent, SWT.NONE);
    tableviewer = new TableViewer(pagebook, SWT.NONE);
    tableviewer.setLabelProvider(new WorkbenchLabelProvider());
    tableviewer.setContentProvider(new ArrayContentProvider());
    tableviewer.setSelection(null);
    // we're cooperative and also provide our selection
    // at least for the tableviewer
    getSite().setSelectionProvider(tableviewer);
    textviewer = new TextViewer(pagebook, SWT.H_SCROLL | SWT.V_SCROLL);
    textviewer.setEditable(false);
    getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(PACKAGE_EXPLORER.id, listener);
}
Example 6
Project: eclipse.jdt.ui-master  File: JUnitLaunchConfigurationTab.java View source code
private void createTestLoaderGroup(Composite comp) {
    Label loaderLabel = new Label(comp, SWT.NONE);
    loaderLabel.setText(JUnitMessages.JUnitLaunchConfigurationTab_Test_Loader);
    GridData gd = new GridData();
    gd.horizontalIndent = 0;
    loaderLabel.setLayoutData(gd);
    fTestLoaderViewer = new ComboViewer(comp, SWT.DROP_DOWN | SWT.READ_ONLY);
    fTestLoaderViewer.getCombo().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    ArrayList<TestKind> items = TestKindRegistry.getDefault().getAllKinds();
    fTestLoaderViewer.setContentProvider(new ArrayContentProvider());
    fTestLoaderViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((TestKind) element).getDisplayName();
        }
    });
    fTestLoaderViewer.setInput(items);
    fTestLoaderViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            validatePage();
            updateLaunchConfigurationDialog();
        }
    });
}
Example 7
Project: EclipseTrader-master  File: OrderDialog.java View source code
protected void createOrderDescriptionGroup(Composite parent) {
    Group content = new Group(parent, SWT.NONE);
    content.setText(Messages.OrderDialog_OrderDescriptionGroup);
    content.setLayout(new GridLayout(2, false));
    content.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    Label label = new Label(content, SWT.NONE);
    label.setText(Messages.OrderDialog_ActionLabel);
    sideCombo = new ComboViewer(content, SWT.BORDER | SWT.READ_ONLY | SWT.DROP_DOWN);
    sideCombo.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    sideCombo.setContentProvider(new ArrayContentProvider());
    sideCombo.setLabelProvider(new LabelProvider());
    label = new Label(content, SWT.NONE);
    label.setText(Messages.OrderDialog_QuantityLabel);
    quantity = new Text(content, SWT.BORDER);
    quantity.setLayoutData(new GridData(convertWidthInCharsToPixels(18), SWT.DEFAULT));
    ((GridData) quantity.getLayoutData()).horizontalAlignment = SWT.FILL;
    label = new Label(content, SWT.NONE);
    label.setText(Messages.OrderDialog_OrderTypeLabel);
    typeCombo = new ComboViewer(content, SWT.BORDER | SWT.READ_ONLY | SWT.DROP_DOWN);
    typeCombo.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    typeCombo.setContentProvider(new ArrayContentProvider());
    typeCombo.setLabelProvider(new LabelProvider());
    label = new Label(content, SWT.NONE);
    label.setText(Messages.OrderDialog_LimitPriceLabel);
    price = new Text(content, SWT.BORDER);
    price.setLayoutData(new GridData(convertWidthInCharsToPixels(18), SWT.DEFAULT));
    ((GridData) price.getLayoutData()).horizontalAlignment = SWT.FILL;
    price.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent event) {
            try {
                double n = priceFormat.parse(((Text) event.widget).getText()).doubleValue();
                ((Text) event.widget).setText(priceFormat.format(n));
            } catch (Exception e) {
            }
        }
    });
    label = new Label(content, SWT.NONE);
    label.setText(Messages.OrderDialog_BrokerLabel);
    brokerCombo = new ComboViewer(content, SWT.BORDER | SWT.READ_ONLY | SWT.DROP_DOWN);
    brokerCombo.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    brokerCombo.setContentProvider(new ArrayContentProvider());
    brokerCombo.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((IBroker) element).getName();
        }
    });
    brokerCombo.setSorter(new ViewerSorter());
    brokerCombo.setInput(tradingService.getBrokers());
    label = new Label(content, SWT.NONE);
    label.setText("Account");
    accountCombo = new ComboViewer(content, SWT.BORDER | SWT.READ_ONLY | SWT.DROP_DOWN);
    accountCombo.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    accountCombo.setContentProvider(new ArrayContentProvider());
    accountCombo.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((IAccount) element).getDescription();
        }
    });
    accountCombo.setSorter(new ViewerSorter());
    accountCombo.getControl().setEnabled(false);
    label = new Label(content, SWT.NONE);
    label.setText(Messages.OrderDialog_RouteLabel);
    routeCombo = new ComboViewer(content, SWT.BORDER | SWT.READ_ONLY | SWT.DROP_DOWN);
    routeCombo.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    routeCombo.setContentProvider(new ArrayContentProvider());
    routeCombo.setLabelProvider(new LabelProvider());
    routeCombo.setSorter(new ViewerSorter());
}
Example 8
Project: xmind-master  File: SpellingCheckPrefPage.java View source code
private void createDictionaryViewer(Composite parent) {
    dictionaryViewer = new CheckListViewer(parent, SWT.BORDER);
    dictionaryViewer.getControl().setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    dictionaryViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    dictionaryViewer.setContentProvider(new ArrayContentProvider());
    dictionaryViewer.setLabelProvider(new DictionaryLabelProvider());
    dictionaryViewer.setComparator(new DictionaryComparator());
    dictionaryViewer.addSelectionChangedListener(new DictionarySelectionListener());
    dictionaryViewer.addOpenListener(new DictionaryOpenHandler());
    dictionaryViewer.setInput(getInput());
    initCheckStates();
}
Example 9
Project: tcf-master  File: PeerAttributesTablePart.java View source code
/* (non-Javadoc)
	 * @see org.eclipse.tcf.te.ui.forms.parts.TablePart#configureTableViewer(org.eclipse.jface.viewers.TableViewer)
	 */
@Override
protected void configureTableViewer(final TableViewer viewer) {
    super.configureTableViewer(viewer);
    if (viewer != null && viewer.getTable() != null && !viewer.getTable().isDisposed()) {
        Table table = viewer.getTable();
        // Create the table columns
        new TableColumn(table, SWT.NONE).setText(Messages.PeerAttributesTablePart_column_name);
        new TableColumn(table, SWT.NONE).setText(Messages.PeerAttributesTablePart_column_value);
        // Create and configure the table layout
        TableLayout tableLayout = new TableLayout();
        tableLayout.addColumnData(new ColumnWeightData(40, true));
        tableLayout.addColumnData(new ColumnWeightData(60, true));
        table.setLayout(tableLayout);
        table.setHeaderVisible(true);
        table.setLinesVisible(true);
        // Setup the cell editors
        viewer.setColumnProperties(new String[] { Messages.PeerAttributesTablePart_column_name, Messages.PeerAttributesTablePart_column_value });
        CellEditor[] cellEditors = new CellEditor[viewer.getColumnProperties().length];
        cellEditors[0] = new TextCellEditor(table);
        ((Text) cellEditors[0].getControl()).setTextLimit(250);
        cellEditors[1] = new TextCellEditor(table);
        ((Text) cellEditors[1].getControl()).setTextLimit(250);
        viewer.setCellEditors(cellEditors);
        viewer.setCellModifier(new ICellModifier() {

            @Override
            public boolean canModify(Object element, String property) {
                return element instanceof TableNode && !isReadOnly();
            }

            @Override
            public Object getValue(Object element, String property) {
                String value = null;
                if (element instanceof TableNode) {
                    if (Messages.PeerAttributesTablePart_column_name.equals(property)) {
                        value = ((TableNode) element).name;
                    } else if (Messages.PeerAttributesTablePart_column_value.equals(property)) {
                        value = ((TableNode) element).value;
                    }
                }
                return value;
            }

            @Override
            public void modify(Object element, String property, Object value) {
                if (element instanceof TableItem)
                    element = ((TableItem) element).getData();
                if (element instanceof TableNode) {
                    if (Messages.PeerAttributesTablePart_column_name.equals(property)) {
                        ((TableNode) element).name = //$NON-NLS-1$
                        value != null ? //$NON-NLS-1$
                        value.toString() : //$NON-NLS-1$
                        "";
                    } else if (Messages.PeerAttributesTablePart_column_value.equals(property)) {
                        ((TableNode) element).value = //$NON-NLS-1$
                        value != null ? //$NON-NLS-1$
                        value.toString() : //$NON-NLS-1$
                        "";
                    }
                    viewer.setInput(nodes);
                    onTableModified();
                }
            }
        });
        // Create and set content and label provider
        viewer.setContentProvider(new ArrayContentProvider());
        viewer.setLabelProvider(new TableLabelProvider());
        // Configure the comparator
        viewer.setComparator(new TableViewerComparator(viewer, (ITableLabelProvider) viewer.getLabelProvider()));
        // Attach listeners
        viewer.addSelectionChangedListener(new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                updateButtons();
            }
        });
    }
}
Example 10
Project: warlock2-master  File: HighlightStringsPreferencePage.java View source code
private void createStringsTable(Composite main) {
    Group stringsGroup = new Group(main, SWT.NONE);
    stringsGroup.setLayout(new GridLayout(2, false));
    stringsGroup.setText(getDisplayName());
    stringsGroup.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
    Composite filterComposite = new Composite(stringsGroup, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    layout.marginWidth = layout.marginHeight = 0;
    filterComposite.setLayout(layout);
    filterComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    new Label(filterComposite, SWT.NONE).setText("Filter: ");
    filterText = new Text(filterComposite, SWT.BORDER);
    filterText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            stringTable.refresh();
        }
    });
    filterText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    new Label(stringsGroup, SWT.NONE);
    stringTable = new TableViewer(stringsGroup, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL);
    TableColumn column = new TableColumn(stringTable.getTable(), SWT.NONE, 0);
    column.setWidth(400);
    stringTable.setUseHashlookup(true);
    stringTable.setColumnProperties(new String[] { "highlightString" });
    CellEditor editors[] = new CellEditor[] { new TextCellEditor(stringTable.getTable()) };
    stringTable.setCellEditors(editors);
    stringTable.setCellModifier(new ICellModifier() {

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

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

        public void modify(Object element, String property, Object value) {
            TableItem item = (TableItem) element;
            HighlightString string = (HighlightString) item.getData();
            String pattern = ((String) value).trim();
            try {
                string.setText(pattern);
            } catch (PatternSyntaxException e) {
                e.printStackTrace();
            }
            stringTable.refresh(string);
        }
    });
    stringTable.addFilter(new ViewerFilter() {

        public boolean select(Viewer viewer, Object parentElement, Object element) {
            HighlightString string = (HighlightString) element;
            String str = string.getText();
            if (str.equals(""))
                return true;
            return (str.toLowerCase().contains(filterText.getText().toLowerCase()));
        }
    });
    stringTable.setLabelProvider(new StringsLabelProvider());
    stringTable.setContentProvider(new ArrayContentProvider());
    stringTable.setInput(highlightStrings);
    int listHeight = stringTable.getTable().getItemHeight() * 8;
    Rectangle trim = stringTable.getTable().computeTrim(0, 0, 0, listHeight);
    GridData data = new GridData(GridData.FILL, GridData.FILL, true, true);
    data.heightHint = trim.height;
    stringTable.getTable().setLayoutData(data);
    stringTable.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            HighlightString string = (HighlightString) selection.getFirstElement();
            if (string != selectedString) {
                stringTable.cancelEditing();
            }
            highlightStringSelected(string);
        }
    });
    Composite buttonsComposite = new Composite(stringsGroup, SWT.NONE);
    buttonsComposite.setLayout(new GridLayout(1, true));
    buttonsComposite.setLayoutData(new GridData(GridData.CENTER, GridData.BEGINNING, true, true));
    addString = createButton(buttonsComposite, "Add", SWT.LEFT | SWT.PUSH);
    addString.setImage(WarlockSharedImages.getImage(WarlockSharedImages.IMG_ADD));
    addString.setLayoutData(new GridData(GridData.FILL_BOTH));
    removeString = createButton(buttonsComposite, "Remove", SWT.LEFT | SWT.PUSH);
    removeString.setImage(WarlockSharedImages.getImage(WarlockSharedImages.IMG_REMOVE));
    removeString.setEnabled(false);
}
Example 11
Project: swtbot-master  File: JDTRecorderDialog.java View source code
/**
	 * Create contents of the dialog.
	 *
	 * @param parent
	 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);
    container.setLayout(new GridLayout(1, false));
    container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    Composite generatorSelectionContainer = new Composite(container, SWT.NONE);
    generatorSelectionContainer.setLayout(new GridLayout(2, false));
    Label selectorLabel = new Label(generatorSelectionContainer, SWT.NONE);
    selectorLabel.setText("Target Bot API:");
    selectorLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
    ComboViewer generatorSelectionCombo = new ComboViewer(generatorSelectionContainer);
    generatorSelectionCombo.setContentProvider(new ArrayContentProvider());
    generatorSelectionCombo.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object o) {
            return ((Generator) o).getLabel();
        }
    });
    generatorSelectionCombo.setInput(this.availableGenerators);
    generatorSelectionCombo.setSelection(new StructuredSelection(this.recorder.getCurrentGenerator()));
    generatorSelectionCombo.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            Generator newGenerator = (Generator) ((IStructuredSelection) event.getSelection()).getFirstElement();
            recorder.setGenerator(newGenerator);
            updateAnnotationToolBar();
            Image image = newGenerator.getImage();
            if (image != null) {
                image = new Image(Display.getDefault(), image.getImageData().scaledTo(80, 80));
                setTitleImage(image);
            } else {
                setTitleImage(null);
            }
        }
    });
    classTabFolder = new CTabFolder(container, SWT.CLOSE | SWT.BORDER);
    classTabFolder.setUnselectedCloseVisible(false);
    classTabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    ToolBar addClassToolbar = new ToolBar(classTabFolder, SWT.HORIZONTAL);
    classTabFolder.setTopRight(addClassToolbar);
    ToolItem addClassItem = new ToolItem(addClassToolbar, SWT.NONE);
    addClassItem.setText("+");
    addClassItem.setToolTipText("Add class");
    addClassItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            openClassShell();
        }
    });
    createTabItem(classTabFolder, "RecordedTestCase");
    classTabFolder.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(org.eclipse.swt.events.SelectionEvent event) {
            SourceViewer viewer = tabViewer.get(classTabFolder.getSelection());
            ClassDocument doc = (ClassDocument) viewer.getDocument();
            if (doc.getActiveMethod() == null) {
                recorder.setRecording(false);
                recordPauseButton.setText("Start Recording");
            }
            updateAnnotationToolBar();
        }
    });
    Composite actionsComposite = new Composite(container, SWT.NONE);
    actionsComposite.setLayout(new RowLayout(SWT.HORIZONTAL));
    recordPauseButton = new Button(actionsComposite, SWT.PUSH);
    recordPauseButton.setText("Start Recording");
    final Button copyButton = new Button(actionsComposite, SWT.PUSH);
    copyButton.setText("Copy");
    recordPauseButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (recorder.isRecording()) {
                recorder.setRecording(false);
                recordPauseButton.setText("Start Recording");
            } else {
                SourceViewer viewer = tabViewer.get(classTabFolder.getSelection());
                ClassDocument doc = (ClassDocument) viewer.getDocument();
                if (doc.getActiveMethod() == null) {
                    openMethodShell(true);
                } else {
                    recorder.setRecording(true);
                    recordPauseButton.setText("Pause");
                }
            }
        }
    });
    this.recorder.addListener(new CodeGenerationListener() {

        public void handleCodeGenerated(GenerationRule code) {
            SourceViewer viewer = tabViewer.get(classTabFolder.getSelection());
            ClassDocument doc = (ClassDocument) viewer.getDocument();
            doc.addGenerationRule(code);
            viewer.setTopIndex(((ClassDocument) viewer.getDocument()).getLastOffset() - 4);
        }
    });
    copyButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            final Clipboard cb = new Clipboard(Display.getDefault());
            TextTransfer textTransfer = TextTransfer.getInstance();
            SourceViewer viewer = tabViewer.get(classTabFolder.getSelection());
            cb.setContents(new Object[] { viewer.getDocument().get() }, new Transfer[] { textTransfer });
            cb.dispose();
        }
    });
    return container;
}
Example 12
Project: cdt-tests-runner-master  File: RegexErrorParserOptionPage.java View source code
private void createPatternsTable(Group group, Composite parent) {
    TableLayoutComposite tableLayouter = new TableLayoutComposite(parent, SWT.NONE);
    // severity
    tableLayouter.addColumnData(new ColumnWeightData(10, true));
    // pattern
    tableLayouter.addColumnData(new ColumnWeightData(40, true));
    // file
    tableLayouter.addColumnData(new ColumnWeightData(10, true));
    // line
    tableLayouter.addColumnData(new ColumnWeightData(10, true));
    // description
    tableLayouter.addColumnData(new ColumnWeightData(15, true));
    // eat line
    tableLayouter.addColumnData(new ColumnWeightData(10, true));
    int style = SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER;
    if (fEditable) {
        style = style | SWT.FULL_SELECTION;
    }
    fTable = new Table(tableLayouter, style);
    fTable.setHeaderVisible(true);
    fTable.setLinesVisible(true);
    fTable.setEnabled(fEditable);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    gridData.heightHint = SWTUtil.getTableHeightHint(fTable, 10);
    gridData.widthHint = new PixelConverter(group).convertWidthInCharsToPixels(100);
    tableLayouter.setLayoutData(gridData);
    fTable.setLayout(new TableLayout());
    fTable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updateButtons();
        }
    });
    fTableViewer = new TableViewer(fTable);
    fTableViewer.setUseHashlookup(true);
    fTableViewer.setContentProvider(new ArrayContentProvider());
    createSeverityColumn();
    createPatternColumn();
    createFileColumn();
    createLineColumn();
    createDescriptionColumn();
    createEatLineColumn();
    initializeTable();
}
Example 13
Project: earthsci-master  File: WorkbenchPage.java View source code
public static boolean saveAll(List dirtyParts, final boolean confirm, final boolean closing, boolean addNonPartSources, final IRunnableContext runnableContext, final IShellProvider shellProvider) {
    // clone the input list
    dirtyParts = new ArrayList(dirtyParts);
    if (closing) {
        // need to be saved when closed, see bug 272070
        for (Iterator it = dirtyParts.iterator(); it.hasNext(); ) {
            ISaveablePart saveablePart = (ISaveablePart) it.next();
            if (!saveablePart.isSaveOnCloseNeeded()) {
                it.remove();
            }
        }
    }
    List modelsToSave;
    if (confirm) {
        boolean saveable2Processed = false;
        // Process all parts that implement ISaveablePart2.
        // These parts are removed from the list after saving
        // them. We then need to restore the workbench to
        // its previous state, for now this is just last
        // active perspective.
        // Note that the given parts may come from multiple
        // windows, pages and perspectives.
        ListIterator listIterator = dirtyParts.listIterator();
        WorkbenchPage currentPage = null;
        Perspective currentPageOriginalPerspective = null;
        while (listIterator.hasNext()) {
            IWorkbenchPart part = (IWorkbenchPart) listIterator.next();
            if (part instanceof ISaveablePart2) {
                WorkbenchPage page = (WorkbenchPage) part.getSite().getPage();
                if (!Util.equals(currentPage, page)) {
                    if (currentPage != null && currentPageOriginalPerspective != null) {
                        if (!currentPageOriginalPerspective.equals(currentPage.getActivePerspective())) {
                            currentPage.setPerspective(currentPageOriginalPerspective.getDesc());
                        }
                    }
                    currentPage = page;
                    currentPageOriginalPerspective = page.getActivePerspective();
                }
                if (confirm) {
                    // if (part instanceof IViewPart) {
                    // Perspective perspective = page
                    // .getFirstPerspectiveWithView((IViewPart) part);
                    // if (perspective != null) {
                    // page.setPerspective(perspective.getDesc());
                    // }
                    // }
                    // // show the window containing the page?
                    // IWorkbenchWindow partsWindow =
                    // page.getWorkbenchWindow();
                    // if (partsWindow !=
                    // partsWindow.getWorkbench().getActiveWorkbenchWindow())
                    // {
                    // Shell shell = partsWindow.getShell();
                    // if (shell.getMinimized()) {
                    // shell.setMinimized(false);
                    // }
                    // shell.setActive();
                    // }
                    page.bringToTop(part);
                }
                // try to save the part
                int choice = SaveableHelper.savePart((ISaveablePart2) part, page.getWorkbenchWindow(), confirm);
                if (choice == ISaveablePart2.CANCEL) {
                    // be an unexpected switch from the current state.
                    return false;
                } else if (choice != ISaveablePart2.DEFAULT) {
                    saveable2Processed = true;
                    listIterator.remove();
                }
            }
        }
        // try to restore the workbench to its previous state
        if (currentPage != null && currentPageOriginalPerspective != null) {
            if (!currentPageOriginalPerspective.equals(currentPage.getActivePerspective())) {
                currentPage.setPerspective(currentPageOriginalPerspective.getDesc());
            }
        }
        // saved, remove them from the list presented to the user.
        if (saveable2Processed) {
            listIterator = dirtyParts.listIterator();
            while (listIterator.hasNext()) {
                ISaveablePart part = (ISaveablePart) listIterator.next();
                if (!part.isDirty()) {
                    listIterator.remove();
                }
            }
        }
        modelsToSave = convertToSaveables(dirtyParts, closing, addNonPartSources);
        // If nothing to save, return.
        if (modelsToSave.isEmpty()) {
            return true;
        }
        boolean canceled = SaveableHelper.waitForBackgroundSaveJobs(modelsToSave);
        if (canceled) {
            return false;
        }
        // Use a simpler dialog if there's only one
        if (modelsToSave.size() == 1) {
            Saveable model = (Saveable) modelsToSave.get(0);
            String message = NLS.bind(WorkbenchMessages.EditorManager_saveChangesQuestion, model.getName());
            // Show a dialog.
            String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };
            MessageDialog d = new MessageDialog(shellProvider.getShell(), WorkbenchMessages.Save_Resource, null, message, MessageDialog.QUESTION, buttons, 0) {

                protected int getShellStyle() {
                    return super.getShellStyle() | SWT.SHEET;
                }
            };
            int choice = SaveableHelper.testGetAutomatedResponse();
            if (SaveableHelper.testGetAutomatedResponse() == SaveableHelper.USER_RESPONSE) {
                choice = d.open();
            }
            // above.
            switch(choice) {
                case ISaveablePart2// yes
                .YES:
                    break;
                case ISaveablePart2// no
                .NO:
                    return true;
                default:
                case // cancel
                ISaveablePart2.CANCEL:
                    return false;
            }
        } else {
            ListSelectionDialog dlg = new ListSelectionDialog(shellProvider.getShell(), modelsToSave, new ArrayContentProvider(), new WorkbenchPartLabelProvider(), WorkbenchMessages.EditorManager_saveResourcesMessage) {

                protected int getShellStyle() {
                    return super.getShellStyle() | SWT.SHEET;
                }
            };
            dlg.setInitialSelections(modelsToSave.toArray());
            dlg.setTitle(WorkbenchMessages.EditorManager_saveResourcesTitle);
            // this "if" statement aids in testing.
            if (SaveableHelper.testGetAutomatedResponse() == SaveableHelper.USER_RESPONSE) {
                int result = dlg.open();
                // Just return false to prevent the operation continuing
                if (result == IDialogConstants.CANCEL_ID) {
                    return false;
                }
                modelsToSave = Arrays.asList(dlg.getResult());
            }
        }
    } else {
        modelsToSave = convertToSaveables(dirtyParts, closing, addNonPartSources);
    }
    // If the editor list is empty return.
    if (modelsToSave.isEmpty()) {
        return true;
    }
    // Create save block.
    final List finalModels = modelsToSave;
    IRunnableWithProgress progressOp = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) {
            IProgressMonitor monitorWrap = new EventLoopProgressMonitor(monitor);
            monitorWrap.beginTask(WorkbenchMessages.Saving_Modifications, finalModels.size());
            for (Iterator i = finalModels.iterator(); i.hasNext(); ) {
                Saveable model = (Saveable) i.next();
                // saving another
                if (!model.isDirty()) {
                    monitor.worked(1);
                    continue;
                }
                SaveableHelper.doSaveModel(model, new SubProgressMonitor(monitorWrap, 1), shellProvider, closing || confirm);
                if (monitorWrap.isCanceled()) {
                    break;
                }
            }
            monitorWrap.done();
        }
    };
    // Do the save.
    return SaveableHelper.runProgressMonitorOperation(WorkbenchMessages.Save_All, progressOp, runnableContext, shellProvider);
}
Example 14
Project: teiid-designer-master  File: CreateDataSourceWizard.java View source code
@Override
protected Control createDialogArea(final Composite parent) {
    setTitle(TITLE);
    setTitleImage(UiPlugin.getDefault().getImage(Images.IMPORT_TEIID_METADATA));
    setMessage("Create and Deploy a Data Source");
    profileWorker = new ConnectionProfileWorker(this.getShell(), null, this);
    // ===========>>>> Create page composite
    final Composite mainPanel = (Composite) super.createDialogArea(parent);
    //        mainPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
    ((GridLayout) mainPanel.getLayout()).marginTop = 5;
    ((GridLayout) mainPanel.getLayout()).marginBottom = 10;
    ((GridLayout) mainPanel.getLayout()).verticalSpacing = 8;
    //$NON-NLS-1$
    WidgetFactory.createLabel(mainPanel, getString("teiidServer.label"));
    if (StringUtilities.isEmpty(teiidServer.getCustomLabel())) {
        WidgetFactory.createLabel(mainPanel, GridData.FILL_HORIZONTAL, 1, teiidServer.getUrl());
    } else {
        WidgetFactory.createLabel(mainPanel, GridData.FILL_HORIZONTAL, 1, teiidServer.getCustomLabel());
    }
    //$NON-NLS-1$
    WidgetFactory.createLabel(mainPanel, getString("name.label"));
    dataSourceName = getDefaultDataSourceName();
    if (selectedModelResource != null) {
        ConnectionInfoHelper helper = new ConnectionInfoHelper();
        dataSourceName = helper.getJndiProperty(selectedModelResource);
        // Strip off "java:/"
        String nameOnly = StringConstants.EMPTY_STRING;
        if (!StringUtilities.isEmpty(dataSourceName)) {
            nameOnly = dataSourceName;
            if (dataSourceName.startsWith(JNDI_PREFIX)) {
                nameOnly = dataSourceName.substring(6);
            }
            dataSourceName = nameOnly;
        }
        if (dataSourceName == null) {
            dataSourceName = ModelUtil.getName(selectedModelResource);
        }
    }
    this.dataSourceNameText = WidgetFactory.createTextField(mainPanel, GridData.FILL_HORIZONTAL, 1, dataSourceName);
    this.dataSourceNameText.setForeground(GlobalUiColorManager.EMPHASIS_COLOR);
    this.dataSourceNameText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            dataSourceName = dataSourceNameText.getText();
            validateInputs();
        }
    });
    {
        Text helpText = new Text(mainPanel, SWT.WRAP | SWT.READ_ONLY);
        helpText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
        helpText.setForeground(GlobalUiColorManager.NOTE_COLOR);
        helpText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
        ((GridData) helpText.getLayoutData()).horizontalSpan = 2;
        //$NON-NLS-1$
        helpText.setText(getString("dataSourceNameHelp.txt"));
    }
    // ===========>>>> Create Connections Group
    final Group connectionSourceGroup = WidgetFactory.createGroup(mainPanel, getString("connectionSourceGroup.label"), GridData.FILL_HORIZONTAL, 2, //$NON-NLS-1$
    4);
    // ===========>>>> Models selection
    boolean useModelRes = selectedModelResource != null;
    useModelCheckBox = WidgetFactory.createRadioButton(connectionSourceGroup, getString("useModelInfo.label"), 0, 4, //$NON-NLS-1$
    useModelRes);
    useModelCheckBox.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent event) {
            if (hasModelResources) {
                resetComboBoxes();
                useConnectionProfileCheckBox.setSelection(!useModelCheckBox.getSelection());
                handleModelResourceSelection();
                setConnectionProperties();
                propsViewer.refresh();
                validateInputs();
            }
        }
    });
    //$NON-NLS-1$
    WidgetFactory.createLabel(connectionSourceGroup, getString("model.label"));
    ArrayList<ModelResource> modelsList = new ArrayList<ModelResource>(relationalModelsMap.values());
    ILabelProvider modelsLabelProvider = new LabelProvider() {

        @Override
        public String getText(final Object source) {
            return ModelUtil.getName((ModelResource) source);
        }

        @Override
        public Image getImage(final Object source) {
            return ModelIdentifier.getModelImage((ModelResource) source);
        }
    };
    if (useModelRes) {
        this.modelsCombo = WidgetFactory.createCombo(connectionSourceGroup, SWT.READ_ONLY, GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_CENTER, modelsList, selectedModelResource, modelsLabelProvider, true);
    } else {
        this.modelsCombo = WidgetFactory.createCombo(connectionSourceGroup, SWT.READ_ONLY, GridData.FILL_HORIZONTAL, modelsList, modelsLabelProvider, true);
    }
    this.modelsCombo.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent event) {
            if (useModelCheckBox.getSelection()) {
                handleModelResourceSelection();
            }
        }
    });
    this.modelsCombo.setVisibleItemCount(10);
    GridData modelsComboGD = new GridData(GridData.FILL_BOTH);
    modelsComboGD.horizontalSpan = 3;
    this.modelsCombo.setLayoutData(modelsComboGD);
    // ===========>>>> Connection Profiles
    useConnectionProfileCheckBox = //$NON-NLS-1$
    WidgetFactory.createRadioButton(//$NON-NLS-1$
    connectionSourceGroup, //$NON-NLS-1$
    getString("useProfileInfo.label"), 0, 4, !useModelRes);
    useConnectionProfileCheckBox.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent event) {
            resetComboBoxes();
            useModelCheckBox.setSelection(!useConnectionProfileCheckBox.getSelection());
            if (useConnectionProfileCheckBox.getSelection()) {
                handleConnectionProfileSelected();
            }
            propsViewer.refresh();
            validateInputs();
        }
    });
    //$NON-NLS-1$
    WidgetFactory.createLabel(connectionSourceGroup, getString("connectionProfile.label"));
    profileLabelProvider = new LabelProvider() {

        @Override
        public String getText(final Object source) {
            return ((IConnectionProfile) source).getName();
        }
    };
    this.connectionProfilesCombo = WidgetFactory.createCombo(connectionSourceGroup, SWT.READ_ONLY, GridData.FILL_HORIZONTAL, profileWorker.getProfiles(), profileLabelProvider, true);
    this.connectionProfilesCombo.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // Need to sync the worker with the current profile
            handleConnectionProfileSelected();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    this.connectionProfilesCombo.setVisibleItemCount(10);
    newCPButton = WidgetFactory.createButton(connectionSourceGroup, NEW_BUTTON);
    newCPButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent event) {
            profileWorker.create();
        }
    });
    editCPButton = WidgetFactory.createButton(connectionSourceGroup, EDIT_BUTTON);
    editCPButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent event) {
            profileWorker.edit();
        }
    });
    if (useModelRes) {
        this.useConnectionProfileCheckBox.setSelection(false);
        this.connectionProfilesCombo.setEnabled(false);
        this.modelsCombo.setEnabled(true);
    } else {
        this.useConnectionProfileCheckBox.setSelection(true);
        this.connectionProfilesCombo.setEnabled(true);
        this.modelsCombo.setEnabled(false);
    }
    // ===========>>>>
    //$NON-NLS-1$
    Group propsGroup = WidgetFactory.createGroup(mainPanel, getString("connectionProperties.label"), GridData.FILL_BOTH, 2, 2);
    final GridData propertiesGridData = new GridData(GridData.FILL_BOTH);
    propertiesGridData.horizontalSpan = 2;
    propertiesGridData.heightHint = 180;
    propertiesGridData.minimumHeight = 180;
    propertiesGridData.grabExcessVerticalSpace = true;
    propsGroup.setLayoutData(propertiesGridData);
    int tableStyle = SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION;
    propsViewer = new TableViewer(propsGroup, tableStyle);
    Table table = propsViewer.getTable();
    table.setForeground(GlobalUiColorManager.EMPHASIS_COLOR);
    // SWT.FILL, SWT.FILL, true, true);
    final GridData gridData = new GridData(GridData.FILL_BOTH);
    gridData.grabExcessHorizontalSpace = true;
    table.setLayoutData(gridData);
    /*** Tree table specific code starts ***/
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    TableColumn column1 = new TableColumn(table, SWT.NONE);
    //$NON-NLS-1$
    column1.setText(getString("property.name.label"));
    column1.setWidth(200);
    TableColumn column2 = new TableColumn(table, SWT.NONE);
    //$NON-NLS-1$
    column2.setText(getString("property.value.label"));
    column2.setWidth(50);
    table.pack();
    GridData columnData = new GridData(GridData.FILL_BOTH);
    table.setLayoutData(columnData);
    // table.setLayout(layout);
    propertiesContentProvider = new TableContentProvider();
    propsViewer.setContentProvider(new ArrayContentProvider());
    propsViewer.setLabelProvider(propertiesContentProvider);
    if (!hasModelResources) {
        useModelCheckBox.setEnabled(false);
        modelsCombo.setEnabled(false);
    }
    if (profileWorker.getProfiles().isEmpty()) {
        useConnectionProfileCheckBox.setEnabled(false);
        connectionProfilesCombo.setEnabled(false);
    } else {
        this.connectionProfilesCombo.select(0);
    }
    sizeScrolledPanel();
    resetComboBoxes();
    return mainPanel;
}
Example 15
Project: streamline-master  File: DataViewer.java View source code
private void createViewer(Composite parent, IPersistentMap<String, DataType<?>> inData) {
    viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
    createColumns(parent, viewer, inData);
    final Table table = viewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    viewer.setContentProvider(ArrayContentProvider.getInstance());
// Get the content for the viewer, setInput will call getElements in the
// contentProvider
//	    viewer.setInput(ModelProvider.INSTANCE.getPersons());
// Make the selection available to other views
// Set the sorter for the table
// Layout the viewer
//	    GridData gridData = new GridData();
//	    gridData.verticalAlignment = GridData.FILL;
//	    gridData.horizontalSpan = 2;
//	    gridData.grabExcessHorizontalSpace = true;
//	    gridData.grabExcessVerticalSpace = true;
//	    gridData.horizontalAlignment = GridData.FILL;
//	    viewer.getControl().setLayoutData(gridData);
}
Example 16
Project: Eclipse-Postfix-Code-Completion-master  File: PullUpMemberPage.java View source code
private void createMemberTable(final Composite parent) {
    final TableLayoutComposite layouter = new TableLayoutComposite(parent, SWT.NONE);
    layouter.addColumnData(new ColumnWeightData(60, true));
    layouter.addColumnData(new ColumnWeightData(40, true));
    final Table table = new Table(layouter, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION | SWT.CHECK);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    final GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = SWTUtil.getTableHeightHint(table, getTableRowCount());
    gd.widthHint = convertWidthInCharsToPixels(30);
    layouter.setLayoutData(gd);
    final TableLayout tableLayout = new TableLayout();
    table.setLayout(tableLayout);
    final TableColumn column0 = new TableColumn(table, SWT.NONE);
    column0.setText(RefactoringMessages.PullUpInputPage1_Member);
    final TableColumn column1 = new TableColumn(table, SWT.NONE);
    column1.setText(RefactoringMessages.PullUpInputPage1_Action);
    fTableViewer = new PullPushCheckboxTableViewer(table);
    fTableViewer.setUseHashlookup(true);
    fTableViewer.setContentProvider(new ArrayContentProvider());
    fTableViewer.setLabelProvider(new MemberActionInfoLabelProvider());
    fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(final SelectionChangedEvent event) {
            updateButtonEnablement(event.getSelection());
        }
    });
    fTableViewer.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(final CheckStateChangedEvent event) {
            final boolean checked = event.getChecked();
            final MemberActionInfo info = (MemberActionInfo) event.getElement();
            if (checked)
                info.setAction(PULL_UP_ACTION);
            else
                info.setAction(MemberActionInfo.NO_ACTION);
            updateWizardPage(null, true);
        }
    });
    fTableViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(final DoubleClickEvent event) {
            editSelectedMembers();
        }
    });
    setTableInput();
    checkPullUp(fProcessor.getMembersToMove(), false);
    setupCellEditors(table);
}
Example 17
Project: tmdm-studio-se-master  File: DataClusterComposite.java View source code
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());
}
Example 18
Project: aws-toolkit-eclipse-master  File: AwsAccountPreferencePageTab.java View source code
/**
     * Creates the account selection section.
     */
private Composite createAccountSelector(final Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    composite.setLayout(new GridLayout(4, false));
    new Label(composite, SWT.READ_ONLY).setText("Default Profile: ");
    accountSelector = new ComboViewer(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
    accountSelector.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    // Use a List of AccountInfo objects as the data input for the combo
    // viewer
    accountSelector.setContentProvider(ArrayContentProvider.getInstance());
    accountSelector.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof AccountInfo) {
                AccountInfo account = (AccountInfo) element;
                if (account.isDirty()) {
                    return "*" + account.getAccountName();
                } else {
                    return account.getAccountName();
                }
            }
            return super.getText(element);
        }
    });
    AccountInfo currentRegionAccount = accountInfoByIdentifier.get(currentRegionAccountId);
    // the data in the preference store is not yet updated.
    if (currentRegionAccount == null) {
        currentRegionAccount = accountInfoByIdentifier.values().iterator().next();
        currentRegionAccountId = currentRegionAccount.getInternalAccountId();
    }
    final List<AccountInfo> allAccounts = new LinkedList<AccountInfo>(accountInfoByIdentifier.values());
    setUpAccountSelectorItems(allAccounts, currentRegionAccount);
    // Add selection listener to the account selector, so that all the
    // account info editors are notified of the newly selected AccountInfo
    // object.
    accountSelector.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            Object selectedObject = selection.getFirstElement();
            if (selectedObject instanceof AccountInfo) {
                AccountInfo accountInfo = (AccountInfo) selectedObject;
                accountChanged(accountInfo);
            }
        }
    });
    final Button addNewAccount = new Button(composite, SWT.PUSH);
    addNewAccount.setText("Add profile");
    deleteAccount = new Button(composite, SWT.PUSH);
    deleteAccount.setText("Remove profile");
    deleteAccount.setEnabled(allAccounts.size() > 1);
    defaultAccountExplanationLabel = new Label(composite, SWT.WRAP);
    defaultAccountExplanationLabel.setText(getDefaultAccountExplanationText());
    parentPrefPage.setItalicFont(defaultAccountExplanationLabel);
    GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false);
    layoutData.horizontalSpan = 4;
    layoutData.widthHint = 200;
    defaultAccountExplanationLabel.setLayoutData(layoutData);
    addNewAccount.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String newAccountId = UUID.randomUUID().toString();
            AccountInfo newAccountInfo = createNewProfileAccountInfo(newAccountId);
            String newAccountName = region == null ? "New Profile" : "New " + region.getName() + " Profile";
            // this will mark the AccountInfo object dirty
            newAccountInfo.setAccountName(newAccountName);
            accountInfoByIdentifier.put(newAccountId, newAccountInfo);
            setUpAccountSelectorItems(accountInfoByIdentifier.values(), newAccountInfo);
            for (AwsAccountPreferencePageTab tab : parentPrefPage.getAllAccountPreferencePageTabs()) {
                if (tab != AwsAccountPreferencePageTab.this) {
                    tab.refreshAccountSelectorItems();
                }
            }
            parentPrefPage.updatePageValidationOfAllTabs();
        }
    });
    deleteAccount.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            accountInfoToBeDeleted.add(accountInfoByIdentifier.get(currentRegionAccountId));
            accountInfoByIdentifier.remove(currentRegionAccountId);
            // AccountInfo object
            if (accountInfoByIdentifier.isEmpty()) {
                String newAccountId = UUID.randomUUID().toString();
                AccountInfo newAccountInfo = createNewProfileAccountInfo(newAccountId);
                // Account name : default-region-id
                newAccountInfo.setAccountName(getRegionAccountDefaultName());
                accountInfoByIdentifier.put(newAccountId, newAccountInfo);
            }
            // Use the first AccountInfo as the next selected account
            AccountInfo nextDefaultAccount = accountInfoByIdentifier.values().iterator().next();
            setUpAccountSelectorItems(accountInfoByIdentifier.values(), nextDefaultAccount);
            for (AwsAccountPreferencePageTab tab : parentPrefPage.getAllAccountPreferencePageTabs()) {
                if (tab != AwsAccountPreferencePageTab.this) {
                    tab.refreshAccountSelectorItems();
                }
            }
            parentPrefPage.updatePageValidationOfAllTabs();
        }
    });
    accountSelector.getCombo().addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent arg0) {
            if (accountSelector.getCombo().getItemCount() > 1) {
                deleteAccount.setEnabled(true);
            } else {
                deleteAccount.setEnabled(false);
            }
        }
    });
    return composite;
}
Example 19
Project: CodingSpectator-master  File: AnnotationsConfigurationBlock.java View source code
/*
	 * @see org.eclipse.ui.internal.editors.text.IPreferenceConfigurationBlock#createControl(org.eclipse.swt.widgets.Composite)
	 */
public Control createControl(Composite parent) {
    PixelConverter pixelConverter = new PixelConverter(parent);
    Composite composite = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    Label label = new Label(composite, SWT.LEFT);
    label.setText(TextEditorMessages.AnnotationsConfigurationBlock_annotationPresentationOptions);
    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gd.horizontalSpan = 2;
    label.setLayoutData(gd);
    Composite editorComposite = new Composite(composite, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    editorComposite.setLayout(layout);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL);
    gd.horizontalSpan = 2;
    editorComposite.setLayoutData(gd);
    fAnnotationTypeViewer = new TableViewer(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    fAnnotationTypeViewer.setLabelProvider(new ItemLabelProvider());
    fAnnotationTypeViewer.setContentProvider(new ItemContentProvider());
    gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
    gd.heightHint = pixelConverter.convertHeightInCharsToPixels(20);
    fAnnotationTypeViewer.getControl().setLayoutData(gd);
    Composite optionsComposite = new Composite(editorComposite, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 2;
    optionsComposite.setLayout(layout);
    optionsComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    label = new Label(optionsComposite, SWT.LEFT);
    label.setText(TextEditorMessages.AnnotationsConfigurationBlock_labels_showIn);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalSpan = 2;
    label.setLayoutData(gd);
    fShowInVerticalRulerCheckBox = new Button(optionsComposite, SWT.CHECK);
    fShowInVerticalRulerCheckBox.setText(TextEditorMessages.AnnotationsConfigurationBlock_showInVerticalRuler);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalSpan = 2;
    gd.horizontalIndent = 20;
    fShowInVerticalRulerCheckBox.setLayoutData(gd);
    fShowInOverviewRulerCheckBox = new Button(optionsComposite, SWT.CHECK);
    fShowInOverviewRulerCheckBox.setText(TextEditorMessages.AnnotationsConfigurationBlock_showInOverviewRuler);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalSpan = 2;
    gd.horizontalIndent = 20;
    fShowInOverviewRulerCheckBox.setLayoutData(gd);
    fShowInTextCheckBox = new Button(optionsComposite, SWT.CHECK);
    fShowInTextCheckBox.setText(TextEditorMessages.AnnotationsConfigurationBlock_showInText);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalIndent = 20;
    fShowInTextCheckBox.setLayoutData(gd);
    fDecorationViewer = new ComboViewer(optionsComposite, SWT.READ_ONLY);
    fDecorationViewer.setContentProvider(new ArrayContentProvider());
    fDecorationViewer.setLabelProvider(new ArrayLabelProvider());
    fDecorationViewer.setComparator(new ViewerComparator(Collator.getInstance()));
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    fDecorationViewer.getControl().setLayoutData(gd);
    fDecorationViewer.setInput(new Object[] { HIGHLIGHT, SQUIGGLES, BOX, DASHED_BOX, UNDERLINE, PROBLEM_UNDERLINE, IBEAM });
    fDecorationViewer.getCombo().setVisibleItemCount(fDecorationViewer.getCombo().getItemCount());
    label = new Label(optionsComposite, SWT.LEFT);
    label.setText(TextEditorMessages.AnnotationsConfigurationBlock_color);
    gd = new GridData();
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalIndent = 20;
    label.setLayoutData(gd);
    fAnnotationForegroundColorEditor = new ColorSelector(optionsComposite);
    Button foregroundColorButton = fAnnotationForegroundColorEditor.getButton();
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    foregroundColorButton.setLayoutData(gd);
    addFiller(optionsComposite);
    fIsNextPreviousTargetCheckBox = new Button(optionsComposite, SWT.CHECK);
    fIsNextPreviousTargetCheckBox.setText(TextEditorMessages.AnnotationsConfigurationBlock_isNavigationTarget);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalSpan = 2;
    gd.horizontalIndent = 0;
    fIsNextPreviousTargetCheckBox.setLayoutData(gd);
    fAnnotationTypeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            handleAnnotationListSelection();
        }
    });
    fShowInTextCheckBox.addSelectionListener(new SelectionListener() {

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

        public void widgetSelected(SelectionEvent e) {
            ListItem item = getSelectedItem();
            final boolean value = fShowInTextCheckBox.getSelection();
            if (value) {
                // enable whatever is in the combo
                String[] decoration = (String[]) ((IStructuredSelection) fDecorationViewer.getSelection()).getFirstElement();
                if (HIGHLIGHT.equals(decoration))
                    fStore.setValue(item.highlightKey, true);
                else
                    fStore.setValue(item.textKey, true);
            } else {
                // disable both
                if (item.textKey != null)
                    fStore.setValue(item.textKey, false);
                if (item.highlightKey != null)
                    fStore.setValue(item.highlightKey, false);
            }
            fStore.setValue(item.textKey, value);
            updateDecorationViewer(item, false);
            fAnnotationTypeViewer.refresh(item);
        }
    });
    fShowInOverviewRulerCheckBox.addSelectionListener(new SelectionListener() {

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

        public void widgetSelected(SelectionEvent e) {
            ListItem item = getSelectedItem();
            fStore.setValue(item.overviewRulerKey, fShowInOverviewRulerCheckBox.getSelection());
            fAnnotationTypeViewer.refresh(item);
        }
    });
    fShowInVerticalRulerCheckBox.addSelectionListener(new SelectionListener() {

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

        public void widgetSelected(SelectionEvent e) {
            ListItem item = getSelectedItem();
            fStore.setValue(item.verticalRulerKey, fShowInVerticalRulerCheckBox.getSelection());
            fAnnotationTypeViewer.refresh(item);
        }
    });
    fIsNextPreviousTargetCheckBox.addSelectionListener(new SelectionListener() {

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

        public void widgetSelected(SelectionEvent e) {
            ListItem item = getSelectedItem();
            fStore.setValue(item.isNextPreviousNavigationKey, fIsNextPreviousTargetCheckBox.getSelection());
            fAnnotationTypeViewer.refresh(item);
        }
    });
    foregroundColorButton.addSelectionListener(new SelectionListener() {

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

        public void widgetSelected(SelectionEvent e) {
            ListItem item = getSelectedItem();
            PreferenceConverter.setValue(fStore, item.colorKey, fAnnotationForegroundColorEditor.getColorValue());
            fAnnotationTypeViewer.refresh(item);
        }
    });
    fDecorationViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        /*
			 * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
			 */
        public void selectionChanged(SelectionChangedEvent event) {
            String[] decoration = (String[]) ((IStructuredSelection) fDecorationViewer.getSelection()).getFirstElement();
            ListItem item = getSelectedItem();
            if (fShowInTextCheckBox.getSelection()) {
                if (HIGHLIGHT.equals(decoration)) {
                    fStore.setValue(item.highlightKey, true);
                    if (item.textKey != null) {
                        fStore.setValue(item.textKey, false);
                        if (item.textStyleKey != null)
                            fStore.setValue(item.textStyleKey, AnnotationPreference.STYLE_NONE);
                    }
                } else {
                    if (item.highlightKey != null)
                        fStore.setValue(item.highlightKey, false);
                    if (item.textKey != null) {
                        fStore.setValue(item.textKey, true);
                        if (item.textStyleKey != null)
                            fStore.setValue(item.textStyleKey, decoration[1]);
                    }
                }
            }
            fAnnotationTypeViewer.refresh(item);
        }
    });
    composite.layout();
    return composite;
}
Example 20
Project: turmeric-eclipse-master  File: EnumTypeWizardDetailsPage.java View source code
/**
	 * Creates the viewer.
	 *
	 * @param container the container
	 */
public void createViewer(Composite container) {
    int style = SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION;
    enumViewer = new TableButtonPanelViewer(container, style, colDef, true) {

        @Override
        protected void addButtonSelected(SelectionEvent event) {
            super.addButtonSelected(event);
            EnumTableModel model = new EnumTableModel();
            model.setEnumValue(COL_ENUM_VALUE);
            model.setEnumDesc(COL_ENUM_DESC);
            if (enumHolder.add(model)) {
                enumViewer.getRemoveButton().setEnabled(true);
                enumViewer.refresh();
                dialogChanged();
            }
        }

        @Override
        protected void downButtonSelected(SelectionEvent event) {
            super.downButtonSelected(event);
            final Object obj = getSelectedObject();
            if (obj instanceof EnumTableModel) {
                ListUtil.moveOnePositionDown(enumHolder, (EnumTableModel) obj);
                enumViewer.refresh();
            }
        }

        @Override
        protected void removeButtonSelected(SelectionEvent event) {
            super.removeButtonSelected(event);
            final Object obj = getSelectedObject();
            if (obj instanceof EnumTableModel && enumHolder.remove(obj)) {
                enumViewer.getRemoveButton().setEnabled(false);
                enumViewer.refresh();
                dialogChanged();
            }
        }

        @Override
        protected void upButtonSelected(SelectionEvent event) {
            super.upButtonSelected(event);
            final Object obj = getSelectedObject();
            if (obj instanceof EnumTableModel) {
                ListUtil.moveOnePositionUp(enumHolder, (EnumTableModel) obj);
                enumViewer.refresh();
            }
        }

        @Override
        protected void viewerSelectionChanged(SelectionChangedEvent event) {
            super.viewerSelectionChanged(event);
            dialogChanged();
        }
    };
    enumViewer.setContentProvider(new ArrayContentProvider());
    enumViewer.setLabelProvider(new EnumTableLabelProvider());
    enumViewer.setColumnProperties(colProperties);
    enumViewer.setInput(enumHolder);
    enumViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
}
Example 21
Project: erlide-master  File: CustomOutlineFiltersDialog.java View source code
private void createCheckBoxList(final Composite parent) {
    // Filler
    new Label(parent, SWT.NONE);
    Label info = new Label(parent, SWT.LEFT);
    info.setText("S&elect the elements to exclude from the view:");
    fCheckBoxList = CheckboxTableViewer.newCheckList(parent, SWT.BORDER);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.heightHint = fCheckBoxList.getTable().getItemHeight() * 10;
    fCheckBoxList.getTable().setLayoutData(data);
    fCheckBoxList.setLabelProvider(createLabelPrivder());
    fCheckBoxList.setContentProvider(new ArrayContentProvider());
    Collections.sort(fBuiltInFilters);
    fCheckBoxList.setInput(fBuiltInFilters);
    setInitialSelections(getEnabledFilterDescriptors().toArray());
    final List<?> initialSelection = getInitialElementSelections();
    if (initialSelection != null && !initialSelection.isEmpty()) {
        checkInitialSelections();
    }
    // Description
    info = new Label(parent, SWT.LEFT);
    info.setText("Filter description:");
    final Text description = new Text(parent, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = convertHeightInCharsToPixels(3);
    description.setLayoutData(data);
    fCheckBoxList.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            final ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                final Object selectedElement = ((IStructuredSelection) selection).getFirstElement();
                if (selectedElement instanceof FilterDescriptor) {
                    description.setText(((FilterDescriptor) selectedElement).getDescription());
                }
            }
        }
    });
    fCheckBoxList.addCheckStateListener(new ICheckStateListener() {

        /*
             * @see org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged
             * (org.eclipse.jface.viewers.CheckStateChangedEvent)
             */
        @Override
        public void checkStateChanged(final CheckStateChangedEvent event) {
            final Object element = event.getElement();
            if (element instanceof FilterDescriptor) {
                // renew if already touched
                if (fFilterDescriptorChangeHistory.contains(element)) {
                    fFilterDescriptorChangeHistory.remove(element);
                }
                fFilterDescriptorChangeHistory.push((FilterDescriptor) element);
            }
        }
    });
    addSelectionButtons(parent);
}
Example 22
Project: cdo-master  File: AbstractDetailsPage.java View source code
protected ComboViewer combo(Composite parent, FormToolkit toolkit, String label, EAttribute attribute) {
    toolkit.createLabel(parent, label);
    ComboViewer result = new ComboViewer(createDecorationComposite(parent, toolkit, layoutData(parent, SWT.LEFT, false, 1)), SWT.READ_ONLY | SWT.DROP_DOWN);
    result.setLabelProvider(new AdapterFactoryLabelProvider(getAdapterFactory()));
    result.setContentProvider(new ArrayContentProvider());
    result.setInput(attribute.getEAttributeType().getInstanceClass().getEnumConstants());
    getContext().bindValue(ViewersObservables.observeSingleSelection(result), EMFEditObservables.observeDetailValue(getRealm(), getEditingDomain(), getValue(), attribute));
    getContext().bindValue(WidgetProperties.enabled().observe(result.getControl()), getValue(), null, ObjectWritableConverter.createUpdateValueStrategy(attribute));
    addRevertDecoration(result.getControl(), attribute);
    return result;
}
Example 23
Project: arquillian-eclipse-master  File: ArquillianLaunchConfigurationTab.java View source code
private void createTestLoaderGroup(Composite comp) {
    Label loaderLabel = new Label(comp, SWT.NONE);
    loaderLabel.setText(JUnitMessages.JUnitLaunchConfigurationTab_Test_Loader);
    GridData gd = new GridData();
    gd.horizontalIndent = 0;
    loaderLabel.setLayoutData(gd);
    fTestLoaderViewer = new ComboViewer(comp, SWT.DROP_DOWN | SWT.READ_ONLY);
    fTestLoaderViewer.getCombo().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    List<ITestKind> items = new ArrayList<ITestKind>();
    items.add(TestKindRegistry.getDefault().getKind(TestKindRegistry.JUNIT4_TEST_KIND_ID));
    fTestLoaderViewer.setContentProvider(new ArrayContentProvider());
    fTestLoaderViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((TestKind) element).getDisplayName();
        }
    });
    fTestLoaderViewer.setInput(items);
    fTestLoaderViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            validatePage();
            updateLaunchConfigurationDialog();
        }
    });
}
Example 24
Project: platform_tools_motodev-master  File: AbstractLayoutItemsDialog.java View source code
/**
     * Create GUI items for GUI Items selection.
     * @param parent
     */
private void createTableArea(Composite parent) {
    Composite tableArea = new Composite(parent, SWT.NONE);
    tableArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    tableArea.setLayout(new GridLayout(2, false));
    Label tableLabel = new Label(tableArea, SWT.NONE);
    tableLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 2, 1));
    tableLabel.setText(CodeUtilsNLS.ChooseLayoutItemsDialog_GUIItems);
    viewer = new TableViewer(tableArea, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER | SWT.CHECK);
    viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    Composite buttonsComposite = new Composite(tableArea, SWT.NONE);
    buttonsComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, true, 1, 1));
    RowLayout buttonsLayout = new RowLayout(SWT.VERTICAL);
    buttonsLayout.pack = false;
    buttonsComposite.setLayout(buttonsLayout);
    selectAllButton = new Button(buttonsComposite, SWT.PUSH);
    selectAllButton.setText(CodeUtilsNLS.UI_SelectAll);
    selectAllButton.setLayoutData(new RowData());
    selectAllButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            checkAllItems(true);
            validate();
        }
    });
    unselectAllButton = new Button(buttonsComposite, SWT.PUSH);
    unselectAllButton.setText(CodeUtilsNLS.UI_UnselectAll);
    unselectAllButton.setLayoutData(new RowData());
    unselectAllButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            checkAllItems(false);
            validate();
        }
    });
    createColumns(viewer);
    final Table table = viewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    ArrayContentProvider provider = new ArrayContentProvider();
    viewer.setContentProvider(provider);
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            if (event.getSource() instanceof TableViewer) {
                Table tb = ((TableViewer) event.getSource()).getTable();
                TableItem[] items = tb.getSelection();
                items[0].setChecked(!items[0].getChecked());
                itemCheckStateChanged(items[0]);
                validate();
            }
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            validate();
        }
    });
    populateViewer();
}
Example 25
Project: LanguageBuddy-master  File: EditTagDialog.java View source code
/* (non-Javadoc)
     * @see org.eclipse.jface.dialogs.MessageDialog#createCustomArea(org.eclipse.swt.widgets.Composite)
     */
@Override
protected Control createDialogArea(Composite parent) {
    Composite c = (Composite) super.createDialogArea(parent);
    //c.setSize(400, SWT.DEFAULT);
    Group group = new Group(c, SWT.SHADOW_ETCHED_IN);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    group.setLayout(layout);
    new Label(group, SWT.LEAD).setText(MessageUtil.getString("TagParent"));
    final Combo parentPathCombo = new Combo(group, SWT.LEAD | SWT.READ_ONLY);
    parentPathCombo.setLayoutData(new GridData(CONTROL_WIDTH, SWT.DEFAULT));
    parentPathCombo.setToolTipText(MessageUtil.getString("TagParentPath"));
    final ComboViewer pathCV = new ComboViewer(parentPathCombo);
    pathCV.setContentProvider(new ArrayContentProvider());
    parentPathCombo.setEnabled(isNew);
    new Label(group, SWT.LEAD).setText(MessageUtil.getString("TagId"));
    tagId = new Text(group, SWT.LEAD);
    tagId.setLayoutData(new GridData(CONTROL_WIDTH, SWT.DEFAULT));
    tagId.setEnabled(isNew);
    if (!isNew) {
        tagId.setText(metaNodeList.getLast().getId());
    }
    new Label(group, SWT.LEAD).setText(MessageUtil.getString("TagLang"));
    langCombo = new Combo(group, SWT.LEAD | SWT.READ_ONLY);
    ComboViewer langCV = new ComboViewer(langCombo);
    langCV.setContentProvider(new ArrayContentProvider());
    new Label(group, SWT.LEAD).setText(MessageUtil.getString("TagDesc"));
    tagDesc = new Text(group, SWT.LEAD);
    tagDesc.setLayoutData(new GridData(CONTROL_WIDTH, SWT.DEFAULT));
    LangType[] langs = WorkspaceLanguageManager.findUserLanguages();
    final UniversalLanguage[] uLangs = new UniversalLanguage[langs.length];
    for (int i = 0; i < langs.length; i++) {
        UniversalLanguage ul = new UniversalLanguage(langs[i].getLang());
        uLangs[i] = ul;
    }
    langCV.setInput(uLangs);
    langCombo.select(0);
    language = uLangs[0];
    pathCV.setInput(getPathList(language.getCode()));
    if (isNew)
        parentPathCombo.select(parentNodeLevel);
    else
        // can't be changed
        parentPathCombo.select(0);
    parentPathCombo.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            parentNodeLevel = parentPathCombo.getSelectionIndex();
            if (parentNodeLevel == 0)
                metaNode = new MetaNode(null, metaData);
            else
                metaNode = new MetaNode(metaNodeList.get(parentNodeLevel - 1), metaData);
        }
    });
    langCombo.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            int i = langCombo.getSelectionIndex();
            if (i > -1) {
                language = uLangs[i];
                String langName = new UniversalLanguage(uLangs[i].getLanguageCode()).getDescription();
                tagDesc.setToolTipText(MessageUtil.getString("TagDescription", langName));
                pathCV.setInput(getPathList(language.getCode()));
                for (DescType d : metaData.getDescArray()) {
                    if (d.getLang().equals(language.getCode())) {
                        tagDesc.setText(d.getStringValue());
                        idDescInSync = false;
                        return;
                    }
                }
            }
        }
    });
    tagId.setToolTipText(MessageUtil.getString("TagID"));
    tagId.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            String id = tagId.getText();
            Matcher m = ILLEGAL_ID_CHAR.matcher(id);
            if (m.find()) {
                id = m.replaceAll("");
                tagId.setText(id);
            }
            metaData.setMetaId(id);
            // if the tagDesc is null, set it to the same as the id
            if (tagDesc.getText().length() == 0 || idDescInSync) {
                tagDesc.setText(tagId.getText());
                setLangDesc();
            }
        }
    });
    langCombo.setToolTipText(MessageUtil.getString("TagLanguage"));
    tagDesc.setToolTipText(MessageUtil.getString("TagDescription", new UniversalLanguage(uLangs[0].getLanguageCode()).getDescription()));
    if (isNew == false && metaNodeList.size() > 0) {
        tagDesc.setText(metaNodeList.getLast().getName(language.getCode()));
        if (tagDesc.getText().equals(tagId.getText()))
            idDescInSync = true;
        else
            idDescInSync = false;
    }
    tagDesc.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            if (tagDesc.getText().equals(tagId.getText()) || tagDesc.getText().length() == 0)
                idDescInSync = true;
            else
                idDescInSync = false;
            setLangDesc();
        }
    });
    c.pack();
    // set the focus
    if (isNew)
        tagId.setFocus();
    else
        tagDesc.setFocus();
    return c;
}
Example 26
Project: tdq-studio-se-master  File: MatchRuleElementTreeSelectionDialog.java View source code
private void createSelectBlockingKeysTable(Composite parent) {
    Composite composite = new Composite(parent, SWT.None);
    GridLayout layout = new GridLayout();
    layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
    composite.setLayout(layout);
    blockingKeysTable = new TableViewer(composite, SWT.BORDER);
    Table table = blockingKeysTable.getTable();
    TableColumn c1 = new TableColumn(table, SWT.NULL);
    //$NON-NLS-1$
    c1.setText(DefaultMessagesImpl.getString("BlockingKeyTableComposite.BLOCKING_KEY_NAME"));
    TableColumn c2 = new TableColumn(table, SWT.NULL);
    //$NON-NLS-1$
    c2.setText(DefaultMessagesImpl.getString("BlockingKeyTableComposite.PRECOLUMN"));
    TableColumn c3 = new TableColumn(table, SWT.NULL);
    //$NON-NLS-1$
    c3.setText(DefaultMessagesImpl.getString("BlockingKeyTableComposite.PRE_ALGO"));
    TableColumn c4 = new TableColumn(table, SWT.NULL);
    //$NON-NLS-1$
    c4.setText(DefaultMessagesImpl.getString("BlockingKeyTableComposite.PRE_VALUE"));
    TableColumn c5 = new TableColumn(table, SWT.NULL);
    //$NON-NLS-1$
    c5.setText(DefaultMessagesImpl.getString("BlockingKeyTableComposite.KEY_ALGO"));
    TableColumn c6 = new TableColumn(table, SWT.NULL);
    //$NON-NLS-1$
    c6.setText(DefaultMessagesImpl.getString("BlockingKeyTableComposite.KEY_VALUE"));
    TableColumn c7 = new TableColumn(table, SWT.NULL);
    //$NON-NLS-1$
    c7.setText(DefaultMessagesImpl.getString("BlockingKeyTableComposite.POST_ALGO"));
    TableColumn c8 = new TableColumn(table, SWT.NULL);
    //$NON-NLS-1$
    c8.setText(DefaultMessagesImpl.getString("BlockingKeyTableComposite.POST_VALUE"));
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    TableLayout tableLayout = new TableLayout();
    for (int i = 0; i < 8; i++) {
        tableLayout.addColumnData(new ColumnWeightData(1, 120, true));
    }
    table.setLayout(tableLayout);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 0, 0);
    table.setLayoutData(data);
    blockingKeysTable.setContentProvider(new ArrayContentProvider());
    blockingKeysTable.setLabelProvider(new BlockingKeysTableLabelProvider(inputColumnNames));
}
Example 27
Project: cdt-master  File: LanguageSettingsProviderTab.java View source code
/**
	 * Create table to display providers.
	 */
private void createProvidersPane(Composite parent) {
    Composite composite = new Composite(parent, SWT.BORDER | SWT.SINGLE);
    composite.setLayout(new GridLayout());
    // items checkboxes  only for project properties page
    tableProviders = new Table(composite, page.isForPrefs() ? SWT.NONE : SWT.CHECK);
    tableProviders.setLayoutData(new GridData(GridData.FILL_BOTH));
    tableProviders.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            displaySelectedOptionPage();
            updateButtons();
        }
    });
    tableProvidersViewer = new CheckboxTableViewer(tableProviders);
    tableProvidersViewer.setContentProvider(new ArrayContentProvider());
    tableProvidersViewer.setLabelProvider(new ProvidersTableLabelProvider());
    tableProvidersViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            ILanguageSettingsProvider checkedProvider = (ILanguageSettingsProvider) event.getElement();
            String id = checkedProvider.getId();
            ILanguageSettingsProvider newProvider = null;
            if (event.getChecked()) {
                if (LanguageSettingsManager.isWorkspaceProvider(checkedProvider) && !LanguageSettingsManager.isPreferShared(id)) {
                    newProvider = getInitialProvider(id);
                    if (newProvider == null) {
                        ILanguageSettingsProvider rawProvider = LanguageSettingsManager.getRawProvider(checkedProvider);
                        if (rawProvider instanceof ILanguageSettingsEditableProvider) {
                            newProvider = LanguageSettingsManager.getProviderCopy((ILanguageSettingsEditableProvider) rawProvider, false);
                        }
                    }
                }
            } else {
                if (!LanguageSettingsManager.isWorkspaceProvider(checkedProvider)) {
                    newProvider = LanguageSettingsManager.getWorkspaceProvider(id);
                }
            }
            int pos = presentedProviders.indexOf(checkedProvider);
            tableProviders.setSelection(pos);
            if (newProvider != null) {
                // will refresh and save checked providers
                replaceSelectedProvider(newProvider);
                createOptionsPage(newProvider);
            } else {
                saveCheckedProviders();
                tableProvidersViewer.refresh(checkedProvider);
            // option page is reused
            }
            displaySelectedOptionPage();
            updateButtons();
        }
    });
}