Search in sources :

Example 6 with ArduinoPlatform

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

the class Arduino method getAllmBedBoardNames.

private static List<String> getAllmBedBoardNames() {
    List<String> ret = new LinkedList<>();
    ArduinoPackage arduinoPkg = BoardsManager.getPackageByProvider(providerArduino);
    for (ArduinoPlatform curPlatform : arduinoPkg.getPlatforms()) {
        if (curPlatform.getArchitecture().equals(MBEDArchitectureName)) {
            ArduinoPlatformVersion curPlatformVersion = curPlatform.getNewestInstalled();
            if (curPlatformVersion != null) {
                List<BoardDescription> boardDescriptions = BoardDescription.makeBoardDescriptors(curPlatformVersion.getBoardsFile());
                for (BoardDescription curBoardDesc : boardDescriptions) {
                    ret.add(curBoardDesc.getBoardName());
                }
            }
        }
    }
    return ret;
}
Also used : ArduinoPlatformVersion(io.sloeber.core.api.Json.ArduinoPlatformVersion) BoardDescription(io.sloeber.core.api.BoardDescription) ArduinoPlatform(io.sloeber.core.api.Json.ArduinoPlatform) ArduinoPackage(io.sloeber.core.api.Json.ArduinoPackage) LinkedList(java.util.LinkedList)

Example 7 with ArduinoPlatform

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

the class MCUBoard method getAllBoards.

public static List<MCUBoard> getAllBoards(String provider, MCUBoard creator) {
    List<MCUBoard> ret = new LinkedList<>();
    ArduinoPackage arduinoPkg = BoardsManager.getPackageByProvider(provider);
    for (ArduinoPlatform curPlatform : arduinoPkg.getPlatforms()) {
        ArduinoPlatformVersion curPlatformVersion = curPlatform.getNewestInstalled();
        if (curPlatformVersion != null) {
            List<BoardDescription> boardDescriptions = BoardDescription.makeBoardDescriptors(curPlatformVersion.getBoardsFile());
            for (BoardDescription curBoardDesc : boardDescriptions) {
                ret.add(creator.createMCUBoard(curBoardDesc));
            }
        }
    }
    return ret;
}
Also used : ArduinoPlatformVersion(io.sloeber.core.api.Json.ArduinoPlatformVersion) BoardDescription(io.sloeber.core.api.BoardDescription) ArduinoPlatform(io.sloeber.core.api.Json.ArduinoPlatform) ArduinoPackage(io.sloeber.core.api.Json.ArduinoPackage) LinkedList(java.util.LinkedList)

Example 8 with ArduinoPlatform

use of io.sloeber.core.api.Json.ArduinoPlatform 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

ArduinoPlatform (io.sloeber.core.api.Json.ArduinoPlatform)8 ArduinoPackage (io.sloeber.core.api.Json.ArduinoPackage)6 ArduinoPlatformVersion (io.sloeber.core.api.Json.ArduinoPlatformVersion)6 MyMultiStatus (io.sloeber.core.tools.MyMultiStatus)3 IOException (java.io.IOException)3 MalformedURLException (java.net.MalformedURLException)3 IStatus (org.eclipse.core.runtime.IStatus)3 MultiStatus (org.eclipse.core.runtime.MultiStatus)3 Status (org.eclipse.core.runtime.Status)3 BoardDescription (io.sloeber.core.api.BoardDescription)2 LinkedList (java.util.LinkedList)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ArduinoPlatformPackageIndex (io.sloeber.core.api.Json.ArduinoPlatformPackageIndex)1 File (java.io.File)1 IPath (org.eclipse.core.runtime.IPath)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