Search in sources :

Example 31 with ArrayContentProvider

use of org.eclipse.jface.viewers.ArrayContentProvider in project eclipse.platform.text by eclipse.

the class SearchDialog method handleCustomizePressed.

private void handleCustomizePressed() {
    List<SearchPageDescriptor> input = SearchPlugin.getDefault().getSearchPageDescriptors();
    input = filterByActivities(input);
    final ArrayList<Image> createdImages = new ArrayList<>(input.size());
    ILabelProvider labelProvider = new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof SearchPageDescriptor)
                return LegacyActionTools.removeMnemonics(((SearchPageDescriptor) element).getLabel());
            return null;
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof SearchPageDescriptor) {
                ImageDescriptor imageDesc = ((SearchPageDescriptor) element).getImage();
                if (imageDesc == null)
                    return null;
                Image image = imageDesc.createImage();
                if (image != null)
                    createdImages.add(image);
                return image;
            }
            return null;
        }
    };
    String message = SearchMessages.SearchPageSelectionDialog_message;
    ListSelectionDialog dialog = new ListSelectionDialog(getShell(), input, new ArrayContentProvider(), labelProvider, message) {

        Button fLastUsedPageButton;

        @Override
        public void create() {
            super.create();
            final CheckboxTableViewer viewer = getViewer();
            final Button okButton = this.getOkButton();
            viewer.addCheckStateListener(event -> okButton.setEnabled(viewer.getCheckedElements().length > 0));
            SelectionListener listener = new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    okButton.setEnabled(viewer.getCheckedElements().length > 0);
                }
            };
            this.getButton(IDialogConstants.SELECT_ALL_ID).addSelectionListener(listener);
            this.getButton(IDialogConstants.DESELECT_ALL_ID).addSelectionListener(listener);
        }

        @Override
        protected Control createDialogArea(Composite parent) {
            Composite control = (Composite) super.createDialogArea(parent);
            fLastUsedPageButton = new Button(control, SWT.CHECK);
            fLastUsedPageButton.setText(SearchMessages.SearchPageSelectionDialog_rememberLastUsedPage_message);
            fLastUsedPageButton.setSelection(fDialogSettings.getBoolean(STORE_IS_OPEN_PREVIOUS_PAGE));
            return control;
        }

        @Override
        protected void okPressed() {
            fDialogSettings.put(STORE_IS_OPEN_PREVIOUS_PAGE, fLastUsedPageButton.getSelection());
            super.okPressed();
        }
    };
    dialog.setTitle(SearchMessages.SearchPageSelectionDialog_title);
    dialog.setInitialSelections(SearchPlugin.getDefault().getEnabledSearchPageDescriptors(fInitialPageId).toArray());
    if (dialog.open() == Window.OK) {
        SearchPageDescriptor.setEnabled(dialog.getResult());
        Display display = getShell().getDisplay();
        close();
        if (display != null && !display.isDisposed()) {
            display.asyncExec(() -> new OpenSearchDialogAction().run());
        }
    }
    destroyImages(createdImages);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArrayList(java.util.ArrayList) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) Image(org.eclipse.swt.graphics.Image) Button(org.eclipse.swt.widgets.Button) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) ListSelectionDialog(org.eclipse.ui.dialogs.ListSelectionDialog) SelectionListener(org.eclipse.swt.events.SelectionListener) Display(org.eclipse.swt.widgets.Display)

Example 32 with ArrayContentProvider

use of org.eclipse.jface.viewers.ArrayContentProvider in project eclipse.platform.text by eclipse.

the class ShowSearchesAction method run.

public void run(boolean showAll) {
    Iterator<Search> iter = SearchManager.getDefault().getPreviousSearches().iterator();
    int cutOffSize;
    if (showAll)
        cutOffSize = 0;
    else
        cutOffSize = SearchDropDownAction.RESULTS_IN_DROP_DOWN;
    int size = SearchManager.getDefault().getPreviousSearches().size() - cutOffSize;
    Search selectedSearch = SearchManager.getDefault().getCurrentSearch();
    Action selectedAction = null;
    ArrayList<Action> input = new ArrayList<>(size);
    int i = 0;
    while (iter.hasNext()) {
        Search search = iter.next();
        if (i++ < cutOffSize)
            continue;
        Action action = new ShowSearchAction(search);
        input.add(action);
        if (selectedSearch == search)
            selectedAction = action;
    }
    // Open a list dialog.
    String title;
    String message;
    if (showAll) {
        title = SearchMessages.PreviousSearchesDialog_title;
        message = SearchMessages.PreviousSearchesDialog_message;
    } else {
        title = SearchMessages.OtherSearchesDialog_title;
        message = SearchMessages.OtherSearchesDialog_message;
    }
    LabelProvider labelProvider = new SearchesLabelProvider();
    ListDialog dlg = new ListDialog(SearchPlugin.getActiveWorkbenchShell());
    dlg.setInput(input);
    dlg.setTitle(title);
    dlg.setContentProvider(new ArrayContentProvider());
    dlg.setLabelProvider(labelProvider);
    dlg.setMessage(message);
    if (selectedAction != null) {
        Object[] selected = new Object[1];
        selected[0] = selectedAction;
        dlg.setInitialSelections(selected);
    }
    if (dlg.open() == Window.OK) {
        List<Object> result = Arrays.asList(dlg.getResult());
        if (result != null && result.size() == 1) {
            ((ShowSearchAction) result.get(0)).run();
        }
    }
}
Also used : Action(org.eclipse.jface.action.Action) ArrayList(java.util.ArrayList) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) ListDialog(org.eclipse.ui.dialogs.ListDialog)

Example 33 with ArrayContentProvider

use of org.eclipse.jface.viewers.ArrayContentProvider in project eclipse.platform.text by eclipse.

the class MatchFilterSelectionDialog method createMatchFilterControls.

private void createMatchFilterControls(Composite parent) {
    // Create list viewer
    Label l = new Label(parent, SWT.NONE);
    l.setFont(parent.getFont());
    l.setText(SearchMessages.MatchFilterSelectionDialog_filter_description);
    Table table = new Table(parent, SWT.CHECK | SWT.BORDER);
    table.setFont(parent.getFont());
    fListViewer = new CheckboxTableViewer(table);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.minimumHeight = convertHeightInCharsToPixels(8);
    table.setLayoutData(data);
    class ListenerAndLabelProvider extends LabelProvider implements ISelectionChangedListener, ICheckStateListener {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            performFilterListSelectionChanged();
        }

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            performFilterListCheckStateChanged();
        }

        @Override
        public String getText(Object element) {
            return ((MatchFilter) element).getName();
        }
    }
    ListenerAndLabelProvider listenerAndLP = new ListenerAndLabelProvider();
    fListViewer.setLabelProvider(listenerAndLP);
    fListViewer.setContentProvider(new ArrayContentProvider());
    fListViewer.addSelectionChangedListener(listenerAndLP);
    fListViewer.addCheckStateListener(listenerAndLP);
    fListViewer.setInput(fAllFilters);
    fListViewer.setCheckedElements(fEnabledFilters);
    l = new Label(parent, SWT.NONE);
    l.setFont(parent.getFont());
    l.setText(SearchMessages.MatchFilterSelectionDialog_description_label);
    fDescription = new Text(parent, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL);
    fDescription.setFont(parent.getFont());
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = convertHeightInCharsToPixels(3);
    fDescription.setLayoutData(data);
}
Also used : Table(org.eclipse.swt.widgets.Table) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Text(org.eclipse.swt.widgets.Text) MatchFilter(org.eclipse.search.ui.text.MatchFilter) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 34 with ArrayContentProvider

use of org.eclipse.jface.viewers.ArrayContentProvider 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(false);
    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 35 with ArrayContentProvider

