Search in sources :

Example 1 with StyledCellLabelProvider

use of org.eclipse.jface.viewers.StyledCellLabelProvider in project AutoRefactor by JnRouvignac.

the class ChooseRefactoringWizardPage method createRefactoringsTable.

private void createRefactoringsTable(Composite parent) {
    tableViewer = newCheckList(parent, BORDER | H_SCROLL | CHECK | NO_FOCUS | HIDE_SELECTION);
    createColumns(tableViewer);
    tableViewer.setContentProvider(new ArrayContentProvider());
    final List<RefactoringRule> refactorings = AllRefactoringRules.getAllRefactoringRules();
    tableViewer.setInput(refactorings);
    tableViewer.setCheckStateProvider(new CheckStateProvider(refactorings));
    tableViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object o1, Object o2) {
            return ((RefactoringRule) o1).getName().compareTo(((RefactoringRule) o2).getName());
        }
    });
    tableViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object refactoring) {
            final String filter = filterText.getText().toLowerCase();
            final RefactoringRule rule = (RefactoringRule) refactoring;
            final String description = rule.getDescription().toLowerCase();
            final String name = rule.getName().toLowerCase();
            return description.contains(filter) || name.contains(filter);
        }
    });
    ColumnViewerToolTipSupport.enableFor(tableViewer, ToolTip.NO_RECREATE);
    tableViewer.setLabelProvider(new StyledCellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            final String filter = filterText.getText().toLowerCase();
            final String name = ((RefactoringRule) cell.getElement()).getName();
            cell.setText(name);
            cell.setStyleRanges(getStyleRanges(name, filter));
        }

        private StyleRange[] getStyleRanges(String text, String filter) {
            final int matchIndex = text.toLowerCase().indexOf(filter);
            final int matchLength = filter.length();
            if (matchIndex != -1 && matchLength != 0) {
                final StyledString styledString = new StyledString(text, defaultStyler);
                styledString.setStyle(matchIndex, matchLength, underlineStyler);
                return styledString.getStyleRanges();
            }
            return null;
        }

        @Override
        public String getToolTipText(Object refactoring) {
            return ((RefactoringRule) refactoring).getDescription();
        }

        @Override
        public Point getToolTipShift(Object object) {
            return new Point(10, 20);
        }
    });
    final Table table = tableViewer.getTable();
    table.setLinesVisible(true);
    tableViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
    packColumns(table);
    table.setFocus();
}
Also used : StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) Table(org.eclipse.swt.widgets.Table) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) TableViewer(org.eclipse.jface.viewers.TableViewer) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Viewer(org.eclipse.jface.viewers.Viewer) ICheckStateProvider(org.eclipse.jface.viewers.ICheckStateProvider) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Point(org.eclipse.swt.graphics.Point) ViewerCell(org.eclipse.jface.viewers.ViewerCell) RefactoringRule(org.autorefactor.refactoring.RefactoringRule) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData)

Example 2 with StyledCellLabelProvider

use of org.eclipse.jface.viewers.StyledCellLabelProvider in project bndtools by bndtools.

the class WorkspacePreviewPage method createControl.

