Skip to content

Commit e16136d

Browse files
committed
added new property control.
1 parent 721cdb0 commit e16136d

File tree

7 files changed

+114
-140
lines changed

7 files changed

+114
-140
lines changed

src/main/java/com/ss/editor/extension/loader/SceneLoader.java

Lines changed: 0 additions & 134 deletions
This file was deleted.

src/main/java/com/ss/editor/plugin/api/property/PropertyDefinition.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ public final class PropertyDefinition {
4747
@NotNull
4848
private final Array<?> options;
4949

50+
/**
51+
* The file extension to filter files/resources.
52+
*/
53+
@Nullable
54+
private final String extension;
55+
5056
/**
5157
* The min value.
5258
*/
@@ -66,6 +72,20 @@ public PropertyDefinition(@NotNull final EditablePropertyType propertyType, @Not
6672
this.max = Float.NaN;
6773
this.min = Float.NaN;
6874
this.options = EMPTY_OPTIONS;
75+
this.extension = null;
76+
}
77+
78+
public PropertyDefinition(@NotNull final EditablePropertyType propertyType, @NotNull final String name,
79+
@NotNull final String id, @Nullable final Object defaultValue,
80+
@Nullable final String extension) {
81+
this.propertyType = propertyType;
82+
this.name = name;
83+
this.id = id;
84+
this.defaultValue = defaultValue;
85+
this.max = Float.NaN;
86+
this.min = Float.NaN;
87+
this.options = EMPTY_OPTIONS;
88+
this.extension = extension;
6989
}
7090

7191
public PropertyDefinition(@NotNull final EditablePropertyType propertyType, @NotNull final String name,
@@ -78,6 +98,7 @@ public PropertyDefinition(@NotNull final EditablePropertyType propertyType, @Not
7898
this.options = options;
7999
this.max = Float.NaN;
80100
this.min = Float.NaN;
101+
this.extension = null;
81102
}
82103

83104
public PropertyDefinition(@NotNull final EditablePropertyType propertyType, @NotNull final String name,
@@ -90,6 +111,7 @@ public PropertyDefinition(@NotNull final EditablePropertyType propertyType, @Not
90111
this.min = min;
91112
this.max = max;
92113
this.options = EMPTY_OPTIONS;
114+
this.extension = null;
93115
}
94116

95117
/**
@@ -148,10 +170,20 @@ public float getMin() {
148170
return options;
149171
}
150172

173+
/**
174+
* Get the file extension to filter files/resources.
175+
*
176+
* @return the file extension to filter files/resources.
177+
*/
178+
@FromAnyThread
179+
public @Nullable String getExtension() {
180+
return extension;
181+
}
182+
151183
@Override
152184
public String toString() {
153185
return "PropertyDefinition{" + "propertyType=" + propertyType + ", name='" + name + '\'' + ", id='" + id +
154-
'\'' + ", defaultValue=" + defaultValue + ", options=" + options + ", min=" + min + ", max=" + max +
155-
'}';
186+
'\'' + ", defaultValue=" + defaultValue + ", options=" + options + ", extension='" + extension + '\'' +
187+
", min=" + min + ", max=" + max + '}';
156188
}
157189
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.ss.editor.plugin.api.property.control;
2+
3+
import static com.ss.editor.util.EditorUtil.getAssetFile;
4+
import static com.ss.editor.util.EditorUtil.toAssetPath;
5+
import static com.ss.rlib.util.ObjectUtils.notNull;
6+
import com.ss.editor.annotation.FXThread;
7+
import com.ss.editor.annotation.FromAnyThread;
8+
import com.ss.editor.plugin.api.property.PropertyDefinition;
9+
import com.ss.editor.ui.component.asset.tree.context.menu.action.NewFileAction;
10+
import com.ss.rlib.util.VarTable;
11+
import com.ss.rlib.util.array.Array;
12+
import com.ss.rlib.util.array.ArrayFactory;
13+
import javafx.scene.control.Label;
14+
import org.jetbrains.annotations.NotNull;
15+
16+
import java.nio.file.Path;
17+
import java.util.function.Predicate;
18+
19+
/**
20+
* The control to edit file values from asset folder.
21+
*
22+
* @author JavaSaBr
23+
*/
24+
public class FileAssetResourcePropertyControl extends AssetResourcePropertyEditorControl<Path> {
25+
26+
@NotNull
27+
private static final Predicate<Class<?>> ACTION_TESTER = type -> type == NewFileAction.class;
28+
29+
/**
30+
* The list of target extensions.
31+
*/
32+
@NotNull
33+
private final Array<String> extensions;
34+
35+
public FileAssetResourcePropertyControl(@NotNull final VarTable vars, @NotNull final PropertyDefinition definition,
36+
@NotNull final Runnable validationCallback) {
37+
super(vars, definition, validationCallback);
38+
this.extensions = ArrayFactory.asArray(notNull(definition.getExtension()));
39+
}
40+
41+
@Override
42+
@FromAnyThread
43+
public @NotNull Predicate<Class<?>> getActionTester() {
44+
return ACTION_TESTER;
45+
}
46+
47+
@Override
48+
@FromAnyThread
49+
protected @NotNull Array<String> getExtensions() {
50+
return extensions;
51+
}
52+
53+
@Override
54+
@FXThread
55+
protected void processSelect(@NotNull final Path file) {
56+
setPropertyValue(notNull(getAssetFile(file)));
57+
super.processSelect(file);
58+
}
59+
60+
@Override
61+
@FXThread
62+
protected void reload() {
63+
64+
final Path file = getPropertyValue();
65+
66+
final Label resourceLabel = getResourceLabel();
67+
resourceLabel.setText(file == null ? NOT_SELECTED : toAssetPath(file));
68+
69+
super.reload();
70+
}
71+
}

src/main/java/com/ss/editor/plugin/api/property/control/GeometryAssetResourcePropertyControl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
public class GeometryAssetResourcePropertyControl extends SpatialAssetResourcePropertyControl<Geometry> {
2020

2121
public GeometryAssetResourcePropertyControl(@NotNull final VarTable vars,
22-
@NotNull final PropertyDefinition definition,
23-
@NotNull final Runnable validationCallback) {
22+
@NotNull final PropertyDefinition definition,
23+
@NotNull final Runnable validationCallback) {
2424
super(vars, definition, validationCallback);
2525
}
2626

src/main/java/com/ss/editor/plugin/api/property/control/PropertyEditorControl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public class PropertyEditorControl<T> extends HBox {
3232
*/
3333
public static final double DEFAULT_FIELD_W_PERCENT = AbstractSimpleEditorDialog.DEFAULT_FIELD_W_PERCENT;
3434

35+
/**
36+
* The editor.
37+
*/
3538
@NotNull
3639
protected static final Editor EDITOR = Editor.getInstance();
3740

src/main/java/com/ss/editor/plugin/api/property/control/PropertyEditorControlFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public class PropertyEditorControlFactory {
4848
return new StringPropertyEditorControl(vars, definition, validation);
4949
case GEOMETRY_FROM_ASSET_FOLDER:
5050
return new GeometryAssetResourcePropertyControl(vars, definition, validation);
51+
case FILE_FROM_ASSET_FOLDER:
52+
return new FileAssetResourcePropertyControl(vars, definition, validation);
5153
case STRING_FROM_LIST:
5254
return new StringFromListPropertyEditorControl(vars, definition, validation, definition.getOptions());
5355
case AWT_FONT:

src/main/java/com/ss/editor/plugin/api/property/control/SpatialAssetResourcePropertyControl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public class SpatialAssetResourcePropertyControl<T extends Spatial> extends Asse
3737
}
3838

3939
public SpatialAssetResourcePropertyControl(@NotNull final VarTable vars,
40-
@NotNull final PropertyDefinition definition,
41-
@NotNull final Runnable validationCallback) {
40+
@NotNull final PropertyDefinition definition,
41+
@NotNull final Runnable validationCallback) {
4242
super(vars, definition, validationCallback);
4343
}
4444

0 commit comments

Comments
 (0)