Search in sources :

Example 1 with Package

use of io.sloeber.core.api.PackageManager.PlatformTree.Package 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)

Aggregations

IndexFile (io.sloeber.core.api.PackageManager.PlatformTree.IndexFile)1 InstallableVersion (io.sloeber.core.api.PackageManager.PlatformTree.InstallableVersion)1 Package (io.sloeber.core.api.PackageManager.PlatformTree.Package)1 Platform (io.sloeber.core.api.PackageManager.PlatformTree.Platform)1 CellLabelProvider (org.eclipse.jface.viewers.CellLabelProvider)1 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)1 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)1 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)1 ICheckStateProvider (org.eclipse.jface.viewers.ICheckStateProvider)1 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerCell (org.eclipse.jface.viewers.ViewerCell)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Event (org.eclipse.swt.widgets.Event)1 Listener (org.eclipse.swt.widgets.Listener)1 Text (org.eclipse.swt.widgets.Text)1