@Override
public void createControl(Composite parent) {
    setTitle("Preview Changes");
    //$NON-NLS-1$
    setImageDescriptor(Plugin.imageDescriptorFromPlugin("icons/bndtools-wizban.png"));
    imgAdded = AbstractUIPlugin.imageDescriptorFromPlugin(Plugin.PLUGIN_ID, "icons/incoming.gif").createImage(parent.getDisplay());
    imgOverwrite = AbstractUIPlugin.imageDescriptorFromPlugin(Plugin.PLUGIN_ID, "icons/conflict.gif").createImage(parent.getDisplay());
    imgError = AbstractUIPlugin.imageDescriptorFromPlugin(Plugin.PLUGIN_ID, "icons/error_obj.gif").createImage(parent.getDisplay());
    int columns = 4;
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(columns, false);
    composite.setLayout(layout);
    setControl(composite);
    Label lblTitle = new Label(composite, SWT.NONE);
    lblTitle.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, columns, 1));
    // Table
    tblOutputs = new Table(composite, SWT.BORDER | SWT.CHECK);
    tblOutputs.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, columns, 1));
    vwrOutputs = new CheckboxTableViewer(tblOutputs);
    vwrOutputs.setContentProvider(ArrayContentProvider.getInstance());
    vwrOutputs.setLabelProvider(new StyledCellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            StyledString label;
            Image icon;
            String path = (String) cell.getElement();
            String error = resourceErrors.get(path);
            if (error != null) {
                label = new StyledString(path, ItalicStyler.INSTANCE_ERROR);
                icon = imgError;
            } else {
                label = new StyledString(path);
                icon = existingFiles.contains(path) ? imgOverwrite : imgAdded;
            }
            cell.setText(path);
            cell.setStyleRanges(label.getStyleRanges());
            cell.setImage(icon);
        }
    });
    vwrOutputs.setSorter(new ViewerSorter(Collator.getInstance()));
    // Details display
    final Label lblDetails = new Label(composite, SWT.NONE);
    lblDetails.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, columns, 1));
    lblDetails.setText(MSG_NOTHING_SELECTED);
    // Button Panel
    Label spacer1 = new Label(composite, SWT.NONE);
    spacer1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    Button btnSelectNonConflict = new Button(composite, SWT.PUSH);
    btnSelectNonConflict.setText("Select Non-Conflicting");
    btnSelectNonConflict.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            modifyLock.modifyOperation(new Runnable() {

                @Override
                public void run() {
                    checkedPaths.clear();
                    for (Entry<String, Resource> entry : templateOutputs.entries()) {
                        String path = entry.getKey();
                        if (!existingFiles.contains(path))
                            checkedPaths.add(path);
                    }
                    vwrOutputs.setCheckedElements(checkedPaths.toArray());
                }
            });
        }
    });
    Button btnSelectAll = new Button(composite, SWT.PUSH);
    btnSelectAll.setText("Select All");
    btnSelectAll.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            vwrOutputs.setAllChecked(true);
        }
    });
    Button btnSelectNone = new Button(composite, SWT.PUSH);
    btnSelectNone.setText("Select None");
    btnSelectNone.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            vwrOutputs.setAllChecked(false);
        }
    });
    // Listeners
    vwrOutputs.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) vwrOutputs.getSelection();
            if (sel.isEmpty()) {
                lblDetails.setText(MSG_NOTHING_SELECTED);
            } else {
                String path = (String) sel.getFirstElement();
                String resourceError = resourceErrors.get(path);
                if (resourceError != null) {
                    lblDetails.setText(resourceError);
                } else if (existingFiles.contains(path)) {
                    lblDetails.setText("This file already exists and will be overwritten");
                } else {
                    lblDetails.setText("This file will be created");
                }
            }
        }
    });
    vwrOutputs.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(final CheckStateChangedEvent event) {
            modifyLock.ifNotModifying(new Runnable() {

                @Override
                public void run() {
                    final String updatedPath = (String) event.getElement();
                    if (event.getChecked()) {
                        checkedPaths.add(updatedPath);
                        // Check any directories that are parents of this path
                        modifyLock.modifyOperation(new Runnable() {

                            @Override
                            public void run() {
                                for (Entry<String, Resource> entry : templateOutputs.entries()) {
                                    String path = entry.getKey();
                                    if (path.endsWith("/") && updatedPath.startsWith(path)) {
                                        checkedPaths.add(path);
                                        vwrOutputs.setChecked(path, true);
                                    }
                                }
                            }
                        });
                    } else {
                        checkedPaths.remove(updatedPath);
                        // Uncheck any paths that are descendants of this path
                        if (updatedPath.endsWith("/")) {
                            modifyLock.modifyOperation(new Runnable() {

                                @Override
                                public void run() {
                                    for (Entry<String, Resource> entry : templateOutputs.entries()) {
                                        String path = entry.getKey();
                                        if (path.startsWith(updatedPath)) {
                                            checkedPaths.remove(path);
                                            vwrOutputs.setChecked(path, false);
                                        }
                                    }
                                }
                            });
                        }
                    }
                }
            });
        }
    });
}
Also used : CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) Label(org.eclipse.swt.widgets.Label) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) StyledString(org.eclipse.jface.viewers.StyledString) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) GridLayout(org.eclipse.swt.layout.GridLayout) Entry(java.util.Map.Entry) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Resource(org.bndtools.templating.Resource) StyledString(org.eclipse.jface.viewers.StyledString) ViewerCell(org.eclipse.jface.viewers.ViewerCell) GridData(org.eclipse.swt.layout.GridData) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 3 with StyledCellLabelProvider

