Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
9c6b4c4f
by Tony Chemit at 2020-07-26T13:01:38+02:00
5 changed files:
- client-datasource-editor-api/src/main/java/fr/ird/observe/client/datasource/editor/tree/navigation/NavigationTree.java
- client-datasource-editor-api/src/main/java/fr/ird/observe/client/datasource/editor/tree/navigation/NavigationTreeCellRenderer.java
- client-datasource-editor-api/src/main/java/fr/ird/observe/client/datasource/editor/tree/navigation/NavigationTreeModel.java
- client-datasource-editor-api/src/main/java/fr/ird/observe/client/datasource/editor/tree/navigation/nodes/NavigationTreeNodeSupport.java
- client-datasource-editor-api/src/main/java/fr/ird/observe/client/datasource/editor/tree/navigation/nodes/ObserveTreeNodeSupport.java
Changes:
| ... | ... | @@ -93,8 +93,7 @@ public class NavigationTree extends JXTree { |
| 93 | 93 |
openNode(e.getPath());
|
| 94 | 94 |
});
|
| 95 | 95 |
|
| 96 |
- NavigationTreeCellRenderer renderer = new NavigationTreeCellRenderer();
|
|
| 97 |
- setCellRenderer(renderer);
|
|
| 96 |
+ setCellRenderer(new NavigationTreeCellRenderer());
|
|
| 98 | 97 |
|
| 99 | 98 |
ClientUIContext clientUIContext = ClientUIContextApplicationComponent.value();
|
| 100 | 99 |
ObserveEditModel navigationEdit = clientUIContext.getObserveEditModel();
|
| ... | ... | @@ -108,6 +107,15 @@ public class NavigationTree extends JXTree { |
| 108 | 107 |
);
|
| 109 | 108 |
}
|
| 110 | 109 |
|
| 110 |
+// public boolean getScrollableTracksViewportWidth() {
|
|
| 111 |
+// return true;
|
|
| 112 |
+// }
|
|
| 113 |
+ |
|
| 114 |
+// @Override
|
|
| 115 |
+// public boolean isFixedRowHeight() {
|
|
| 116 |
+// return true;
|
|
| 117 |
+// }
|
|
| 118 |
+ |
|
| 111 | 119 |
@Override
|
| 112 | 120 |
public void updateUI() {
|
| 113 | 121 |
setSelectionModel(new NavigationTreeSelectionModel());
|
| 1 | 1 |
package fr.ird.observe.client.datasource.editor.tree.navigation;
|
| 2 | 2 |
|
| 3 |
-/*-
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Client DataSource Editor API
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 | 3 |
import fr.ird.observe.client.datasource.editor.tree.navigation.nodes.NavigationTreeNodeSupport;
|
| 26 |
-import org.apache.logging.log4j.LogManager;
|
|
| 27 |
-import org.apache.logging.log4j.Logger;
|
|
| 4 |
+import org.jdesktop.swingx.renderer.CellContext;
|
|
| 5 |
+import org.jdesktop.swingx.renderer.DefaultTreeRenderer;
|
|
| 6 |
+import org.jdesktop.swingx.renderer.IconValue;
|
|
| 7 |
+import org.jdesktop.swingx.renderer.LabelProvider;
|
|
| 28 | 8 |
import org.jdesktop.swingx.renderer.StringValue;
|
| 29 |
-import org.jdesktop.swingx.tree.DefaultXTreeCellRenderer;
|
|
| 30 | 9 |
|
| 31 | 10 |
import javax.swing.Icon;
|
| 32 |
-import javax.swing.JLabel;
|
|
| 33 |
-import javax.swing.JTree;
|
|
| 34 |
-import javax.swing.SwingUtilities;
|
|
| 35 |
-import java.awt.Color;
|
|
| 36 |
-import java.awt.Component;
|
|
| 37 |
-import java.awt.Dimension;
|
|
| 38 | 11 |
|
| 39 | 12 |
/**
|
| 40 | 13 |
* Created on 14/11/16.
|
| ... | ... | @@ -42,78 +15,41 @@ import java.awt.Dimension; |
| 42 | 15 |
* @author Tony Chemit - dev@tchemit.fr
|
| 43 | 16 |
* @since 6.0
|
| 44 | 17 |
*/
|
| 45 |
-public class NavigationTreeCellRenderer extends DefaultXTreeCellRenderer implements StringValue {
|
|
| 18 |
+public class NavigationTreeCellRenderer extends DefaultTreeRenderer {
|
|
| 46 | 19 |
|
| 47 |
- /** Logger */
|
|
| 48 |
- private static final Logger log = LogManager.getLogger(NavigationTreeCellRenderer.class);
|
|
| 49 |
- |
|
| 50 |
-// @Override
|
|
| 51 |
-// public Color getBackgroundSelectionColor() {
|
|
| 52 |
-// return null;
|
|
| 53 |
-// }
|
|
| 54 |
-//
|
|
| 55 |
-// @Override
|
|
| 56 |
-// public Color getBackgroundNonSelectionColor() {
|
|
| 57 |
-// // Fixes http://forge.codelutin.com/issues/830 for jdk 7
|
|
| 58 |
-// return Color.WHITE;
|
|
| 59 |
-// }
|
|
| 20 |
+ public NavigationTreeCellRenderer() {
|
|
| 21 |
+ super(new NavigationTreeLabelProvider());
|
|
| 22 |
+ }
|
|
| 60 | 23 |
|
| 61 |
- @Override
|
|
| 62 |
- public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
|
|
| 24 |
+ private static class NavigationTreeStringIconValue implements StringValue, IconValue {
|
|
| 63 | 25 |
|
| 64 |
- if (!(tree.getModel() instanceof NavigationTreeModel)) {
|
|
| 65 |
- Component rendererComponent;
|
|
| 66 |
- rendererComponent = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
|
|
| 67 |
- return rendererComponent;
|
|
| 26 |
+ @Override
|
|
| 27 |
+ public Icon getIcon(Object value) {
|
|
| 28 |
+ NavigationTreeNodeSupport<?> n = (NavigationTreeNodeSupport<?>) value;
|
|
| 29 |
+ return n.getIcon();
|
|
| 68 | 30 |
}
|
| 69 | 31 |
|
| 70 |
- // get the icon to set for the node
|
|
| 71 |
- NavigationTreeNodeSupport node = (NavigationTreeNodeSupport) value;
|
|
| 72 |
- |
|
| 73 |
- Icon icon = node.getIcon();
|
|
| 32 |
+ @Override
|
|
| 33 |
+ public String getString(Object value) {
|
|
| 34 |
+ NavigationTreeNodeSupport<?> n = (NavigationTreeNodeSupport<?>) value;
|
|
| 35 |
+ return n.toString();
|
|
| 36 |
+ }
|
|
| 37 |
+ }
|
|
| 74 | 38 |
|
| 75 |
- if (!sel) {
|
|
| 39 |
+ private static class NavigationTreeLabelProvider extends LabelProvider {
|
|
| 76 | 40 |
|
| 77 |
- Color color = node.getColor();
|
|
| 78 |
- if (log.isTraceEnabled()) {
|
|
| 79 |
- log.trace("===" + color + " for node " + node.getDataType() + " - " + node.getId());
|
|
| 80 |
- }
|
|
| 81 |
- setTextNonSelectionColor(color);
|
|
| 41 |
+ public NavigationTreeLabelProvider() {
|
|
| 42 |
+ super(new NavigationTreeStringIconValue());
|
|
| 82 | 43 |
}
|
| 83 | 44 |
|
| 84 |
- String text = node.getText();
|
|
| 85 |
- if (log.isTraceEnabled()) {
|
|
| 86 |
- log.trace("===" + text + " for node " + node.getDataType() + " - " + node.getId());
|
|
| 87 |
- }
|
|
| 88 |
- JLabel comp = (JLabel) super.getTreeCellRendererComponent(tree, text, sel, expanded, leaf, row, hasFocus);
|
|
| 89 |
- comp.setToolTipText(text);
|
|
| 90 |
- comp.setIcon(icon);
|
|
| 91 |
- Dimension size = comp.getPreferredSize();
|
|
| 92 |
- double height = size.getHeight();
|
|
| 93 |
- if (height > 50) {
|
|
| 94 |
- log.error(String.format("Size is amazing: %s for node: %s", size, text));
|
|
| 95 |
- Dimension newSize = new Dimension((int) size.getWidth(), 32);
|
|
| 96 |
- comp.setSize(newSize);
|
|
| 97 |
- comp.setPreferredSize(newSize);
|
|
| 98 |
- } else {
|
|
| 99 |
- int stringWidth = SwingUtilities.computeStringWidth(comp.getFontMetrics(comp.getFont()), text);
|
|
| 100 |
- if (size.getWidth() < stringWidth) {
|
|
| 101 |
- log.error(String.format("Size is too low: %s for node: %s", size, text));
|
|
| 102 |
- Dimension newSize = new Dimension(stringWidth + 5, (int) height);
|
|
| 103 |
- comp.setPreferredSize(newSize);
|
|
| 45 |
+ @Override
|
|
| 46 |
+ protected void configureVisuals(CellContext context) {
|
|
| 47 |
+ NavigationTreeNodeSupport<?> value = (NavigationTreeNodeSupport<?>) context.getValue();
|
|
| 48 |
+ if (!context.isSelected()) {
|
|
| 49 |
+ defaultVisuals.setForeground(value.getColor());
|
|
| 104 | 50 |
}
|
| 51 |
+ super.configureVisuals(context);
|
|
| 105 | 52 |
}
|
| 106 |
- return comp;
|
|
| 107 |
- }
|
|
| 108 |
- |
|
| 109 |
- @Override
|
|
| 110 |
- public String getString(Object value) {
|
|
| 111 |
- NavigationTreeNodeSupport node = (NavigationTreeNodeSupport) value;
|
|
| 112 |
- return node.getText();
|
|
| 113 |
- }
|
|
| 114 | 53 |
|
| 115 |
- @Override
|
|
| 116 |
- protected String paramString() {
|
|
| 117 |
- return "Nope";
|
|
| 118 | 54 |
}
|
| 119 | 55 |
}
|
| ... | ... | @@ -24,12 +24,10 @@ package fr.ird.observe.client.datasource.editor.tree.navigation; |
| 24 | 24 |
|
| 25 | 25 |
import fr.ird.observe.client.configuration.ClientConfig;
|
| 26 | 26 |
import fr.ird.observe.client.configuration.NavigationTreeConfigBean;
|
| 27 |
-import fr.ird.observe.client.datasource.editor.tree.navigation.nodes.ClassNavigationTreeNode;
|
|
| 28 | 27 |
import fr.ird.observe.client.datasource.editor.tree.navigation.nodes.NavigationTreeModelInitializer;
|
| 29 | 28 |
import fr.ird.observe.client.datasource.editor.tree.navigation.nodes.NavigationTreeNodeSupport;
|
| 30 | 29 |
import fr.ird.observe.client.datasource.editor.tree.navigation.nodes.ReferenceNavigationTreeNodeSupport;
|
| 31 | 30 |
import fr.ird.observe.client.datasource.editor.tree.navigation.nodes.RootNavigationTreeNode;
|
| 32 |
-import fr.ird.observe.client.datasource.editor.tree.navigation.nodes.StringNavigationTreeNodeSupport;
|
|
| 33 | 31 |
import fr.ird.observe.client.datasource.editor.tree.navigation.nodes.WithChildsToReload;
|
| 34 | 32 |
import fr.ird.observe.navigation.model.DtoModelNavigationModel;
|
| 35 | 33 |
import fr.ird.observe.navigation.model.ObserveNavigationNode;
|
| ... | ... | @@ -124,7 +124,7 @@ public abstract class NavigationTreeNodeSupport<O> extends ObserveTreeNodeSuppor |
| 124 | 124 |
this.loaded = loaded;
|
| 125 | 125 |
}
|
| 126 | 126 |
|
| 127 |
- public NavigationTreeNodeSupport findChildById(String id) {
|
|
| 127 |
+ public NavigationTreeNodeSupport<?> findChildById(String id) {
|
|
| 128 | 128 |
if (id == null) {
|
| 129 | 129 |
|
| 130 | 130 |
// id null ? donc rien a faire
|
| ... | ... | @@ -147,9 +147,9 @@ public abstract class NavigationTreeNodeSupport<O> extends ObserveTreeNodeSuppor |
| 147 | 147 |
// au final le noeud est une feuille, donc ne convient pas
|
| 148 | 148 |
return null;
|
| 149 | 149 |
}
|
| 150 |
- Enumeration children = children();
|
|
| 150 |
+ Enumeration<?> children = children();
|
|
| 151 | 151 |
while (children.hasMoreElements()) {
|
| 152 |
- NavigationTreeNodeSupport node = (NavigationTreeNodeSupport) children.nextElement();
|
|
| 152 |
+ NavigationTreeNodeSupport<?> node = (NavigationTreeNodeSupport<?>) children.nextElement();
|
|
| 153 | 153 |
if (id.equals(node.getId()) || (node.getUserObject() instanceof String && id.equals(node.getUserObject()))) {
|
| 154 | 154 |
return node;
|
| 155 | 155 |
}
|
| ... | ... | @@ -158,7 +158,7 @@ public abstract class NavigationTreeNodeSupport<O> extends ObserveTreeNodeSuppor |
| 158 | 158 |
return null;
|
| 159 | 159 |
}
|
| 160 | 160 |
|
| 161 |
- public NavigationTreeNodeSupport findChildByType(Class<?> childType) {
|
|
| 161 |
+ public NavigationTreeNodeSupport<?> findChildByType(Class<?> childType) {
|
|
| 162 | 162 |
|
| 163 | 163 |
if (childType.isAssignableFrom(getClass())) {
|
| 164 | 164 |
|
| ... | ... | @@ -177,9 +177,9 @@ public abstract class NavigationTreeNodeSupport<O> extends ObserveTreeNodeSuppor |
| 177 | 177 |
// au final le noeud est une feuille, donc ne convient pas
|
| 178 | 178 |
return null;
|
| 179 | 179 |
}
|
| 180 |
- Enumeration children = children();
|
|
| 180 |
+ Enumeration<?> children = children();
|
|
| 181 | 181 |
while (children.hasMoreElements()) {
|
| 182 |
- NavigationTreeNodeSupport node = (NavigationTreeNodeSupport) children.nextElement();
|
|
| 182 |
+ NavigationTreeNodeSupport<?> node = (NavigationTreeNodeSupport<?>) children.nextElement();
|
|
| 183 | 183 |
if (childType.isAssignableFrom(node.getClass())) {
|
| 184 | 184 |
return node;
|
| 185 | 185 |
}
|
| ... | ... | @@ -202,30 +202,6 @@ public abstract class NavigationTreeNodeSupport<O> extends ObserveTreeNodeSuppor |
| 202 | 202 |
return isOpen() ? Color.BLACK : Color.GRAY;
|
| 203 | 203 |
}
|
| 204 | 204 |
|
| 205 |
-// public JMenuItem toMenuItem(SelectNode action, JAXXObject ui) {
|
|
| 206 |
-//
|
|
| 207 |
-// JMenuItem mi = new JMenuItem();
|
|
| 208 |
-// AbstractAction a = new AbstractAction() {
|
|
| 209 |
-//
|
|
| 210 |
-// @Override
|
|
| 211 |
-// public void actionPerformed(ActionEvent e) {
|
|
| 212 |
-// if (log.isInfoEnabled()) {
|
|
| 213 |
-// log.info("Select action from menuItem: " + e.getSource());
|
|
| 214 |
-// }
|
|
| 215 |
-// action.actionPerformed(mi);
|
|
| 216 |
-// }
|
|
| 217 |
-// };
|
|
| 218 |
-// mi.setAction(a);
|
|
| 219 |
-// mi.setText(getText().trim());
|
|
| 220 |
-// ObserveKeyStrokes.addKeyStroke(mi, ObserveKeyStrokes.KEY_STROKE_PRESSED_ENTER);
|
|
| 221 |
-// mi.setIcon(getIcon(true));
|
|
| 222 |
-// mi.setForeground(getColor());
|
|
| 223 |
-// mi.setBackground(Color.WHITE);
|
|
| 224 |
-// mi.putClientProperty("node", this);
|
|
| 225 |
-// mi.putClientProperty("ui", ui);
|
|
| 226 |
-// return mi;
|
|
| 227 |
-// }
|
|
| 228 |
- |
|
| 229 | 205 |
public NavigationTreeNodeSupport<?> findChildByModelNode(ObserveNavigationNode<?> node) {
|
| 230 | 206 |
|
| 231 | 207 |
if (!isLoaded()) {
|
| ... | ... | @@ -238,7 +214,7 @@ public abstract class NavigationTreeNodeSupport<O> extends ObserveTreeNodeSuppor |
| 238 | 214 |
|
| 239 | 215 |
String id = node.getId();
|
| 240 | 216 |
Class<?> type = node.getType();
|
| 241 |
- Enumeration children = children();
|
|
| 217 |
+ Enumeration<?> children = children();
|
|
| 242 | 218 |
while (children.hasMoreElements()) {
|
| 243 | 219 |
NavigationTreeNodeSupport<?> child = (NavigationTreeNodeSupport<?>) children.nextElement();
|
| 244 | 220 |
if (child instanceof ReferenceNavigationTreeNodeSupport<?, ?>) {
|
| ... | ... | @@ -67,4 +67,8 @@ public abstract class ObserveTreeNodeSupport<O> extends DefaultMutableTreeNode { |
| 67 | 67 |
return servicesProviderSupplier.get();
|
| 68 | 68 |
}
|
| 69 | 69 |
|
| 70 |
+ @Override
|
|
| 71 |
+ public String toString() {
|
|
| 72 |
+ return getText();
|
|
| 73 |
+ }
|
|
| 70 | 74 |
}
|