Search in sources :

Example 76 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project liferay-ide by liferay.

the class CustomJspPage method _createLeftPart.

private void _createLeftPart(Composite parent) {
    ScrolledComposite leftContainer = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
    Composite leftPart = SWTUtil.createComposite(leftContainer, 1, 1, GridData.FILL_BOTH, 0, 0);
    FillLayout layout = new FillLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    leftContainer.setLayout(layout);
    leftContainer.setMinSize(410, 200);
    leftContainer.setExpandHorizontal(true);
    leftContainer.setExpandVertical(true);
    leftContainer.setContent(leftPart);
    Label leftLabel = new Label(leftPart, SWT.NONE);
    leftLabel.setText("6.2 Custom JSPs (double-click to compare with 6.2)");
    _leftTreeViewer = new TreeViewer(leftPart, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    _leftTreeViewer.getTree().setLayoutData(gd);
    _leftTreeViewer.setContentProvider(new ViewContentProvider());
    _leftTreeViewer.setLabelProvider(new LeftViewLabelProvider());
    _leftTreeViewer.addDoubleClickListener(new DoubleClickExpandListener(_leftTreeViewer));
    _leftTreeViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            ISelection selection = event.getSelection();
            File file = (File) ((ITreeSelection) selection).getFirstElement();
            if (file.isDirectory()) {
                return;
            }
            if (_is62FileFound(file)) {
                String[] paths = _get62FilePaths(file);
                compare(paths[0], paths[1], "6.2 original JSP", "custom JSP");
            } else {
                MessageDialog.openInformation(Display.getDefault().getActiveShell(), "File not found", "There is no such file in liferay 62");
            }
        }
    });
    _leftTreeViewer.setComparator(new ViewerComparator() {

        @Override
        public int category(Object element) {
            File file = (File) element;
            if (file.isDirectory()) {
                return -1;
            } else {
                return super.category(element);
            }
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) TreeViewer(org.eclipse.jface.viewers.TreeViewer) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) Label(org.eclipse.swt.widgets.Label) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FillLayout(org.eclipse.swt.layout.FillLayout) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) ISelection(org.eclipse.jface.viewers.ISelection) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 77 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project liferay-ide by liferay.

the class SDKProjectConvertWizardPage method createProjectsList.

protected void createProjectsList(Composite workArea) {
    Label title = new Label(workArea, SWT.NONE);
    title.setText(Msgs.importProjectLabel);
    title.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
    // Composite listComposite = new Composite(workArea, SWT.NONE);
    // GridLayout layout = new GridLayout();
    // layout.numColumns = 2;
    // layout.marginWidth = 0;
    // layout.makeColumnsEqualWidth = false;
    // listComposite.setLayout(layout);
    // GridData gd = new GridData(GridData.GRAB_HORIZONTAL
    // | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
    // gd.grabExcessHorizontalSpace = true;
    // gd.horizontalSpan = 3;
    // listComposite.setLayoutData(gd);
    projectsList = new CheckboxTreeViewer(workArea, SWT.BORDER);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
    gridData.widthHint = new PixelConverter(projectsList.getControl()).convertWidthInCharsToPixels(25);
    gridData.heightHint = new PixelConverter(projectsList.getControl()).convertHeightInCharsToPixels(10);
    projectsList.getControl().setLayoutData(gridData);
    projectsList.setContentProvider(new ITreeContentProvider() {

        public void dispose() {
        }

        public Object[] getChildren(Object parentElement) {
            return null;
        }

        public Object[] getElements(Object inputElement) {
            return (Object[]) getDataModel().getProperty(SELECTED_PROJECTS);
        }

        public Object getParent(Object element) {
            return null;
        }

        public boolean hasChildren(Object element) {
            return false;
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    projectsList.setLabelProvider(new ProjectLabelProvider());
    projectsList.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            ProjectRecord element = (ProjectRecord) event.getElement();
            if (element.hasConflicts()) {
                projectsList.setChecked(element, false);
            }
            getDataModel().setProperty(SELECTED_PROJECTS, projectsList.getCheckedElements());
            setPageComplete(ListUtil.isNotEmpty(projectsList.getCheckedElements()));
        }
    });
    projectsList.setInput(this);
    projectsList.setComparator(new ViewerComparator());
}
Also used : CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) PixelConverter(org.eclipse.jface.layout.PixelConverter) ProjectRecord(com.liferay.ide.project.core.ProjectRecord) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 78 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project liferay-ide by liferay.