use of org.eclipse.jface.viewers.StyledCellLabelProvider in project bndtools by bndtools.

the class EditableParametersPart method createControl.

public Control createControl(Composite parent) {
    this.parent = parent;
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    composite.setLayout(layout);
    Label titleLabel = new Label(composite, SWT.NONE);
    titleLabel.setText(title);
    titleLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1));
    Table table = new Table(composite, SWT.BORDER | SWT.MULTI);
    viewer = new TableViewer(table);
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    final Image iconImg = imageDescriptor.createImage(parent.getDisplay());
    viewer.setLabelProvider(new StyledCellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            @SuppressWarnings("unchecked") Pair<String, Attrs> entry = (Pair<String, Attrs>) cell.getElement();
            StyledString label = new StyledString(entry.getFirst(), BoldStyler.INSTANCE_DEFAULT);
            for (Entry<String, String> attribEntry : entry.getSecond().entrySet()) {
                label.append("; " + attribEntry.getKey() + "=", StyledString.QUALIFIER_STYLER);
                label.append(attribEntry.getValue());
            }
            cell.setText(label.toString());
            cell.setStyleRanges(label.getStyleRanges());
            cell.setImage(iconImg);
        }
    });
    viewer.setInput(entries);
    GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    gd.widthHint = 280;
    gd.heightHint = 80;
    table.setLayoutData(gd);
    final AddRemoveButtonBarPart buttonBarPart = new AddRemoveButtonBarPart();
    ToolBar buttonBar = buttonBarPart.createControl(composite, SWT.FLAT | SWT.VERTICAL);
    buttonBar.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    final Image imgEdit = ImageDescriptor.createFromURL(BUNDLE.getEntry("icons/edit.gif")).createImage(parent.getDisplay());
    final Image imgEditDisabled = ImageDescriptor.createFromURL(BUNDLE.getEntry("icons/edit-disabled.gif")).createImage(parent.getDisplay());
    final ToolItem btnEdit = new ToolItem(buttonBar, SWT.PUSH);
    btnEdit.setImage(imgEdit);
    btnEdit.setDisabledImage(imgEditDisabled);
    buttonBarPart.setRemoveEnabled(false);
    btnEdit.setEnabled(false);
    buttonBarPart.addListener(new AddRemoveListener() {

        @Override
        public void addSelected() {
            doAdd();
        }

        @Override
        public void removeSelected() {
            doRemove();
        }
    });
    btnEdit.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doEdit();
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            boolean enabled = !viewer.getSelection().isEmpty();
            buttonBarPart.setRemoveEnabled(enabled);
            btnEdit.setEnabled(enabled);
        }
    });
    viewer.addOpenListener(new IOpenListener() {

        @Override
        public void open(OpenEvent event) {
            doEdit();
        }
    });
    table.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.DEL && e.stateMask == 0)
                doRemove();
        }
    });
    composite.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent ev) {
            iconImg.dispose();
            imgEdit.dispose();
            imgEditDisabled.dispose();
        }
    });
    return composite;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) Attrs(aQute.bnd.header.Attrs) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) StyledString(org.eclipse.jface.viewers.StyledString) Image(org.eclipse.swt.graphics.Image) DisposeEvent(org.eclipse.swt.events.DisposeEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Entry(java.util.Map.Entry) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ToolItem(org.eclipse.swt.widgets.ToolItem) Pair(aQute.libg.tuple.Pair) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) StyledString(org.eclipse.jface.viewers.StyledString) ViewerCell(org.eclipse.jface.viewers.ViewerCell) AddRemoveButtonBarPart(org.bndtools.utils.swt.AddRemoveButtonBarPart) AddRemoveListener(org.bndtools.utils.swt.AddRemoveButtonBarPart.AddRemoveListener) IOpenListener(org.eclipse.jface.viewers.IOpenListener) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) TableViewer(org.eclipse.jface.viewers.TableViewer) OpenEvent(org.eclipse.jface.viewers.OpenEvent)

