From 0f1493dc75083309bc321bad9b2218f72767ce0b Mon Sep 17 00:00:00 2001 From: jantje Date: Tue, 9 Nov 2021 02:05:35 +0100 Subject: [PATCH] #1339 moved libraryTree class to gui still need to do the install part removed the ([index name]) from the library name and added the indexname to the tooltip Added a (can update) tag when a newer version is available --- io.sloeber.core/META-INF/MANIFEST.MF | 1 + .../api/Json/library/LibraryIndexJson.java | 13 +- .../core/api/Json/library/LibraryJson.java | 12 +- .../io/sloeber/core/api/LibraryManager.java | 207 +----------- .../src/io/sloeber/core/api/Node.java | 11 - .../src/io/sloeber/core/tools/Libraries.java | 7 +- .../ui/preferences/LibrarySelectionPage.java | 300 ++++++++++++++---- 7 files changed, 273 insertions(+), 278 deletions(-) delete mode 100644 io.sloeber.core/src/io/sloeber/core/api/Node.java diff --git a/io.sloeber.core/META-INF/MANIFEST.MF b/io.sloeber.core/META-INF/MANIFEST.MF index b2258ad1e..1eb0a1000 100644 --- a/io.sloeber.core/META-INF/MANIFEST.MF +++ b/io.sloeber.core/META-INF/MANIFEST.MF @@ -32,6 +32,7 @@ Export-Package: cc.arduino.packages;x-internal:=true, cc.arduino.packages.ssh;x-internal:=true, io.sloeber.core;x-friends:="io.sloeber.tests", io.sloeber.core.api, + io.sloeber.core.api.Json.library, io.sloeber.core.api.Json.packages, io.sloeber.core.builder;x-internal:=true, io.sloeber.core.common;x-friends:="io.sloeber.tests", diff --git a/io.sloeber.core/src/io/sloeber/core/api/Json/library/LibraryIndexJson.java b/io.sloeber.core/src/io/sloeber/core/api/Json/library/LibraryIndexJson.java index ac9ef0e26..a7a768116 100644 --- a/io.sloeber.core/src/io/sloeber/core/api/Json/library/LibraryIndexJson.java +++ b/io.sloeber.core/src/io/sloeber/core/api/Json/library/LibraryIndexJson.java @@ -20,7 +20,6 @@ import com.google.gson.annotations.JsonAdapter; import io.sloeber.core.api.Defaults; -import io.sloeber.core.api.LibraryDescriptor; import io.sloeber.core.api.VersionNumber; /** @@ -123,11 +122,11 @@ public Map getLatestLibraries() { * * @return */ - public Map getLatestInstallableLibraries() { - Map ret = new HashMap<>(); + public Map getLatestInstallableLibraries() { + Map ret = new HashMap<>(); for (Entry curLibrary : this.latestLibs.entrySet()) { if (!curLibrary.getValue().isAVersionInstalled()) { - ret.put(curLibrary.getKey(), new LibraryDescriptor(curLibrary.getValue())); + ret.put(curLibrary.getKey(), curLibrary.getValue()); } } return ret; @@ -159,15 +158,15 @@ public String getName() { * * @return */ - public Map getLatestInstallableLibraries(Set libNames) { - Map ret = new HashMap<>(); + public Map getLatestInstallableLibraries(Set libNames) { + Map ret = new HashMap<>(); if (libNames.isEmpty()) { return ret; } for (Entry curLibrary : this.latestLibs.entrySet()) { if (libNames.contains(curLibrary.getKey())) { if (!curLibrary.getValue().isAVersionInstalled()) { - ret.put(curLibrary.getKey(), new LibraryDescriptor(curLibrary.getValue())); + ret.put(curLibrary.getKey(), curLibrary.getValue()); } } } diff --git a/io.sloeber.core/src/io/sloeber/core/api/Json/library/LibraryJson.java b/io.sloeber.core/src/io/sloeber/core/api/Json/library/LibraryJson.java index fb18e89c4..7d0273943 100644 --- a/io.sloeber.core/src/io/sloeber/core/api/Json/library/LibraryJson.java +++ b/io.sloeber.core/src/io/sloeber/core/api/Json/library/LibraryJson.java @@ -52,12 +52,15 @@ public class LibraryJson implements Comparable { private String archiveFileName; private int size; private String checksum; + private LibraryIndexJson myParent; + public static final String LIBRARY_SOURCE_FODER = "src"; //$NON-NLS-1$ @SuppressWarnings("nls") public LibraryJson(JsonElement json, LibraryIndexJson libraryIndexJson) { JsonObject jsonObject = json.getAsJsonObject(); try { + myParent = libraryIndexJson; name = getSafeString(jsonObject, "name"); version = getSafeVersion(jsonObject, "version"); author = getSafeString(jsonObject, "author"); @@ -221,7 +224,11 @@ public Collection getSources(IProject project) { @Override public int compareTo(LibraryJson other) { - return this.name.compareTo(other.name); + int ret = this.name.compareTo(other.name); + if (ret == 0) { + ret = this.version.compareTo(other.version); + } + return ret; } /** @@ -247,4 +254,7 @@ public IStatus remove(IProgressMonitor monitor) { return Status.OK_STATUS; } + public LibraryIndexJson getParent() { + return myParent; + } } diff --git a/io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java b/io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java index f58a960d2..d5ec98752 100644 --- a/io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java +++ b/io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java @@ -8,11 +8,9 @@ import java.io.IOException; import java.io.Reader; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; @@ -62,194 +60,15 @@ static public List getLibraryIndices() { return libraryIndices; } - public static LibraryTree getLibraryTree() { - return new LibraryTree(); - - } - - public static class LibraryTree { - - private TreeMap categories = new TreeMap<>(); - - public class Category implements Comparable, Node { - private String name; - protected TreeMap libraries = new TreeMap<>(); - - public Category(String name) { - this.name = name; - } - - @Override - public String getName() { - return this.name; - } - - public Collection getLibraries() { - return this.libraries.values(); - } - - @Override - public int compareTo(Category other) { - return this.name.compareTo(other.name); - } - - @Override - public boolean hasChildren() { - return !this.libraries.isEmpty(); - } - - @Override - public Object[] getChildren() { - return this.libraries.values().toArray(); - } - - @Override - public Object getParent() { - return LibraryTree.this; - } - } - - public class Library implements Comparable, Node { - private String name; - private String indexName; - private Category category; - protected TreeSet versions = new TreeSet<>(); - protected VersionNumber version; - private String tooltip; - - public Library(Category category, String name, String indexName, String tooltip) { - this.category = category; - this.name = name; - this.tooltip = tooltip; - this.indexName = indexName; - } - - public Collection getVersions() { - return this.versions; - } - - @Override - public String getName() { - return name; - } - - public String getTooltip() { - return tooltip; - } - - public VersionNumber getLatest() { - return versions.last(); - } - - public VersionNumber getVersion() { - return version; - } - - public String getIndexName() { - return indexName; - } - - public void setVersion(VersionNumber version) { - this.version = version; - } - - @Override - public int compareTo(Library other) { - return this.name.compareTo(other.name); - } - - @Override - public boolean hasChildren() { - return false; - } - - @Override - public Object[] getChildren() { - return null; - } - - @Override - public Object getParent() { - return this.category; - } - } - - public LibraryTree() { - for (LibraryIndexJson libraryIndex : getLibraryIndices()) { - for (String categoryName : libraryIndex.getCategories()) { - Category category = this.categories.get(categoryName); - if (category == null) { - category = new Category(categoryName); - this.categories.put(category.getName(), category); - } - for (io.sloeber.core.api.Json.library.LibraryJson library : libraryIndex - .getLibraries(categoryName)) { - Library lib = category.libraries.get(library.getName() + " (" + libraryIndex.getName() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ - if (lib == null) { - String builder = "Architectures:" + library.getArchitectures().toString() + "\n\n" //$NON-NLS-1$ //$NON-NLS-2$ - + library.getSentence(); - lib = new Library(category, library.getName(), libraryIndex.getName(), builder); - category.libraries.put(library.getName() + " (" + libraryIndex.getName() + ")", lib); //$NON-NLS-1$//$NON-NLS-2$ - } - lib.versions.add(library.getVersion()); - if (library.isInstalled()) { - lib.version = library.getVersion(); - } - } - } - } - } - - public Collection getCategories() { - return this.categories.values(); - } - - public Collection getAllLibraries() { - Set all = new TreeSet<>(); - for (Category category : this.categories.values()) { - all.addAll(category.getLibraries()); - } - return all; - } - - private static LibraryIndexJson findLibraryIndex(String name) { - for (LibraryIndexJson libraryIndex : getLibraryIndices()) { - if (libraryIndex.getName().equals(name)) - return libraryIndex; - } - return null; - } - - public void reset() { - for (Library library : this.getAllLibraries()) { - LibraryIndexJson libraryIndex = findLibraryIndex(library.getIndexName()); - - if (libraryIndex != null) { - io.sloeber.core.api.Json.library.LibraryJson installed = libraryIndex - .getInstalledLibrary(library.getName()); - library.setVersion(installed != null ? installed.getVersion() : null); - } - } + public static IStatus setLibraryTree(List removeLibs, List addLibs, + IProgressMonitor monitor, MultiStatus status) { + for (LibraryJson lib : removeLibs) { + status.add(lib.remove(monitor)); + if (monitor.isCanceled()) + return Status.CANCEL_STATUS; } - - } - - public static IStatus setLibraryTree(LibraryTree libs, IProgressMonitor monitor, MultiStatus status) { - for (LibraryTree.Library lib : libs.getAllLibraries()) { - LibraryIndexJson libraryIndex = getLibraryIndex(lib.getIndexName()); - - if (libraryIndex != null) { - io.sloeber.core.api.Json.library.LibraryJson toRemove = libraryIndex.getInstalledLibrary(lib.getName()); - if (toRemove != null && !toRemove.getVersion().equals(lib.getVersion())) { - status.add(toRemove.remove(monitor)); - } - io.sloeber.core.api.Json.library.LibraryJson toInstall = libraryIndex.getLibrary(lib.getName(), - lib.getVersion()); - if (toInstall != null && !toInstall.isInstalled()) { - status.add(toInstall.install(monitor)); - } - } - + for (LibraryJson lib : addLibs) { + status.add(lib.install(monitor)); if (monitor.isCanceled()) return Status.CANCEL_STATUS; } @@ -307,10 +126,10 @@ static public void loadJson(File jsonFile) { public static void installLibrary(String libName) { Set libNamesToInstall = new TreeSet<>(); libNamesToInstall.add(libName); - Map libsToInstall = LibraryManager.getLatestInstallableLibraries(libNamesToInstall); + Map libsToInstall = LibraryManager.getLatestInstallableLibraries(libNamesToInstall); if (!libsToInstall.isEmpty()) { - for (Entry curLib : libsToInstall.entrySet()) { - curLib.getValue().toLibrary().install(new NullProgressMonitor()); + for (LibraryJson curLib : libsToInstall.values()) { + curLib.install(new NullProgressMonitor()); } } } @@ -371,9 +190,9 @@ public static void removeAllLibs() { } } - public static Map getLatestInstallableLibraries(Set libnames) { + public static Map getLatestInstallableLibraries(Set libnames) { Set remainingLibNames = new TreeSet<>(libnames); - Map ret = new HashMap<>(); + Map ret = new HashMap<>(); for (LibraryIndexJson libraryIndex : libraryIndices) { ret.putAll(libraryIndex.getLatestInstallableLibraries(remainingLibNames)); remainingLibNames.removeAll(ret.keySet()); diff --git a/io.sloeber.core/src/io/sloeber/core/api/Node.java b/io.sloeber.core/src/io/sloeber/core/api/Node.java deleted file mode 100644 index d5c13d56e..000000000 --- a/io.sloeber.core/src/io/sloeber/core/api/Node.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.sloeber.core.api; - -public interface Node { - boolean hasChildren(); - - Object[] getChildren(); - - Object getParent(); - - String getName(); -} \ No newline at end of file diff --git a/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java b/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java index d50cc46a1..d6a00db95 100644 --- a/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java +++ b/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java @@ -38,7 +38,6 @@ import io.sloeber.core.api.BoardDescription; import io.sloeber.core.api.IInstallLibraryHandler; -import io.sloeber.core.api.LibraryDescriptor; import io.sloeber.core.api.LibraryManager; import io.sloeber.core.api.SloeberProject; import io.sloeber.core.api.VersionNumber; @@ -423,7 +422,7 @@ public static void checkLibraries(IProject affectedProject) { if (!uninstalledIncludedHeaders.isEmpty()) { // some libraries may need to be installed - Map availableLibs = LibraryManager + Map availableLibs = LibraryManager .getLatestInstallableLibraries(uninstalledIncludedHeaders); if (!availableLibs.isEmpty()) { @@ -432,8 +431,8 @@ public static void checkLibraries(IProject affectedProject) { // be some user // interaction availableLibs = installHandler.selectLibrariesToInstall(availableLibs); - for (Entry curLib : availableLibs.entrySet()) { - curLib.getValue().toLibrary().install(new NullProgressMonitor()); + for (Entry curLib : availableLibs.entrySet()) { + curLib.getValue().install(new NullProgressMonitor()); } } } diff --git a/io.sloeber.ui/src/io/sloeber/ui/preferences/LibrarySelectionPage.java b/io.sloeber.ui/src/io/sloeber/ui/preferences/LibrarySelectionPage.java index 1910d6855..f013ff665 100644 --- a/io.sloeber.ui/src/io/sloeber/ui/preferences/LibrarySelectionPage.java +++ b/io.sloeber.ui/src/io/sloeber/ui/preferences/LibrarySelectionPage.java @@ -2,6 +2,11 @@ import static io.sloeber.ui.Activator.*; +import java.util.Collection; +import java.util.Collections; +import java.util.TreeMap; +import java.util.TreeSet; + import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; @@ -37,9 +42,9 @@ import org.eclipse.ui.dialogs.PatternFilter; import io.sloeber.core.api.LibraryManager; -import io.sloeber.core.api.LibraryManager.LibraryTree; -import io.sloeber.core.api.Node; import io.sloeber.core.api.VersionNumber; +import io.sloeber.core.api.Json.library.LibraryIndexJson; +import io.sloeber.core.api.Json.library.LibraryJson; import io.sloeber.ui.Messages; public class LibrarySelectionPage extends PreferencePage implements IWorkbenchPreferencePage { @@ -48,22 +53,207 @@ public class LibrarySelectionPage extends PreferencePage implements IWorkbenchPr private boolean isJobRunning = false; protected TreeViewer viewer; protected TreeEditor editor; - protected LibraryTree libs = LibraryManager.getLibraryTree(); + protected LibraryTree libs = new LibraryTree(); final static String emptyString = ""; //$NON-NLS-1$ + final static String blankLine = "\n\n";//$NON-NLS-1$ + final static String canUpdateLabel = " (update)"; - @Override - public void init(IWorkbench workbench) { - // nothing needed here + public interface Node { + boolean hasChildren(); + + Object[] getChildren(); + + Object getParent(); + + String getName(); } - @Override - protected void performDefaults() { - this.libs.reset(); - this.viewer.refresh(); - if (this.editor != null && this.editor.getEditor() != null) { - this.editor.getEditor().dispose(); + public static class LibraryTree implements Node { + + private TreeMap categories = new TreeMap<>(); + + public class Category implements Comparable, Node { + private String name; + private TreeMap libraries = new TreeMap<>(); + + public Category(String name) { + this.name = name; + } + + @Override + public String getName() { + return this.name; + } + + public Collection getLibraries() { + return this.libraries.values(); + } + + @Override + public int compareTo(Category other) { + return this.name.compareTo(other.name); + } + + @Override + public boolean hasChildren() { + return !this.libraries.isEmpty(); + } + + @Override + public Object[] getChildren() { + return this.libraries.values().toArray(); + } + + @Override + public Object getParent() { + return LibraryTree.this; + } + } + + public class Library implements Comparable, Node { + private String myName; + private Category myParent; + protected TreeSet myVersions = new TreeSet<>(Collections.reverseOrder()); + protected LibraryJson myInstalledVersion; + + public Library(Category category, String name) { + myParent = category; + myName = name; + } + + public Collection getVersions() { + return myVersions; + } + + @Override + public String getName() { + if (canUpdate()) { + return myName + canUpdateLabel; + } + return myName; + } + + public boolean canUpdate() { + return myInstalledVersion == null ? false : getLatest().compareTo(myInstalledVersion) != 0; + } + + private String myTooltip = null; + + public String getTooltip() { + if (myTooltip == null) { + LibraryJson library = getLatest(); + myTooltip = "Architectures:" + library.getArchitectures().toString() + blankLine + + library.getSentence() + blankLine + "provided by: " + library.getParent().getName(); + } + return myTooltip; + } + + public LibraryJson getLatest() { + return myVersions.first(); + } + + public LibraryJson getVersion() { + return myInstalledVersion; + } + + public void setVersion(LibraryJson version) { + myInstalledVersion = version; + } + + public void setVersion(VersionNumber versionNumber) { + if (versionNumber == null) { + myInstalledVersion = null; + } + for (LibraryJson curLib : myVersions) { + if (curLib.getVersion().compareTo(versionNumber) == 0) { + myInstalledVersion = curLib; + return; + } + } + // this should not happen + myInstalledVersion = null; + } + + @Override + public int compareTo(Library other) { + return myName.compareTo(other.myName); + } + + @Override + public boolean hasChildren() { + return false; + } + + @Override + public Object[] getChildren() { + return null; + } + + @Override + public Object getParent() { + return myParent; + } + + public String getVersionString() { + if (myInstalledVersion == null) { + return emptyString; + } + return myInstalledVersion.getVersion().toString(); + } + + } + + public LibraryTree() { + for (LibraryIndexJson libraryIndex : LibraryManager.getLibraryIndices()) { + for (String categoryName : libraryIndex.getCategories()) { + Category category = this.categories.get(categoryName); + if (category == null) { + category = new Category(categoryName); + this.categories.put(category.getName(), category); + } + for (LibraryJson library : libraryIndex.getLibraries(categoryName)) { + Library lib = category.libraries.get(library.getName()); + if (lib == null) { + lib = new Library(category, library.getName()); + category.libraries.put(library.getName(), lib); + } + lib.myVersions.add(library); + if (library.isInstalled()) { + lib.myInstalledVersion = library; + } + } + } + } + } + + private Collection getCategories() { + return this.categories.values(); + } + + @Override + public boolean hasChildren() { + return getCategories().isEmpty(); + } + + @Override + public Object[] getChildren() { + return getCategories().toArray(); + } + + @Override + public Object getParent() { + return null; + } + + @Override + public String getName() { + return null; } - super.performDefaults(); + } + + @Override + public void init(IWorkbench workbench) { + // nothing needed here } @Override @@ -83,31 +273,32 @@ protected Control createContents(Composite parent) { @Override public boolean performOk() { - if (this.isJobRunning == false) { - this.isJobRunning = true; - Job job = new Job(Messages.ui_Adopting_arduino_libraries) { - @Override - protected IStatus run(IProgressMonitor monitor) { - MultiStatus status = new MultiStatus(PLUGIN_ID, 0, Messages.ui_installing_arduino_libraries, null); - return LibraryManager.setLibraryTree(LibrarySelectionPage.this.libs, monitor, status); - } - }; - job.addJobChangeListener(new JobChangeAdapter() { + if (this.isJobRunning == true) { + MessageDialog.openInformation(getShell(), "Library Manager", //$NON-NLS-1$ + "Library Manager is busy. Please wait some time..."); //$NON-NLS-1$ + return false; + } + this.isJobRunning = true; + Job job = new Job(Messages.ui_Adopting_arduino_libraries) { + @Override + protected IStatus run(IProgressMonitor monitor) { + MultiStatus status = new MultiStatus(PLUGIN_ID, 0, Messages.ui_installing_arduino_libraries, null); + // return LibraryManager.setLibraryTree(LibrarySelectionPage.this.libs, monitor, + // status); + return null; + } + }; + job.addJobChangeListener(new JobChangeAdapter() { - @Override - public void done(IJobChangeEvent event) { - LibrarySelectionPage.this.isJobRunning = false; - } + @Override + public void done(IJobChangeEvent event) { + LibrarySelectionPage.this.isJobRunning = false; + } - }); - job.setUser(true); - job.schedule(); - return true; - } else { - MessageDialog.openInformation(getShell(), "Library Manager", - "Library Manager is busy. Please wait some time..."); - } - return false; + }); + job.setUser(true); + job.schedule(); + return true; } public void createTree(Composite parent) { @@ -174,7 +365,7 @@ public void widgetSelected(SelectionEvent event) { if (item.getChecked()) { child.setVersion(child.getLatest()); } else { - child.setVersion(null); + child.setVersion((LibraryJson) null); } } for (TreeItem child : item.getItems()) { @@ -191,7 +382,7 @@ public void widgetSelected(SelectionEvent event) { .setVersion(((LibraryTree.Library) item.getData()).getLatest()); item.setText(1, ((LibraryTree.Library) item.getData()).getLatest().toString()); } else { - ((LibraryTree.Library) item.getData()).setVersion(null); + ((LibraryTree.Library) item.getData()).setVersion((LibraryJson) null); item.setText(1, emptyString); } verifySubtreeCheckStatus(item.getParentItem()); @@ -200,8 +391,8 @@ public void widgetSelected(SelectionEvent event) { if (item != null && item.getItemCount() == 0 && item.getChecked()) { // Create the dropdown and add data to it final CCombo combo = new CCombo(LibrarySelectionPage.this.viewer.getTree(), SWT.READ_ONLY); - for (VersionNumber version1 : ((LibraryTree.Library) item.getData()).getVersions()) { - combo.add(version1.toString()); + for (LibraryJson version1 : ((LibraryTree.Library) item.getData()).getVersions()) { + combo.add(version1.getVersion().toString()); } // Select the previously selected item from the cell @@ -219,8 +410,10 @@ public void widgetSelected(SelectionEvent event) { combo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event1) { - ((LibraryTree.Library) item.getData()).setVersion(new VersionNumber(combo.getText())); + LibraryTree.Library lib = (LibraryTree.Library) item.getData(); + lib.setVersion(new VersionNumber(combo.getText())); item.setText(1, combo.getText()); + item.setText(0, lib.getName()); // Item selected: end the editing session combo.dispose(); } @@ -269,13 +462,12 @@ public static String getColumnText(Object element, int col) { switch (col) { case 0: if (element instanceof LibraryTree.Library) { - return ((LibraryTree.Library) element).getName() + " (" //$NON-NLS-1$ - + ((LibraryTree.Library) element).getIndexName() + ")"; //$NON-NLS-1$ + return ((LibraryTree.Library) element).getName(); } return emptyString; case 1: if (element instanceof LibraryTree.Library) { - return ((LibraryTree.Library) element).getVersion().toString(); + return ((LibraryTree.Library) element).getVersionString(); } return emptyString; default: @@ -302,14 +494,9 @@ public int getToolTipTimeDisplayed(Object object) { @Override public void update(ViewerCell cell) { if (cell.getColumnIndex() == 0) { - if (cell.getElement() instanceof LibraryTree.Library) { - cell.setText(((LibraryTree.Library) cell.getElement()).getName() + " (" //$NON-NLS-1$ - + ((LibraryTree.Library) cell.getElement()).getIndexName() + ")"); //$NON-NLS-1$ - } else { - cell.setText(((Node) cell.getElement()).getName()); - } + cell.setText(((Node) cell.getElement()).getName()); } else if (cell.getElement() instanceof LibraryTree.Library) { - cell.setText(((LibraryTree.Library) cell.getElement()).getVersion().toString()); + cell.setText(((LibraryTree.Library) cell.getElement()).getVersionString()); } else { cell.setText(null); } @@ -361,25 +548,16 @@ public Object[] getChildren(Object node) { @Override public Object getParent(Object node) { - if (node instanceof Node) { - return ((Node) node).getParent(); - } - return null; + return ((Node) node).getParent(); } @Override public boolean hasChildren(Object node) { - if (node instanceof LibraryTree) { - return !((LibraryTree) node).getCategories().isEmpty(); - } return ((Node) node).hasChildren(); } @Override public Object[] getElements(Object node) { - if (node instanceof LibraryTree) { - return ((LibraryTree) node).getCategories().toArray(); - } return getChildren(node); }