From 066d6ec3539848e30bc080dc96bfc6e03cd25de2 Mon Sep 17 00:00:00 2001 From: Pascal Neub Date: Wed, 15 Mar 2023 09:33:54 +0100 Subject: [PATCH] chore: version 1.0.0 --- pom.xml | 11 ++- .../groupedtabs/actions/CloseGroupAction.java | 2 +- .../actions/SelectGroupAction.java | 3 +- .../groupedtabs/actions/SortTabsAction.java | 2 +- .../api/IDataObjectGroupProvider.java | 38 ++++++++++ .../impl/DefaultDataObjectGroupProvider.java | 71 +++++++++++++++++++ .../impl/GroupingTabDecorator.java | 2 +- .../actions/CloseGroupActionTest.java | 2 +- .../actions/SelectGroupActionTest.java | 2 +- .../actions/SortTabsActionTest.java | 2 +- 10 files changed, 125 insertions(+), 10 deletions(-) create mode 100644 src/main/java/de/adito/aditoweb/nbm/groupedtabs/api/IDataObjectGroupProvider.java create mode 100644 src/main/java/de/adito/aditoweb/nbm/groupedtabs/impl/DefaultDataObjectGroupProvider.java diff --git a/pom.xml b/pom.xml index 7a16ef8..7190d1d 100644 --- a/pom.xml +++ b/pom.xml @@ -55,9 +55,14 @@ - de.adito.nbm - de-adito-groupedtabs-api - RELEASE125-1.9.0 + org.netbeans.api + org-netbeans-modules-projectapi + ${netbeans.version} + + + org.netbeans.api + org-openide-filesystems + ${netbeans.version} diff --git a/src/main/java/de/adito/aditoweb/nbm/groupedtabs/actions/CloseGroupAction.java b/src/main/java/de/adito/aditoweb/nbm/groupedtabs/actions/CloseGroupAction.java index 4f89aeb..f253132 100644 --- a/src/main/java/de/adito/aditoweb/nbm/groupedtabs/actions/CloseGroupAction.java +++ b/src/main/java/de/adito/aditoweb/nbm/groupedtabs/actions/CloseGroupAction.java @@ -1,7 +1,7 @@ package de.adito.aditoweb.nbm.groupedtabs.actions; import de.adito.aditoweb.nbm.groupedtabs.NbUtils; -import de.adito.nbm.groupedtabs.api.IDataObjectGroupProvider; +import de.adito.aditoweb.nbm.groupedtabs.api.IDataObjectGroupProvider; import org.openide.awt.*; import org.openide.loaders.DataObject; import org.openide.util.*; diff --git a/src/main/java/de/adito/aditoweb/nbm/groupedtabs/actions/SelectGroupAction.java b/src/main/java/de/adito/aditoweb/nbm/groupedtabs/actions/SelectGroupAction.java index f403424..95f47f9 100644 --- a/src/main/java/de/adito/aditoweb/nbm/groupedtabs/actions/SelectGroupAction.java +++ b/src/main/java/de/adito/aditoweb/nbm/groupedtabs/actions/SelectGroupAction.java @@ -1,7 +1,7 @@ package de.adito.aditoweb.nbm.groupedtabs.actions; import de.adito.aditoweb.nbm.groupedtabs.*; -import de.adito.nbm.groupedtabs.api.IDataObjectGroupProvider; +import de.adito.aditoweb.nbm.groupedtabs.api.IDataObjectGroupProvider; import org.jetbrains.annotations.*; import org.openide.awt.*; import org.openide.loaders.DataObject; @@ -86,6 +86,7 @@ static Stream getGroupsInTopComponentMode(@NotNull TopComponent pTopComp // get the underlaying DataObject for the TopComponent and fetch the group using it .map(pTc -> pTc.getLookup().lookup(DataObject.class)) + .filter(Objects::nonNull) .map(groupProvider::group) // flatmap Optional diff --git a/src/main/java/de/adito/aditoweb/nbm/groupedtabs/actions/SortTabsAction.java b/src/main/java/de/adito/aditoweb/nbm/groupedtabs/actions/SortTabsAction.java index 449a738..1f9141d 100644 --- a/src/main/java/de/adito/aditoweb/nbm/groupedtabs/actions/SortTabsAction.java +++ b/src/main/java/de/adito/aditoweb/nbm/groupedtabs/actions/SortTabsAction.java @@ -1,7 +1,7 @@ package de.adito.aditoweb.nbm.groupedtabs.actions; import de.adito.aditoweb.nbm.groupedtabs.*; -import de.adito.nbm.groupedtabs.api.IDataObjectGroupProvider; +import de.adito.aditoweb.nbm.groupedtabs.api.IDataObjectGroupProvider; import org.jetbrains.annotations.NotNull; import org.openide.awt.*; import org.openide.loaders.DataObject; diff --git a/src/main/java/de/adito/aditoweb/nbm/groupedtabs/api/IDataObjectGroupProvider.java b/src/main/java/de/adito/aditoweb/nbm/groupedtabs/api/IDataObjectGroupProvider.java new file mode 100644 index 0000000..9cc0f62 --- /dev/null +++ b/src/main/java/de/adito/aditoweb/nbm/groupedtabs/api/IDataObjectGroupProvider.java @@ -0,0 +1,38 @@ +package de.adito.aditoweb.nbm.groupedtabs.api; + +import org.jetbrains.annotations.*; +import org.openide.loaders.DataObject; +import org.openide.util.Lookup; + +import java.util.*; + +/** + * Provide an implementation of this interface in the global lookup to alter the grouping behavior of DataObject tabs. + * Implementations also have to implement a Comparator for DataObjects, to sort DataObjects inside groups. + * + * @author p.neub, 27.02.2023 + */ +public interface IDataObjectGroupProvider extends Comparator +{ + /** + * Returns an instance of the {@link IDataObjectGroupProvider}. + * The default implementation is {@link de.adito.nbm.groupedtabs.impl.DefaultDataObjectGroupProvider} + * + * @return an instance of {@link IDataObjectGroupProvider} + */ + @NotNull + static IDataObjectGroupProvider getDefault() + { + return Objects.requireNonNull(Lookup.getDefault().lookup(IDataObjectGroupProvider.class)); + } + + /** + * Name of the group that the specified DataObject is part of. + * Return {@link Optional#empty()} if this DataObject does not belong to any specific group. + * + * @param pDataObject the DataObject + * @return the group of the DataObject + */ + @NotNull + Optional group(@NotNull DataObject pDataObject); +} diff --git a/src/main/java/de/adito/aditoweb/nbm/groupedtabs/impl/DefaultDataObjectGroupProvider.java b/src/main/java/de/adito/aditoweb/nbm/groupedtabs/impl/DefaultDataObjectGroupProvider.java new file mode 100644 index 0000000..2f7c4ed --- /dev/null +++ b/src/main/java/de/adito/aditoweb/nbm/groupedtabs/impl/DefaultDataObjectGroupProvider.java @@ -0,0 +1,71 @@ +package de.adito.aditoweb.nbm.groupedtabs.impl; + +import de.adito.aditoweb.nbm.groupedtabs.api.IDataObjectGroupProvider; +import org.jetbrains.annotations.NotNull; +import org.netbeans.api.project.*; +import org.openide.filesystems.FileObject; +import org.openide.loaders.DataObject; +import org.openide.util.lookup.ServiceProvider; + +import java.util.*; + +/** + * Default implementation of {@link IDataObjectGroupProvider}. + * All files that are inside the folder of an entity belong to one group. + * All other files belong to the default group. + * DataObjects are sorted by their path. + * + * @author p.neub, 28.02.2023 + */ +@ServiceProvider(service = IDataObjectGroupProvider.class) +public final class DefaultDataObjectGroupProvider implements IDataObjectGroupProvider +{ + @NotNull + @Override + public Optional group(@NotNull DataObject pDataObject) + { + final FileObject file = pDataObject.getPrimaryFile(); + return Optional.ofNullable(file) + .map(FileOwnerQuery::getOwner) + .map(Project::getProjectDirectory) + .map(FileObject::getPath) + .map(pProjectDir -> { + FileObject curr = file.getParent(); + while (true) + { + FileObject parent = curr.getParent(); + if (parent == null || pProjectDir.equals(parent.getPath())) + return null; + switch (parent.getName()) + { + case "entity": + return curr.getName(); + case "neonView": + return "#VIEW"; + case "neonDashboard": + return "#DASHBOARD"; + case "language": + return "#LANGUAGE"; + case "process": + return "#PROCESS"; + } + curr = parent; + } + }); + } + + @Override + public int compare(DataObject pFirst, DataObject pSecond) + { + final Optional group = group(pFirst); + if (group.isPresent()) + { + if (pFirst.getPrimaryFile().getName().equals(group.get())) + return -1; + if (pSecond.getPrimaryFile().getName().equals(group.get())) + return 1; + } + return pFirst.getPrimaryFile().getPath() + .compareToIgnoreCase(pSecond.getPrimaryFile().getPath()); + } +} diff --git a/src/main/java/de/adito/aditoweb/nbm/groupedtabs/impl/GroupingTabDecorator.java b/src/main/java/de/adito/aditoweb/nbm/groupedtabs/impl/GroupingTabDecorator.java index d02d1a0..4248f3b 100644 --- a/src/main/java/de/adito/aditoweb/nbm/groupedtabs/impl/GroupingTabDecorator.java +++ b/src/main/java/de/adito/aditoweb/nbm/groupedtabs/impl/GroupingTabDecorator.java @@ -1,7 +1,7 @@ package de.adito.aditoweb.nbm.groupedtabs.impl; import de.adito.aditoweb.nbm.groupedtabs.*; -import de.adito.nbm.groupedtabs.api.IDataObjectGroupProvider; +import de.adito.aditoweb.nbm.groupedtabs.api.IDataObjectGroupProvider; import org.netbeans.core.multitabs.TabDecorator; import org.netbeans.swing.tabcontrol.TabData; import org.openide.loaders.DataObject; diff --git a/src/test/java/de/adito/aditoweb/nbm/groupedtabs/actions/CloseGroupActionTest.java b/src/test/java/de/adito/aditoweb/nbm/groupedtabs/actions/CloseGroupActionTest.java index 438024e..2750100 100644 --- a/src/test/java/de/adito/aditoweb/nbm/groupedtabs/actions/CloseGroupActionTest.java +++ b/src/test/java/de/adito/aditoweb/nbm/groupedtabs/actions/CloseGroupActionTest.java @@ -1,6 +1,6 @@ package de.adito.aditoweb.nbm.groupedtabs.actions; -import de.adito.nbm.groupedtabs.api.IDataObjectGroupProvider; +import de.adito.aditoweb.nbm.groupedtabs.api.IDataObjectGroupProvider; import org.junit.jupiter.api.Test; import org.mockito.MockedStatic; import org.openide.loaders.DataObject; diff --git a/src/test/java/de/adito/aditoweb/nbm/groupedtabs/actions/SelectGroupActionTest.java b/src/test/java/de/adito/aditoweb/nbm/groupedtabs/actions/SelectGroupActionTest.java index 145322e..c4edf88 100644 --- a/src/test/java/de/adito/aditoweb/nbm/groupedtabs/actions/SelectGroupActionTest.java +++ b/src/test/java/de/adito/aditoweb/nbm/groupedtabs/actions/SelectGroupActionTest.java @@ -1,6 +1,6 @@ package de.adito.aditoweb.nbm.groupedtabs.actions; -import de.adito.nbm.groupedtabs.api.IDataObjectGroupProvider; +import de.adito.aditoweb.nbm.groupedtabs.api.IDataObjectGroupProvider; import org.junit.jupiter.api.Test; import org.mockito.*; import org.openide.loaders.DataObject; diff --git a/src/test/java/de/adito/aditoweb/nbm/groupedtabs/actions/SortTabsActionTest.java b/src/test/java/de/adito/aditoweb/nbm/groupedtabs/actions/SortTabsActionTest.java index ba7c274..3dae148 100644 --- a/src/test/java/de/adito/aditoweb/nbm/groupedtabs/actions/SortTabsActionTest.java +++ b/src/test/java/de/adito/aditoweb/nbm/groupedtabs/actions/SortTabsActionTest.java @@ -1,6 +1,6 @@ package de.adito.aditoweb.nbm.groupedtabs.actions; -import de.adito.nbm.groupedtabs.api.IDataObjectGroupProvider; +import de.adito.aditoweb.nbm.groupedtabs.api.IDataObjectGroupProvider; import lombok.SneakyThrows; import org.junit.jupiter.api.*; import org.mockito.MockedStatic;