Skip to content

Commit 2220f85

Browse files
committed
Refactor ports
1 parent 709de84 commit 2220f85

9 files changed

Lines changed: 87 additions & 75 deletions

File tree

patternfx-core/src/main/java/com/techsenger/patternfx/core/AbstractDescriptor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
*
2727
* @author Pavel Castornii
2828
*/
29-
public abstract class AbstractDescriptor implements ReadOnlyDescriptor {
29+
public abstract class AbstractDescriptor implements DescriptorBase {
3030

31-
private static Function<ReadOnlyDescriptor, String> logPrefixResolver = (d) -> "[" + d.getFullName() + "]";
31+
private static Function<DescriptorBase, String> logPrefixResolver = (d) -> "[" + d.getFullName() + "]";
3232

33-
public static Function<ReadOnlyDescriptor, String> getLogPrefixResolver() {
33+
public static Function<DescriptorBase, String> getLogPrefixResolver() {
3434
return logPrefixResolver;
3535
}
3636

37-
public static void setLogPrefixResolver(Function<ReadOnlyDescriptor, String> logPrefixResolver) {
37+
public static void setLogPrefixResolver(Function<DescriptorBase, String> logPrefixResolver) {
3838
Objects.requireNonNull(logPrefixResolver, "logPrefixResolver can't be null");
3939
AbstractDescriptor.logPrefixResolver = logPrefixResolver;
4040
}

patternfx-core/src/main/java/com/techsenger/patternfx/core/AbstractObservableDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @author Pavel Castornii
2525
*/
2626
public abstract class AbstractObservableDescriptor extends AbstractDescriptor
27-
implements ObservableReadOnlyDescriptor {
27+
implements ObservableDescriptor {
2828

2929
protected AbstractObservableDescriptor(ComponentName name) {
3030
super(name);

patternfx-core/src/main/java/com/techsenger/patternfx/core/ReadOnlyDescriptor.java renamed to patternfx-core/src/main/java/com/techsenger/patternfx/core/DescriptorBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
* @author Pavel Castornii
2828
*/
29-
public interface ReadOnlyDescriptor {
29+
public interface DescriptorBase {
3030

3131
/**
3232
* Returns the logical name of the component. Multiple component instances can share the same {@link ComponentName}.

patternfx-core/src/main/java/com/techsenger/patternfx/core/ObservableReadOnlyDescriptor.java renamed to patternfx-core/src/main/java/com/techsenger/patternfx/core/ObservableDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
* @author Pavel Castornii
2525
*/
26-
public interface ObservableReadOnlyDescriptor extends ReadOnlyDescriptor {
26+
public interface ObservableDescriptor extends DescriptorBase {
2727

2828
/**
2929
* Returns the state property of the component.

patternfx-mvp/src/main/java/com/techsenger/patternfx/mvp/AbstractParentPresenter.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.techsenger.patternfx.mvp;
1818

1919
import com.google.errorprone.annotations.concurrent.LazyInit;
20-
import java.util.List;
2120
import org.slf4j.Logger;
2221
import org.slf4j.LoggerFactory;
2322

@@ -56,16 +55,6 @@ public void deinitializeTree() {
5655
}
5756
}
5857

59-
@Override
60-
public List<? extends ChildPort> getChildren() {
61-
return getComposer().getChildPorts();
62-
}
63-
64-
@Override
65-
public void requestFocus() {
66-
getView().requestFocus();
67-
}
68-
6958
@Override
7059
protected void postInitialize() {
7160
super.postInitialize();
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2024-2025 Pavel Castornii.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.techsenger.patternfx.mvp;
18+
19+
import com.techsenger.annotations.Unmodifiable;
20+
import com.techsenger.patternfx.core.TreeIterator;
21+
import java.util.List;
22+
import java.util.function.BiConsumer;
23+
24+
/**
25+
*
26+
* @author Pavel Castornii
27+
*/
28+
public interface ComposerBase {
29+
30+
/**
31+
* Returns an unmodifiable observable list of child components.
32+
*
33+
* @return a non-null, unmodifiable observable list of child components
34+
*/
35+
@Unmodifiable List<? extends ChildPort> getChildPorts();
36+
37+
/**
38+
* Returns an iterator that traverses the component subtree starting from this component in depth-first order.
39+
*
40+
* @return an {@link Iterator} that iterates over this component and all of its descendants
41+
*/
42+
TreeIterator<ParentPort> depthFirstIterator();
43+
44+
/**
45+
* Returns an iterator that traverses the component subtree starting from this component in breadth-first order.
46+
*
47+
* @return an {@link Iterator} that iterates over this component and all of its descendants
48+
*/
49+
TreeIterator<ParentPort> breadthFirstIterator();
50+
51+
/**
52+
* Returns a string representation of this component and all its descendants as a sub-tree with this
53+
* Presenter as root.
54+
*
55+
* @return a tree-formatted string representation of this component
56+
*/
57+
String toTreeString();
58+
59+
/**
60+
* Returns a string representation of this component and all its descendants as a sub-tree with this component
61+
* as root, allowing the caller to customize the string output for each component.
62+
*
63+
* <p>The provided {@code appender} is invoked for each component and is responsible for appending the
64+
* complete string representation of that component to the given {@link StringBuilder}. The tree structure and
65+
* line separation are handled by this method.
66+
*
67+
* @param appender a callback used to append the full string representation of each component.
68+
* @return a tree-formatted string representation of this component
69+
*/
70+
String toTreeString(BiConsumer<ParentPort, StringBuilder> appender);
71+
}

patternfx-mvp/src/main/java/com/techsenger/patternfx/mvp/ParentComposer.java

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,11 @@
1616

1717
package com.techsenger.patternfx.mvp;
1818

19-
import com.techsenger.annotations.Unmodifiable;
20-
import com.techsenger.patternfx.core.TreeIterator;
21-
import java.util.List;
22-
import java.util.function.BiConsumer;
23-
2419
/**
2520
*
2621
* @author Pavel Castornii
2722
*/
28-
public interface ParentComposer {
23+
public interface ParentComposer extends ComposerBase {
2924

3025
/**
3126
* Composes the static structure of this component by creating and adding its default child components. This
@@ -39,47 +34,4 @@ public interface ParentComposer {
3934
*
4035
*/
4136
void compose();
42-
43-
/**
44-
* Returns an unmodifiable observable list of child components.
45-
*
46-
* @return a non-null, unmodifiable observable list of child components
47-
*/
48-
@Unmodifiable List<? extends ChildPort> getChildPorts();
49-
50-
/**
51-
* Returns an iterator that traverses the component subtree starting from this component in depth-first order.
52-
*
53-
* @return an {@link Iterator} that iterates over this component and all of its descendants
54-
*/
55-
TreeIterator<ParentPort> depthFirstIterator();
56-
57-
/**
58-
* Returns an iterator that traverses the component subtree starting from this component in breadth-first order.
59-
*
60-
* @return an {@link Iterator} that iterates over this component and all of its descendants
61-
*/
62-
TreeIterator<ParentPort> breadthFirstIterator();
63-
64-
/**
65-
* Returns a string representation of this component and all its descendants as a sub-tree with this
66-
* Presenter as root.
67-
*
68-
* @return a tree-formatted string representation of this component
69-
*/
70-
String toTreeString();
71-
72-
/**
73-
* Returns a string representation of this component and all its descendants as a sub-tree with this component
74-
* as root, allowing the caller to customize the string output for each component.
75-
*
76-
* <p>The provided {@code appender} is invoked for each component and is responsible for appending the
77-
* complete string representation of that component to the given {@link StringBuilder}. The tree structure and
78-
* line separation are handled by this method.
79-
*
80-
* @param appender a callback used to append the full string representation of each component.
81-
* @return a tree-formatted string representation of this component
82-
*/
83-
String toTreeString(BiConsumer<ParentPort, StringBuilder> appender);
84-
8537
}

patternfx-mvp/src/main/java/com/techsenger/patternfx/mvp/ParentPort.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,21 @@
1616

1717
package com.techsenger.patternfx.mvp;
1818

19-
import com.techsenger.annotations.Unmodifiable;
20-
import com.techsenger.patternfx.core.ReadOnlyDescriptor;
21-
import java.util.List;
19+
import com.techsenger.patternfx.core.DescriptorBase;
2220

2321
/**
2422
*
2523
* @author Pavel Castornii
2624
*/
2725
public interface ParentPort {
2826

29-
void requestFocus();
30-
3127
/**
32-
* Returns an unmodifiable list of child components.
28+
* Returns the composer with minimal functionality.
3329
*/
34-
@Unmodifiable List<? extends ChildPort> getChildren();
30+
ComposerBase getComposer();
3531

36-
ReadOnlyDescriptor getDescriptor();
32+
/**
33+
* Returns the descriptor with minimal functionality.
34+
*/
35+
DescriptorBase getDescriptor();
3736
}

patternfx-mvp/src/main/java/com/techsenger/patternfx/mvp/ParentPresenter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public interface ParentPresenter<V extends ParentView, C extends ParentComposer>
2525
/**
2626
* Returns the composer.
2727
*/
28+
@Override
2829
C getComposer();
2930

3031
/**

0 commit comments

Comments
 (0)