This repository has been archived by the owner on Sep 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
125 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/de/adito/aditoweb/nbm/groupedtabs/actions/CloseGroupAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/de/adito/aditoweb/nbm/groupedtabs/actions/SortTabsAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/de/adito/aditoweb/nbm/groupedtabs/api/IDataObjectGroupProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<DataObject> | ||
{ | ||
/** | ||
* 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<String> group(@NotNull DataObject pDataObject); | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/de/adito/aditoweb/nbm/groupedtabs/impl/DefaultDataObjectGroupProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> 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<String> 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()); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/de/adito/aditoweb/nbm/groupedtabs/impl/GroupingTabDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/test/java/de/adito/aditoweb/nbm/groupedtabs/actions/CloseGroupActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/test/java/de/adito/aditoweb/nbm/groupedtabs/actions/SelectGroupActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/test/java/de/adito/aditoweb/nbm/groupedtabs/actions/SortTabsActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters