Search in sources :

Example 51 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider 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 52 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider 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 53 with ITreeContentProvider

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

the class LiferayDataModelWizardPage method handleFileBrowseButton.

protected void handleFileBrowseButton(final Text text, String title, String message) {
    ISelectionStatusValidator validator = getContainerDialogSelectionValidator();
    ViewerFilter filter = getContainerDialogViewerFilter();
    ITreeContentProvider contentProvider = new WorkbenchContentProvider();
    IDecoratorManager decoratorManager = PlatformUI.getWorkbench().getDecoratorManager();
    ILabelProvider labelProvider = new DecoratingLabelProvider(new WorkbenchLabelProvider(), decoratorManager.getLabelDecorator());
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), labelProvider, contentProvider);
    dialog.setValidator(validator);
    dialog.setTitle(title);
    dialog.setMessage(message);
    dialog.addFilter(filter);
    final IWebProject lrproject = LiferayCore.create(IWebProject.class, CoreUtil.getProject(getDataModel().getStringProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME)));
    if (lrproject != null) {
        final IFolder defaultDocroot = lrproject.getDefaultDocrootFolder();
        if (defaultDocroot != null) {
            dialog.setInput(defaultDocroot);
            if (dialog.open() == Window.OK) {
                Object element = dialog.getFirstResult();
                try {
                    if (element instanceof IFile) {
                        IFile file = (IFile) element;
                        final IPath relativePath = file.getFullPath().makeRelativeTo(defaultDocroot.getFullPath());
                        text.setText("/" + relativePath.toPortableString());
                    // dealWithSelectedContainerResource(container);
                    }
                } catch (Exception ex) {
                // Do nothing
                }
            }
        }
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IFile(org.eclipse.core.resources.IFile) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) IPath(org.eclipse.core.runtime.IPath) IWebProject(com.liferay.ide.core.IWebProject) IDecoratorManager(org.eclipse.ui.IDecoratorManager) DecoratingLabelProvider(org.eclipse.jface.viewers.DecoratingLabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) CoreException(org.eclipse.core.runtime.CoreException) JavaModelException(org.eclipse.jdt.core.JavaModelException) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) EObject(org.eclipse.emf.ecore.EObject) IFolder(org.eclipse.core.resources.IFolder)

Example 54 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project arduino-eclipse-plugin by Sloeber.

the class PlatformSelectionPage method createContents.

@Override
protected Control createContents(Composite parent) {
    Composite control = new Composite(parent, SWT.NONE);
    control.setLayout(new GridLayout());
    Button btnCheckButton = new Button(control, SWT.CHECK);
    // $NON-NLS-1$
    btnCheckButton.setText("Hide 3th party json files");
    btnCheckButton.setSelection(this.myHideJson);
    btnCheckButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            PlatformSelectionPage.this.myHideJson = btnCheckButton.getSelection();
            MyPreferences.setHideJson(PlatformSelectionPage.this.myHideJson);
            PlatformSelectionPage.this.viewer.setInput(EMPTY_STRING);
        }
    });
    Text desc = new Text(control, SWT.READ_ONLY);
    desc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    desc.setBackground(parent.getBackground());
    desc.setText(Messages.platformSelectionTip);
    PatternFilter filter = new PatternFilter() {

        @Override
        protected boolean isLeafMatch(final Viewer viewer1, final Object element) {
            boolean isMatch = false;
            if (element instanceof InstallableVersion) {
                InstallableVersion ver = (InstallableVersion) element;
                isMatch |= wordMatches(ver.getVersion().toString());
                isMatch |= myWordMatches(ver.getPlatform());
            }
            if (element instanceof IndexFile) {
                IndexFile indexFile = (IndexFile) element;
                isMatch |= myWordMatches(indexFile);
            }
            if (element instanceof Package) {
                Package pac = (Package) element;
                isMatch |= myWordMatches(pac);
            }
            if (element instanceof Platform) {
                Platform platform = (Platform) element;
                isMatch |= myWordMatches(platform);
            }
            return isMatch;
        }

        private boolean myWordMatches(Platform platform) {
            boolean ret = wordMatches(platform.getName());
            ret |= wordMatches(platform.getArchitecture());
            ret |= wordMatches(platform.getBoards());
            ret |= myWordMatches(platform.getPackage());
            return ret;
        }

        private boolean myWordMatches(Package pac) {
            boolean ret = wordMatches(pac.getEmail());
            ret |= wordMatches(pac.getMaintainer());
            ret |= wordMatches(pac.getName());
            ret |= wordMatches(pac.getWebsiteURL().toString());
            ret |= wordMatches(pac.getIndexFile().toString());
            return ret;
        }

        private boolean myWordMatches(IndexFile indexFile) {
            return wordMatches(indexFile.getFullName());
        }
    };
    this.myGuiplatformTree = new FilteredTree(control, SWT.CHECK | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION, filter, true) {

        @Override
        protected TreeViewer doCreateTreeViewer(Composite composite, int style) {
            CheckboxTreeViewer viewer1 = new CheckboxTreeViewer(composite);
            viewer1.setCheckStateProvider(new ICheckStateProvider() {

                @Override
                public boolean isChecked(Object element) {
                    if (element instanceof InstallableVersion) {
                        return ((InstallableVersion) element).isInstalled();
                    }
                    if (element instanceof IndexFile) {
                        return ((IndexFile) element).isInstalled();
                    }
                    if (element instanceof Package) {
                        return ((Package) element).isInstalled();
                    }
                    if (element instanceof Platform) {
                        return ((Platform) element).isInstalled();
                    }
                    return false;
                }

                @Override
                public boolean isGrayed(Object element) {
                    if (element instanceof InstallableVersion) {
                        return false;
                    }
                    if (element instanceof IndexFile) {
                        return ((IndexFile) element).isInstalled();
                    }
                    if (element instanceof Package) {
                        return ((Package) element).isInstalled();
                    }
                    if (element instanceof Platform) {
                        return ((Platform) element).isInstalled();
                    }
                    return false;
                }
            });
            viewer1.addCheckStateListener(new ICheckStateListener() {

                @Override
                public void checkStateChanged(CheckStateChangedEvent event) {
                    Object element = event.getElement();
                    if (element instanceof InstallableVersion) {
                        InstallableVersion cur = (InstallableVersion) element;
                        cur.setInstalled(event.getChecked());
                    }
                    PlatformSelectionPage.this.viewer.refresh();
                }
            });
            viewer1.setContentProvider(new ITreeContentProvider() {

                @Override
                public Object[] getElements(Object inputElement) {
                    if (PlatformSelectionPage.this.myHideJson) {
                        Set<Package> packages = PlatformSelectionPage.this.myPlatformTree.getAllPackages();
                        return packages.toArray(new Object[packages.size()]);
                    }
                    Collection<IndexFile> indexFiles = PlatformSelectionPage.this.myPlatformTree.getAllIndexFiles();
                    return indexFiles.toArray(new Object[indexFiles.size()]);
                }

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

                @Override
                public void inputChanged(Viewer viewer11, Object oldInput, Object newInput) {
                // nothing to do
                }

                @Override
                public Object[] getChildren(Object parentElement) {
                    if (parentElement instanceof IndexFile) {
                        Collection<Package> packages = ((IndexFile) parentElement).getAllPackages();
                        return packages.toArray(new Object[packages.size()]);
                    }
                    if (parentElement instanceof Package) {
                        Collection<Platform> platforms = ((Package) parentElement).getPlatforms();
                        return platforms.toArray(new Object[platforms.size()]);
                    }
                    if (parentElement instanceof Platform) {
                        Collection<InstallableVersion> versions = ((Platform) parentElement).getVersions();
                        return versions.toArray(new Object[versions.size()]);
                    }
                    return null;
                }

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

                @Override
                public boolean hasChildren(Object element) {
                    return !(element instanceof InstallableVersion);
                }
            });
            viewer1.setLabelProvider(new CellLabelProvider() {

                @Override
                public String getToolTipText(Object element) {
                    if (element instanceof IndexFile) {
                        return ((IndexFile) element).getFullName();
                    }
                    if (element instanceof Package) {
                        Package pkg = (Package) element;
                        return // $NON-NLS-1$
                        Messages.packageTooltip.replaceAll("\\$\\{MAINTAINER}", pkg.getMaintainer()).replaceAll("\\$\\{EMAIL}", // $NON-NLS-1$
                        pkg.getEmail()).replaceAll("\\$\\{URL}", // $NON-NLS-1$
                        pkg.getWebsiteURL().toString());
                    }
                    if (element instanceof Platform) {
                        return ((Platform) element).getBoards();
                    }
                    if (element instanceof InstallableVersion) {
                        return null;
                    }
                    return null;
                }

                @Override
                public org.eclipse.swt.graphics.Point getToolTipShift(Object object) {
                    return new org.eclipse.swt.graphics.Point(5, 5);
                }

                @Override
                public int getToolTipDisplayDelayTime(Object object) {
                    return 1000;
                }

                @Override
                public int getToolTipTimeDisplayed(Object object) {
                    return 5000;
                }

                @Override
                public void update(ViewerCell cell) {
                    if (cell.getElement() instanceof IndexFile) {
                        cell.setText(((IndexFile) cell.getElement()).getNiceName());
                    }
                    if (cell.getElement() instanceof Package) {
                        cell.setText(((Package) cell.getElement()).getName());
                    }
                    if (cell.getElement() instanceof Platform) {
                        cell.setText(((Platform) cell.getElement()).getName());
                    }
                    if (cell.getElement() instanceof InstallableVersion) {
                        cell.setText(((InstallableVersion) cell.getElement()).getVersion().toString());
                    }
                }
            });
            return viewer1;
        }
    };
    this.viewer = this.myGuiplatformTree.getViewer();
    ColumnViewerToolTipSupport.enableFor(this.viewer);
    this.myGuiplatformTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    this.viewer.setInput(EMPTY_STRING);
    return control;
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) Listener(org.eclipse.swt.widgets.Listener) Platform(io.sloeber.core.api.PackageManager.PlatformTree.Platform) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) IndexFile(io.sloeber.core.api.PackageManager.PlatformTree.IndexFile) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) Composite(org.eclipse.swt.widgets.Composite) ICheckStateProvider(org.eclipse.jface.viewers.ICheckStateProvider) Text(org.eclipse.swt.widgets.Text) ViewerCell(org.eclipse.jface.viewers.ViewerCell) InstallableVersion(io.sloeber.core.api.PackageManager.PlatformTree.InstallableVersion) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) Package(io.sloeber.core.api.PackageManager.PlatformTree.Package) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 55 with ITreeContentProvider

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