the class SDKProjectsImportWizardPage method createProjectsList.

protected void createProjectsList(Composite workArea) {
    labelProjectsList = new Label(workArea, SWT.NONE);
    labelProjectsList.setText(Msgs.importProjectsLabel);
    labelProjectsList.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
    projectsList = new CheckboxTreeViewer(workArea, SWT.BORDER);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    gridData.widthHint = new PixelConverter(projectsList.getControl()).convertWidthInCharsToPixels(25);
    gridData.heightHint = new PixelConverter(projectsList.getControl()).convertHeightInCharsToPixels(10);
    projectsList.getControl().setLayoutData(gridData);
    projectsList.setContentProvider(new ITreeContentProvider() {

        public void dispose() {
        }

        public Object[] getChildren(Object parentElement) {
            return null;
        }

        public Object[] getElements(Object inputElement) {
            return getProjectRecords();
        }

        public Object getParent(Object element) {
            return null;
        }

        public boolean hasChildren(Object element) {
            return false;
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    projectsList.setLabelProvider(createProjectsListLabelProvider());
    projectsList.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            handleCheckStateChangedEvent(event);
        }
    });
    projectsList.setInput(this);
    projectsList.setComparator(new ViewerComparator());
    createSelectionButtons(workArea);
}
Also used : CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) PixelConverter(org.eclipse.jface.layout.PixelConverter) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 79 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project liferay-ide by liferay.

the class WorkingSetGroup method _createControl.

