Skip to content
This repository has been archived by the owner on Sep 4, 2023. It is now read-only.

Commit

Permalink
chore: version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pas-n committed Mar 15, 2023
1 parent 20624e6 commit 066d6ec
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 10 deletions.
11 changes: 8 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@
</dependency>

<dependency>
<groupId>de.adito.nbm</groupId>
<artifactId>de-adito-groupedtabs-api</artifactId>
<version>RELEASE125-1.9.0</version>
<groupId>org.netbeans.api</groupId>
<artifactId>org-netbeans-modules-projectapi</artifactId>
<version>${netbeans.version}</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-filesystems</artifactId>
<version>${netbeans.version}</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -86,6 +86,7 @@ static Stream<String> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
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);
}
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());
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 066d6ec

Please sign in to comment.