the class ChooseServerDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);
    final TreeViewer tv = new TreeViewer(container);
    tv.setContentProvider(new ITreeContentProvider() {

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

        @Override
        public void dispose() {
        }

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

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

        @Override
        public Object[] getElements(Object inputElement) {
            return (IServer[]) valid.toArray(new IServer[valid.size()]);
        }

        @Override
        public Object[] getChildren(Object parentElement) {
            return null;
        }
    });
    tv.setLabelProvider(new LabelProvider() {

        @Override
        public Image getImage(Object element) {
            if (element instanceof IServer)
                return ImageResource.getImage(((IServer) element).getServerType().getId());
            return super.getImage(element);
        }

        @Override
        public String getText(Object element) {
            if (element instanceof IServer)
                return ((IServer) element).getName();
            return super.getText(element);
        }
    });
    tv.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            selected = null;
            ISelection sel = tv.getSelection();
            if (sel instanceof IStructuredSelection) {
                Object first = ((IStructuredSelection) sel).getFirstElement();
                if (first instanceof IServer) {
                    selected = (IServer) first;
                }
            }
            getButton(IDialogConstants.OK_ID).setEnabled(selected != null);
        }
    });
    tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
    tv.setInput(PlatformUI.getWorkbench());
    return container;
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) IServer(org.eclipse.wst.server.core.IServer) Composite(org.eclipse.swt.widgets.Composite) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) ISelection(org.eclipse.jface.viewers.ISelection) GridData(org.eclipse.swt.layout.GridData) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Aggregations

ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)67 Viewer (org.eclipse.jface.viewers.Viewer)31 LabelProvider (org.eclipse.jface.viewers.LabelProvider)18 GridData (org.eclipse.swt.layout.GridData)18 Composite (org.eclipse.swt.widgets.Composite)16 TreeViewer (org.eclipse.jface.viewers.TreeViewer)15 GridLayout (org.eclipse.swt.layout.GridLayout)14 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)12 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)12 Label (org.eclipse.swt.widgets.Label)12 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)11 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)11 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)11 WorkbenchContentProvider (org.eclipse.ui.model.WorkbenchContentProvider)11 WorkbenchLabelProvider (org.eclipse.ui.model.WorkbenchLabelProvider)11 ArrayList (java.util.ArrayList)10 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)9 ElementTreeSelectionDialog (org.eclipse.ui.dialogs.ElementTreeSelectionDialog)9 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)8 SourceViewer (org.eclipse.jface.text.source.SourceViewer)7