use of org.eclipse.jface.viewers.ArrayContentProvider in project uiautomatorviewer by yangzaiCN.

the class UiAutomatorViewer method createContents.

/**
 * Create contents of the application window.
 *
 * @param parent
 */
@Override
protected Control createContents(Composite parent) {
    UiAutomatorModel.createInstance(this);
    Composite basePane = new Composite(parent, SWT.NONE);
    basePane.setLayout(new GridLayout(2, false));
    mScreenshotCanvas = new Canvas(basePane, SWT.NONE);
    mScreenshotCanvas.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseUp(MouseEvent e) {
            UiAutomatorModel.getModel().toggleExploreMode();
        }
    });
    mScreenshotCanvas.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK));
    mScreenshotCanvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3));
    mScreenshotCanvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            if (mCachedScaleImage != null) {
                // shifting the image here, so that there's a border around screen shot
                // this makes highlighting red rectangles on the screen shot edges more visible
                e.gc.drawImage(mCachedScaleImage, IMG_BORDER, IMG_BORDER);
                Rectangle rect = UiAutomatorModel.getModel().getCurrentDrawingRect();
                if (rect != null) {
                    e.gc.setForeground(e.gc.getDevice().getSystemColor(SWT.COLOR_RED));
                    if (UiAutomatorModel.getModel().isExploreMode()) {
                        // when we highlight nodes dynamically on mouse move,
                        // use dashed borders
                        e.gc.setLineStyle(SWT.LINE_DASH);
                        e.gc.setLineWidth(1);
                    } else {
                        // when highlighting nodes on tree node selection,
                        // use solid borders
                        e.gc.setLineStyle(SWT.LINE_SOLID);
                        e.gc.setLineWidth(2);
                    }
                    e.gc.drawRectangle(IMG_BORDER + getScaledSize(rect.x), IMG_BORDER + getScaledSize(rect.y), getScaledSize(rect.width), getScaledSize(rect.height));
                }
            }
        }
    });
    mScreenshotCanvas.addMouseMoveListener(new MouseMoveListener() {

        @Override
        public void mouseMove(MouseEvent e) {
            if (UiAutomatorModel.getModel().isExploreMode()) {
                UiAutomatorModel.getModel().updateSelectionForCoordinates(getInverseScaledSize(e.x - IMG_BORDER), getInverseScaledSize(e.y - IMG_BORDER));
            }
        }
    });
    mScreenshotCanvas.setBackgroundImage(ImageHelper.loadImageDescriptorFromResource("images/logo.png").createImage());
    ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
    toolBarManager.add(mOpenFilesAction);
    toolBarManager.add(mExpandAllAction);
    toolBarManager.add(mScreenshotAction);
    toolBarManager.createControl(basePane);
    mTreeViewer = new TreeViewer(basePane, SWT.BORDER);
    Tree tree = mTreeViewer.getTree();
    GridData gd_Tree = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1);
    gd_Tree.widthHint = 350;
    tree.setLayoutData(gd_Tree);
    mTreeViewer.setContentProvider(new BasicTreeNodeContentProvider());
    // default LabelProvider uses toString() to generate text to display
    mTreeViewer.setLabelProvider(new LabelProvider());
    mTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            if (event.getSelection().isEmpty()) {
                UiAutomatorModel.getModel().setSelectedNode(null);
            } else if (event.getSelection() instanceof IStructuredSelection) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                Object o = selection.toArray()[0];
                if (o instanceof BasicTreeNode) {
                    UiAutomatorModel.getModel().setSelectedNode((BasicTreeNode) o);
                }
            }
        }
    });
    // move focus so that it's not on tool bar (looks weird)
    tree.setFocus();
    Group grpNodeDetail = new Group(basePane, SWT.NONE);
    grpNodeDetail.setLayout(new FillLayout(SWT.HORIZONTAL));
    GridData gd_grpNodeDetail = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_grpNodeDetail.heightHint = FIXED_DETAIL_VIEW_HEIGHT;
    gd_grpNodeDetail.minimumHeight = FIXED_DETAIL_VIEW_HEIGHT;
    gd_grpNodeDetail.widthHint = FIXED_RHS_WIDTH;
    gd_grpNodeDetail.minimumWidth = FIXED_RHS_WIDTH;
    grpNodeDetail.setLayoutData(gd_grpNodeDetail);
    grpNodeDetail.setText("Node Detail");
    Composite tableContainer = new Composite(grpNodeDetail, SWT.NONE);
    tableContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    TableColumnLayout columnLayout = new TableColumnLayout();
    tableContainer.setLayout(columnLayout);
    mTableViewer = new TableViewer(tableContainer, SWT.BORDER | SWT.FULL_SELECTION);
    Table table = mTableViewer.getTable();
    table.setLinesVisible(true);
    // use ArrayContentProvider here, it assumes the input to the TableViewer
    // is an array, where each element represents a row in the table
    mTableViewer.setContentProvider(new ArrayContentProvider());
    TableViewerColumn tableViewerColumnKey = new TableViewerColumn(mTableViewer, SWT.NONE);
    TableColumn tblclmnKey = tableViewerColumnKey.getColumn();
    tableViewerColumnKey.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof AttributePair) {
                // first column, shows the attribute name
                return ((AttributePair) element).key;
            }
            return super.getText(element);
        }
    });
    columnLayout.setColumnData(tblclmnKey, new ColumnWeightData(1, ColumnWeightData.MINIMUM_WIDTH, true));
    TableViewerColumn tableViewerColumnValue = new TableViewerColumn(mTableViewer, SWT.NONE);
    tableViewerColumnValue.setEditingSupport(new AttributeTableEditingSupport(mTableViewer));
    TableColumn tblclmnValue = tableViewerColumnValue.getColumn();
    columnLayout.setColumnData(tblclmnValue, new ColumnWeightData(2, ColumnWeightData.MINIMUM_WIDTH, true));
    tableViewerColumnValue.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof AttributePair) {
                // second column, shows the attribute value
                return ((AttributePair) element).value;
            }
            return super.getText(element);
        }
    });
    return basePane;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Group(org.eclipse.swt.widgets.Group) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Rectangle(org.eclipse.swt.graphics.Rectangle) AttributePair(com.android.uiautomator.tree.AttributePair) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ToolBarManager(org.eclipse.jface.action.ToolBarManager) BasicTreeNode(com.android.uiautomator.tree.BasicTreeNode) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) BasicTreeNodeContentProvider(com.android.uiautomator.tree.BasicTreeNodeContentProvider) Tree(org.eclipse.swt.widgets.Tree) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) MouseAdapter(org.eclipse.swt.events.MouseAdapter) FillLayout(org.eclipse.swt.layout.FillLayout) TableColumn(org.eclipse.swt.widgets.TableColumn) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)92 GridData (org.eclipse.swt.layout.GridData)67 Composite (org.eclipse.swt.widgets.Composite)59 TableViewer (org.eclipse.jface.viewers.TableViewer)56 SelectionEvent (org.eclipse.swt.events.SelectionEvent)45 Table (org.eclipse.swt.widgets.Table)43 GridLayout (org.eclipse.swt.layout.GridLayout)41 Button (org.eclipse.swt.widgets.Button)37 Label (org.eclipse.swt.widgets.Label)36 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)32 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)32 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)30 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)30 Group (org.eclipse.swt.widgets.Group)23 ComboViewer (org.eclipse.jface.viewers.ComboViewer)21 TableColumn (org.eclipse.swt.widgets.TableColumn)21 LabelProvider (org.eclipse.jface.viewers.LabelProvider)19 Combo (org.eclipse.swt.widgets.Combo)19 Text (org.eclipse.swt.widgets.Text)19 Point (org.eclipse.swt.graphics.Point)18