Example 4 with StyledCellLabelProvider

use of org.eclipse.jface.viewers.StyledCellLabelProvider in project bndtools by bndtools.

the class AddFilesToRepositoryWizardPage method createControl.

@Override
@SuppressWarnings("unused")
public void createControl(Composite parent) {
    setTitle("Add Files to Repository");
    Composite composite = new Composite(parent, SWT.NONE);
    new Label(composite, SWT.NONE).setText("Selected files:");
    // Spacer;
    new Label(composite, SWT.NONE);
    Table table = new Table(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    TableColumn col;
    col = new TableColumn(table, SWT.NONE);
    col.setText("Path");
    col.setWidth(300);
    col = new TableColumn(table, SWT.NONE);
    col.setText("Bundle Name/Version");
    col.setWidth(300);
    viewer = new TableViewer(table);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new StyledCellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            File file = (File) cell.getElement();
            Pair<String, String> bundleId = bsnMap.get(file);
            int index = cell.getColumnIndex();
            if (index == 0) {
                if (bundleId == null) {
                    cell.setImage(errorImg);
                } else {
                    cell.setImage(jarImg);
                }
                StyledString label = new StyledString(file.getName());
                String parentPath = file.getParent();
                if (parentPath != null) {
                    label.append(" (" + parentPath + ")", StyledString.QUALIFIER_STYLER);
                }
                cell.setText(label.getString());
                cell.setStyleRanges(label.getStyleRanges());
            } else if (index == 1) {
                if (bundleId == null) {
                    cell.setImage(errorImg);
                    cell.setText("Not a JAR file");
                } else {
                    String bsn = bundleId.getFirst();
                    String version = bundleId.getSecond();
                    if (bsn == null) {
                        cell.setImage(warnImg);
                        cell.setText("Not a Bundle JAR");
                    } else {
                        cell.setImage(okayImg);
                        StyledString styledString = new StyledString(bsn);
                        if (version != null) {
                            styledString.append(" [" + version + "]", StyledString.COUNTER_STYLER);
                            cell.setText(styledString.getString());
                            cell.setStyleRanges(styledString.getStyleRanges());
                        }
                    }
                }
            }
        }
    });
    viewer.setInput(files);
    validate();
    final Button btnAdd = new Button(composite, SWT.PUSH);
    btnAdd.setText("Add JARs...");
    final Button btnAddExternal = new Button(composite, SWT.PUSH);
    btnAddExternal.setText("Add External JARs...");
    final Button btnRemove = new Button(composite, SWT.NONE);
    btnRemove.setText("Remove");
    btnRemove.setEnabled(false);
    // LISTENERS
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            btnRemove.setEnabled(!viewer.getSelection().isEmpty());
        }
    });
    btnAdd.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doAdd();
        }
    });
    btnAddExternal.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doAddExternal();
        }
    });
    btnRemove.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doRemove();
        }
    });
    // LAYOUT
    composite.setLayout(new GridLayout(2, false));
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 4));
    btnAdd.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    btnRemove.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    setControl(composite);
}
Also used : StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) TableColumn(org.eclipse.swt.widgets.TableColumn) ViewerCell(org.eclipse.jface.viewers.ViewerCell) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Pair(bndtools.types.Pair)

Example 5 with StyledCellLabelProvider

use of org.eclipse.jface.viewers.StyledCellLabelProvider in project bndtools by bndtools.

