22
33import static com .ss .editor .manager .FileIconManager .DEFAULT_FILE_ICON_SIZE ;
44import static java .util .Collections .singletonList ;
5- import com .ss .editor .config .EditorConfig ;
65import com .ss .editor .manager .FileIconManager ;
76import com .ss .editor .ui .component .asset .tree .resource .FolderResourceElement ;
87import com .ss .editor .ui .component .asset .tree .resource .LoadingResourceElement ;
2322import java .util .function .Consumer ;
2423
2524/**
26- * The implementation of the cell for {@link TreeView} for showing a resource.
25+ * The implementation of the cell for {@link TreeView} to show resource.
2726 *
2827 * @author JavaSaBr
2928 */
@@ -33,16 +32,16 @@ public class ResourceTreeCell extends TreeCell<ResourceElement> {
3332 private static final FileIconManager ICON_MANAGER = FileIconManager .getInstance ();
3433
3534 /**
36- * The tooltip of this resource .
35+ * The icon .
3736 */
3837 @ NotNull
39- private final Tooltip tooltip ;
38+ private final ImageView icon ;
4039
4140 /**
42- * The icon .
41+ * The tooltip of this resource .
4342 */
44- @ NotNull
45- private final ImageView icon ;
43+ @ Nullable
44+ private Tooltip tooltip ;
4645
4746 /**
4847 * Instantiates a new Resource tree cell.
@@ -100,35 +99,28 @@ private void processClick(@NotNull final MouseEvent event) {
10099 final ResourceTree treeView = (ResourceTree ) getTreeView ();
101100
102101 if (event .getButton () == MouseButton .SECONDARY ) {
103-
104102 final ContextMenu contextMenu = treeView .getContextMenu (item );
105103 if (contextMenu == null ) return ;
106-
107104 contextMenu .show (this , Side .BOTTOM , 0 , 0 );
108-
109105 } else if (!isFolder && event .getButton () == MouseButton .PRIMARY && event .getClickCount () > 1 ) {
110-
111106 final Consumer <ResourceElement > openFunction = treeView .getOpenFunction ();
112-
113- if (openFunction != null ) {
114- openFunction .accept (item );
115- }
107+ if (openFunction != null ) openFunction .accept (item );
116108 }
117109 }
118110
119111 @ Override
120112 protected void updateItem (@ Nullable final ResourceElement item , boolean empty ) {
121113 super .updateItem (item , empty );
122114
115+ removeToolTip ();
116+
123117 if (item == null ) {
124118 setText (StringUtils .EMPTY );
125119 setGraphic (null );
126- Tooltip .uninstall (this , tooltip );
127120 return ;
128121 } else if (item instanceof LoadingResourceElement ) {
129122 setText (StringUtils .EMPTY );
130123 setGraphic (new ProgressIndicator ());
131- Tooltip .uninstall (this , tooltip );
132124 return ;
133125 }
134126
@@ -139,22 +131,18 @@ protected void updateItem(@Nullable final ResourceElement item, boolean empty) {
139131
140132 setText (fileName .toString ());
141133 setGraphic (icon );
134+ createToolTip ();
135+ }
142136
143- final EditorConfig editorConfig = EditorConfig .getInstance ();
144- final Path currentAsset = editorConfig .getCurrentAsset ();
145-
146- if (file .equals (currentAsset )) {
147- Tooltip .install (this , tooltip );
148- updateTooltip (file .toString ());
149- } else {
150- Tooltip .uninstall (this , tooltip );
151- }
137+ private void removeToolTip () {
138+ if (tooltip == null ) return ;
139+ Tooltip .uninstall (this , tooltip );
140+ tooltip = null ;
152141 }
153142
154- /**
155- * Update the tooltip.
156- */
157- private void updateTooltip (@ NotNull final String text ) {
158- tooltip .setText (text );
143+ private void createToolTip () {
144+ tooltip = getItem ().createToolTip ();
145+ if (tooltip == null ) return ;
146+ Tooltip .install (this , tooltip );
159147 }
160148}
0 commit comments