private void _createControl(Composite container) {
    addToWorkingSetButton = new Button(container, SWT.CHECK);
    GridData gd_addToWorkingSetButton = new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1);
    gd_addToWorkingSetButton.verticalIndent = 12;
    addToWorkingSetButton.setLayoutData(gd_addToWorkingSetButton);
    addToWorkingSetButton.setSelection(true);
    addToWorkingSetButton.setData("name", "addToWorkingSetButton");
    addToWorkingSetButton.setText("Add project to working set");
    addToWorkingSetButton.setSelection(false);
    final Label workingsetLabel = new Label(container, SWT.NONE);
    GridData gd_workingsetLabel = new GridData();
    gd_workingsetLabel.horizontalIndent = 10;
    workingsetLabel.setLayoutData(gd_workingsetLabel);
    workingsetLabel.setEnabled(false);
    workingsetLabel.setData("name", "workingsetLabel");
    workingsetLabel.setText("Working set:");
    Combo workingsetCombo = new Combo(container, SWT.READ_ONLY);
    workingsetCombo.setEnabled(false);
    workingsetCombo.setData("name", "workingsetCombo");
    workingsetCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    _workingsetComboViewer = new ComboViewer(workingsetCombo);
    _workingsetComboViewer.setContentProvider(new IStructuredContentProvider() {

        public void dispose() {
        }

        public Object[] getElements(Object input) {
            if (input instanceof IWorkingSet[]) {
                return (IWorkingSet[]) input;
            } else if (input instanceof List<?>) {
                return new Object[] { input };
            } else if (input instanceof Set<?>) {
                return ((Set<?>) input).toArray();
            }
            return new IWorkingSet[0];
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    _workingsetComboViewer.setLabelProvider(new LabelProvider() {

        public void dispose() {
            _images.dispose();
            super.dispose();
        }

        @SuppressWarnings("deprecation")
        public Image getImage(Object element) {
            if (element instanceof IWorkingSet) {
                ImageDescriptor imageDescriptor = ((IWorkingSet) element).getImage();
                if (imageDescriptor != null) {
                    try {
                        return (Image) _images.create(imageDescriptor);
                    } catch (DeviceResourceException dre) {
                        return null;
                    }
                }
            }
            return super.getImage(element);
        }

        public String getText(Object element) {
            if (element instanceof IWorkingSet) {
                return ((IWorkingSet) element).getLabel();
            } else if (element instanceof List<?>) {
                StringBuffer sb = new StringBuffer();
                for (Object o : (List<?>) element) {
                    if (o instanceof IWorkingSet) {
                        if (sb.length() > 0) {
                            sb.append(", ");
                        }
                        sb.append(((IWorkingSet) o).getLabel());
                    }
                }
                return sb.toString();
            }
            return super.getText(element);
        }

        private ResourceManager _images = new LocalResourceManager(JFaceResources.getResources());
    });
    _workingsetComboViewer.setComparator(new ViewerComparator());
    final Button newWorkingSetButton = new Button(container, SWT.NONE);
    newWorkingSetButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    newWorkingSetButton.setData("name", "configureButton");
    newWorkingSetButton.setText("More...");
    newWorkingSetButton.setEnabled(false);
    newWorkingSetButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(final SelectionEvent e) {
            IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
            IWorkingSetSelectionDialog dialog = workingSetManager.createWorkingSetSelectionDialog(_shell, true, _working_set_ids.toArray(new String[0]));
            if (dialog.open() == Window.OK) {
                IWorkingSet[] workingSets = dialog.getSelection();
                selectWorkingSets(Arrays.asList(workingSets));
            }
        }
    });
    if (selectWorkingSets(_workingSets)) {
        addToWorkingSetButton.setSelection(true);
        workingsetLabel.setEnabled(true);
        _workingsetComboViewer.getCombo().setEnabled(true);
        newWorkingSetButton.setEnabled(true);
    }
    addToWorkingSetButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            boolean addToWorkingingSet = addToWorkingSetButton.getSelection();
            workingsetLabel.setEnabled(addToWorkingingSet);
            _workingsetComboViewer.getCombo().setEnabled(addToWorkingingSet);
            newWorkingSetButton.setEnabled(addToWorkingingSet);
            if (addToWorkingingSet) {
                updateConfiguration();
            } else {
                _workingSets.clear();
            }
        }
    });
    _workingsetComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            updateConfiguration();
        }
    });
}
Also used : LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Image(org.eclipse.swt.graphics.Image) Button(org.eclipse.swt.widgets.Button) DeviceResourceException(org.eclipse.jface.resource.DeviceResourceException) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IWorkingSetManager(org.eclipse.ui.IWorkingSetManager) IWorkingSetSelectionDialog(org.eclipse.ui.dialogs.IWorkingSetSelectionDialog) List(java.util.List) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) IWorkingSet(org.eclipse.ui.IWorkingSet) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ResourceManager(org.eclipse.jface.resource.ResourceManager) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 80 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project jbosstools-openshift by jbosstools.

the class DeploymentConfigPage method createDataVolumeTable.

protected TableViewer createDataVolumeTable(Composite tableContainer) {
    Table table = new Table(tableContainer, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    this.dataViewer = new TableViewerBuilder(table, tableContainer).column(new IColumnLabelProvider<String>() {

        @Override
        public String getValue(String label) {
            return label;
        }
    }).name("Container Path").align(SWT.LEFT).weight(2).minWidth(100).buildColumn().buildViewer();
    dataViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            String first = (String) e1;
            String other = (String) e2;
            return first.compareTo(other);
        }
    });
    return dataViewer;
}
Also used : IColumnLabelProvider(org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder.IColumnLabelProvider) Table(org.eclipse.swt.widgets.Table) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) TableViewerBuilder(org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder)

Aggregations

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