the class IndexerWizardPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NULL);
    setControl(composite);
    // Create controls
    new Label(composite, SWT.NONE).setText(Messages.IndexerWizardPage_baseDir);
    txtBaseDir = new Text(composite, SWT.BORDER);
    newSpacer(composite);
    Composite cmpButtonBar = new Composite(composite, SWT.NONE);
    Button btnBrowseWorkspace = new Button(cmpButtonBar, SWT.PUSH);
    btnBrowseWorkspace.setText(Messages.IndexerWizardPage_browse);
    Button btnBrowseExternal = new Button(cmpButtonBar, SWT.PUSH);
    btnBrowseExternal.setText(Messages.IndexerWizardPage_browseExternal);
    new Label(composite, SWT.NONE).setText(Messages.IndexerWizardPage_resourcePattern);
    txtResourcePattern = new Text(composite, SWT.BORDER);
    ControlDecoration decorResourcePattern = new ControlDecoration(txtResourcePattern, SWT.LEFT | SWT.TOP, composite);
    decorResourcePattern.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
    decorResourcePattern.setMarginWidth(3);
    decorResourcePattern.setDescriptionText(Messages.IndexerWizardPage_resourcePatternHelp);
    decorResourcePattern.setShowHover(true);
    decorResourcePattern.setShowOnlyOnFocus(false);
    Label lblInputs = new Label(composite, SWT.NONE);
    lblInputs.setText(Messages.IndexerWizardPage_inputs);
    Table tblInputs = new Table(composite, SWT.MULTI | SWT.BORDER);
    vwrInputs = new TableViewer(tblInputs);
    vwrInputs.setContentProvider(ArrayContentProvider.getInstance());
    vwrInputs.setLabelProvider(new StyledCellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            Object elem = cell.getElement();
            if (elem instanceof Path) {
                cell.setText(elem.toString());
                cell.setImage(imgFile);
            } else if (elem instanceof IStatus) {
                IStatus status = (IStatus) elem;
                cell.setText(status.getMessage());
                if (status.getSeverity() == IStatus.ERROR)
                    cell.setImage(imgError);
                else if (status.getSeverity() == IStatus.WARNING)
                    cell.setImage(imgWarning);
            }
        }
    });
    newSpacer(composite);
    lblInputCount = new Label(composite, SWT.NONE);
    Label lblOutputs = new Label(composite, SWT.NONE);
    lblOutputs.setText(Messages.IndexerWizardPage_output);
    Group grpOutput = new Group(composite, SWT.NONE);
    new Label(grpOutput, SWT.NONE).setText(Messages.IndexerWizardPage_prefix);
    txtOutputPrefix = new Text(grpOutput, SWT.BORDER);
    newSpacer(grpOutput);
    btnOutputPretty = new Button(grpOutput, SWT.RADIO);
    btnOutputPretty.setText(Messages.IndexerWizardPage_prettyPrint);
    newSpacer(grpOutput);
    btnOutputCompressed = new Button(grpOutput, SWT.RADIO);
    btnOutputCompressed.setText(Messages.IndexerWizardPage_compressed);
    newSpacer(grpOutput);
    lblOutputName = new Label(grpOutput, SWT.NONE);
    // LAYOUT
    GridLayout gl;
    GridData gd;
    gl = new GridLayout(2, false);
    gl.horizontalSpacing = 10;
    composite.setLayout(gl);
    txtBaseDir.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    cmpButtonBar.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false));
    gl = new GridLayout(2, false);
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    cmpButtonBar.setLayout(gl);
    btnBrowseWorkspace.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
    btnBrowseExternal.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
    txtResourcePattern.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    lblInputs.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    gd.heightHint = 120;
    gd.widthHint = 100;
    tblInputs.setLayoutData(gd);
    lblInputCount.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));
    lblOutputs.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
    grpOutput.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    grpOutput.setLayout(new GridLayout(2, false));
    txtOutputPrefix.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    btnOutputCompressed.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    btnOutputPretty.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    lblOutputName.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    // LOAD DATA
    if (baseDir != null)
        txtBaseDir.setText(baseDir.getAbsolutePath());
    if (resourcePattern != null)
        txtResourcePattern.setText(resourcePattern);
    //$NON-NLS-1$
    txtOutputPrefix.setText("index");
    btnOutputCompressed.setSelection(outputStyle == IndexFormatStyle.COMPRESSED);
    btnOutputPretty.setSelection(outputStyle == IndexFormatStyle.PRETTY_UNCOMPRESSED);
    updateOutputFileName();
    updateInputs();
    // LISTENERS
    txtBaseDir.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent me) {
            String baseDirStr = txtBaseDir.getText();
            baseDir = baseDirStr.isEmpty() ? null : new File(baseDirStr);
            validate();
            updateInputs();
        }
    });
    txtResourcePattern.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent me) {
            resourcePattern = txtResourcePattern.getText();
            updateInputs();
        }
    });
    btnBrowseWorkspace.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
            ContainerSelectionDialog containerDlg = new ContainerSelectionDialog(getShell(), root, false, Messages.IndexerWizardPage_selectBaseDir);
            containerDlg.showClosedProjects(false);
            if (containerDlg.open() == Window.OK) {
                Object[] selection = containerDlg.getResult();
                if (selection != null && selection.length > 0) {
                    IPath workspacePath = (IPath) selection[0];
                    IResource resource = root.findMember(workspacePath);
                    if (resource == null)
                        MessageDialog.openError(getShell(), "Error", "Could not find resource for path " + workspacePath);
                    else
                        txtBaseDir.setText(resource.getLocation().toString());
                }
            }
        }
    });
    btnBrowseExternal.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog dirDialog = new DirectoryDialog(getShell());
            dirDialog.setMessage(Messages.IndexerWizardPage_selectBaseDir);
            String selectedPath = dirDialog.open();
            if (selectedPath != null)
                txtBaseDir.setText(selectedPath);
        }
    });
    txtOutputPrefix.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent me) {
            updateOutputFileName();
            validate();
        }
    });
    Listener outputRadioListener = new Listener() {

        @Override
        public void handleEvent(Event ev) {
            outputStyle = btnOutputCompressed.getSelection() ? IndexFormatStyle.COMPRESSED : IndexFormatStyle.PRETTY_UNCOMPRESSED;
            updateOutputFileName();
            validate();
        }
    };
    btnOutputCompressed.addListener(SWT.Selection, outputRadioListener);
    btnOutputPretty.addListener(SWT.Selection, outputRadioListener);
    validate();
}
Also used : Group(org.eclipse.swt.widgets.Group) IStatus(org.eclipse.core.runtime.IStatus) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) IPath(org.eclipse.core.runtime.IPath) Path(java.nio.file.Path) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) IPath(org.eclipse.core.runtime.IPath) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) ViewerCell(org.eclipse.jface.viewers.ViewerCell) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) ContainerSelectionDialog(org.eclipse.ui.dialogs.ContainerSelectionDialog) GridData(org.eclipse.swt.layout.GridData) ModifyEvent(org.eclipse.swt.events.ModifyEvent) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) File(java.io.File) IResource(org.eclipse.core.resources.IResource)

Aggregations

StyledCellLabelProvider (org.eclipse.jface.viewers.StyledCellLabelProvider)5 ViewerCell (org.eclipse.jface.viewers.ViewerCell)5 GridData (org.eclipse.swt.layout.GridData)5 Table (org.eclipse.swt.widgets.Table)5 StyledString (org.eclipse.jface.viewers.StyledString)4 TableViewer (org.eclipse.jface.viewers.TableViewer)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 Composite (org.eclipse.swt.widgets.Composite)4 Label (org.eclipse.swt.widgets.Label)4 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 Button (org.eclipse.swt.widgets.Button)3 File (java.io.File)2 Entry (java.util.Map.Entry)2 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)2 CheckboxTableViewer (org.eclipse.jface.viewers.CheckboxTableViewer)2 Image (org.eclipse.swt.graphics.Image)2 Attrs (aQute.bnd.header.Attrs)1