Search in sources :

Example 1 with ArduinoPlatformPackageIndex

use of io.sloeber.core.api.Json.ArduinoPlatformPackageIndex in project arduino-eclipse-plugin by Sloeber.

the class PlatformSelectionPage method mustBeInstalled.

private boolean mustBeInstalled(ArduinoPlatform platform) {
    ArduinoPackage parentPkg = platform.getParent();
    ArduinoPlatformPackageIndex parentIndex = parentPkg.getPackageIndex();
    InstallableVersion[] inScopeVersions = myShownPlatforms.get(parentIndex.getID()).get(parentPkg.getID()).get(platform.getID());
    for (InstallableVersion version : inScopeVersions) {
        if (version.mustBeInstalled()) {
            return true;
        }
    }
    return false;
}
Also used : ArduinoPlatformPackageIndex(io.sloeber.core.api.Json.ArduinoPlatformPackageIndex) ArduinoPackage(io.sloeber.core.api.Json.ArduinoPackage)

Example 2 with ArduinoPlatformPackageIndex

use of io.sloeber.core.api.Json.ArduinoPlatformPackageIndex in project arduino-eclipse-plugin by Sloeber.

the class BoardsManager method loadPackage.

private static void loadPackage(File jsonFile) {
    try (Reader reader = new FileReader(jsonFile)) {
        ArduinoPlatformPackageIndex index = new Gson().fromJson(reader, ArduinoPlatformPackageIndex.class);
        index.setPackageFile(jsonFile);
        packageIndices.add(index);
    } catch (Exception e) {
        Common.log(new Status(IStatus.ERROR, Activator.getId(), Manager_Failed_to_parse.replace(FILE_TAG, jsonFile.getAbsolutePath()), e));
        // Delete the file so it stops damaging
        jsonFile.delete();
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) MyMultiStatus(io.sloeber.core.tools.MyMultiStatus) Status(org.eclipse.core.runtime.Status) ArduinoPlatformPackageIndex(io.sloeber.core.api.Json.ArduinoPlatformPackageIndex) Reader(java.io.Reader) FileReader(java.io.FileReader) Gson(com.google.gson.Gson) FileReader(java.io.FileReader) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 3 with ArduinoPlatformPackageIndex

use of io.sloeber.core.api.Json.ArduinoPlatformPackageIndex in project arduino-eclipse-plugin by Sloeber.

the class PlatformSelectionPage method mustBeInstalled.

private boolean mustBeInstalled(ArduinoPackage pkg) {
    ArduinoPlatformPackageIndex parentIndex = pkg.getPackageIndex();
    TreeMap<String, InstallableVersion[]> inScopeVersions = myShownPlatforms.get(parentIndex.getID()).get(pkg.getID());
    for (InstallableVersion[] versions : inScopeVersions.values()) {
        for (InstallableVersion version : versions) {
            if (version.mustBeInstalled()) {
                return true;
            }
        }
    }
    return false;
}
Also used : ArduinoPlatformPackageIndex(io.sloeber.core.api.Json.ArduinoPlatformPackageIndex)

Example 4 with ArduinoPlatformPackageIndex

use of io.sloeber.core.api.Json.ArduinoPlatformPackageIndex 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);
    btnCheckButton.setText(Messages.PlatformSelectionPage_hide_third_party_url);
    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 ArduinoPlatformPackageIndex) {
                ArduinoPlatformPackageIndex indexFile = (ArduinoPlatformPackageIndex) element;
                isMatch |= myWordMatches(indexFile);
            }
            if (element instanceof ArduinoPackage) {
                ArduinoPackage pac = (ArduinoPackage) element;
                isMatch |= myWordMatches(pac);
            }
            if (element instanceof ArduinoPlatformVersion) {
                ArduinoPlatformVersion platform = (ArduinoPlatformVersion) element;
                isMatch |= myWordMatches(platform);
            }
            return isMatch;
        }

        private boolean myWordMatches(ArduinoPlatformVersion arduinoPlatformVersion) {
            boolean ret = wordMatches(arduinoPlatformVersion.getName());
            ret |= wordMatches(arduinoPlatformVersion.getArchitecture());
            ret |= wordMatches(arduinoPlatformVersion.getConcattenatedBoardNames());
            ret |= myWordMatches(arduinoPlatformVersion.getParent().getParent());
            return ret;
        }

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

        private boolean myWordMatches(ArduinoPlatformPackageIndex indexFile) {
            return wordMatches(indexFile.getID());
        }
    };
    this.myGuiplatformTree = new FilteredTree(control, SWT.CHECK | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION, filter, true, 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).mustBeInstalled();
                    }
                    if (element instanceof ArduinoPlatformPackageIndex) {
                        return mustBeInstalled((ArduinoPlatformPackageIndex) element);
                    }
                    if (element instanceof ArduinoPackage) {
                        return mustBeInstalled((ArduinoPackage) element);
                    }
                    if (element instanceof ArduinoPlatform) {
                        return mustBeInstalled((ArduinoPlatform) element);
                    }
                    return false;
                }

                @Override
                public boolean isGrayed(Object element) {
                    if (element instanceof InstallableVersion) {
                        return false;
                    }
                    if (element instanceof ArduinoPlatformPackageIndex) {
                        return mustBeInstalled((ArduinoPlatformPackageIndex) element);
                    }
                    if (element instanceof ArduinoPackage) {
                        return mustBeInstalled((ArduinoPackage) element);
                    }
                    if (element instanceof ArduinoPlatform) {
                        return mustBeInstalled((ArduinoPlatform) element);
                    }
                    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.setMustBeInstalled(event.getChecked());
                    }
                    PlatformSelectionPage.this.viewer.refresh();
                }
            });
            viewer1.setContentProvider(new ITreeContentProvider() {

                @Override
                public Object[] getElements(Object inputElement) {
                    if (PlatformSelectionPage.this.myHideJson) {
                        List<ArduinoPackage> packages = BoardsManager.getPackages();
                        Collections.sort(packages);
                        return packages.toArray(new Object[packages.size()]);
                    }
                    List<ArduinoPlatformPackageIndex> indexFiles = BoardsManager.getPackageIndices();
                    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 ArduinoPlatformPackageIndex) {
                        Collection<ArduinoPackage> packages = ((ArduinoPlatformPackageIndex) parentElement).getPackages();
                        return packages.toArray(new Object[packages.size()]);
                    }
                    if (parentElement instanceof ArduinoPackage) {
                        Collection<ArduinoPlatform> platforms = ((ArduinoPackage) parentElement).getPlatforms();
                        ArduinoPlatform[] platformArray = platforms.toArray(new ArduinoPlatform[platforms.size()]);
                        Arrays.sort(platformArray);
                        return platformArray;
                    }
                    if (parentElement instanceof ArduinoPlatform) {
                        ArduinoPlatform platform = (ArduinoPlatform) parentElement;
                        ArduinoPackage parentPackage = platform.getParent();
                        ArduinoPlatformPackageIndex parentIndex = parentPackage.getPackageIndex();
                        return myShownPlatforms.get(parentIndex.getID()).get(parentPackage.getID()).get(platform.getID());
                    }
                    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 ArduinoPlatformPackageIndex) {
                        return ((ArduinoPlatformPackageIndex) element).getID();
                    }
                    if (element instanceof ArduinoPackage) {
                        // $NON-NLS-1$
                        String NULL = "NULL";
                        ArduinoPackage pkg = (ArduinoPackage) element;
                        String maintainer = pkg.getMaintainer();
                        String email = pkg.getEmail();
                        String weburlString = pkg.getWebsiteURL();
                        if (maintainer == null)
                            maintainer = NULL;
                        if (email == null)
                            email = NULL;
                        if (weburlString == null)
                            weburlString = NULL;
                        return Messages.packageTooltip.replace(Messages.MAINTAINER, maintainer).replace(Messages.EMAIL, email).replace(Messages.URL, weburlString);
                    }
                    if (element instanceof ArduinoPlatformVersion) {
                        return ((ArduinoPlatformVersion) element).getConcattenatedBoardNames();
                    }
                    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 ArduinoPlatformPackageIndex) {
                        cell.setText(((ArduinoPlatformPackageIndex) cell.getElement()).getName());
                    }
                    if (cell.getElement() instanceof ArduinoPackage) {
                        cell.setText(((ArduinoPackage) cell.getElement()).getName());
                    }
                    if (cell.getElement() instanceof ArduinoPlatform) {
                        cell.setText(((ArduinoPlatform) 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) ArduinoPlatformVersion(io.sloeber.core.api.Json.ArduinoPlatformVersion) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) Listener(org.eclipse.swt.widgets.Listener) ArduinoPackage(io.sloeber.core.api.Json.ArduinoPackage) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) 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) ArduinoPlatformPackageIndex(io.sloeber.core.api.Json.ArduinoPlatformPackageIndex) ArduinoPlatform(io.sloeber.core.api.Json.ArduinoPlatform) Composite(org.eclipse.swt.widgets.Composite) ICheckStateProvider(org.eclipse.jface.viewers.ICheckStateProvider) Text(org.eclipse.swt.widgets.Text) ViewerCell(org.eclipse.jface.viewers.ViewerCell) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Aggregations

ArduinoPlatformPackageIndex (io.sloeber.core.api.Json.ArduinoPlatformPackageIndex)4 ArduinoPackage (io.sloeber.core.api.Json.ArduinoPackage)2 Gson (com.google.gson.Gson)1 ArduinoPlatform (io.sloeber.core.api.Json.ArduinoPlatform)1 ArduinoPlatformVersion (io.sloeber.core.api.Json.ArduinoPlatformVersion)1 MyMultiStatus (io.sloeber.core.tools.MyMultiStatus)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 MalformedURLException (java.net.MalformedURLException)1 IStatus (org.eclipse.core.runtime.IStatus)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 Status (org.eclipse.core.runtime.Status)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