Commit 3fd71f05 authored by Dumoulin Nicolas's avatar Dumoulin Nicolas
Browse files

methods and class names refactoring

parent 9096facc
......@@ -30,8 +30,7 @@ import fr.cemagref.ohoui.structure.OhObjectCollection;
import fr.cemagref.ohoui.structure.OhObjectComplex;
import fr.cemagref.ohoui.ui.panels.AbstractOhEditor;
import fr.cemagref.ohoui.ui.panels.DefaultObjectEditor;
import fr.cemagref.ohoui.ui.panels.OhEditorProducer;
import fr.cemagref.ohoui.ui.panels.PanelsProvider;
import fr.cemagref.ohoui.ui.panels.EditorsProvider;
import java.awt.CardLayout;
import java.awt.Dimension;
import java.util.HashMap;
......@@ -104,10 +103,9 @@ public class NodesAndPanelsPanel extends JPanel implements ListSelectionListener
editorsCardLayout.show(editorsPanel, getCode(selectedObject));
} else {
// retrieve editor and put it in cache
OhEditorProducer editorProducer = PanelsProvider.getEditor(selectedObject);
AbstractOhEditor<Object, JComponent> editor = null;
if (editorProducer != null) {
editor = editorProducer.getEditor(selectedObject);
if (EditorsProvider.hasEditorFor(selectedObject)) {
editor = EditorsProvider.createEditorFor(selectedObject);
// TODO following tests should be avoided by presence of correct producer
} else if (selectedObject instanceof OhObjectCollection) {
// TODO bring an editor with a list and add/remove buttons
......@@ -115,7 +113,7 @@ public class NodesAndPanelsPanel extends JPanel implements ListSelectionListener
editor = new DefaultObjectEditor(selectedObject);
} else {
// TODO pay attention if object value is null ?
editor = PanelsProvider.getEditor(selectedObject).getEditor(selectedObject);
editor = EditorsProvider.createEditorFor(selectedObject);
}
editorsMap.put(selectedObject, editor);
if (editor != null) {
......
......@@ -17,9 +17,8 @@
package fr.cemagref.ohoui.ui.nodesandpanels;
import fr.cemagref.ohoui.structure.OhObject;
import fr.cemagref.ohoui.structure.OhObjectCollection;
import fr.cemagref.ohoui.structure.OhObjectComplex;
import fr.cemagref.ohoui.ui.panels.PanelsProvider;
import fr.cemagref.ohoui.ui.panels.EditorsProvider;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
......@@ -54,7 +53,7 @@ public class OhTreeModel implements TreeModel {
@Override
public boolean isLeaf(Object node) {
OhObject ohObject = (OhObject) node;
return (!(node instanceof OhObjectComplex) || (PanelsProvider.isTypeHandled(ohObject)));
return (!(node instanceof OhObjectComplex) || (EditorsProvider.hasEditorFor(ohObject)));
}
@Override
......
/*
* Copyright (C) 2010 Cemagref
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.cemagref.ohoui.ui.panels;
import fr.cemagref.ohoui.structure.OhObject;
......@@ -9,6 +25,10 @@ import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JPanel;
/**
*
* @author Nicolas Dumoulin <nicolas.dumoulin@cemagref.fr>
*/
public class DefaultObjectEditor extends AbstractOhEditor<Object, JComponent> {
public DefaultObjectEditor(OhObject object) {
......@@ -19,8 +39,8 @@ public class DefaultObjectEditor extends AbstractOhEditor<Object, JComponent> {
for (OhObject child : (OhObjectComplex<?>) object) {
if (child.getValue() == null) {
// TODO add button for object creation
} else if (PanelsProvider.isTypeHandled(child)) {
panel.add((JComponent) PanelsProvider.getEditor(child).getEditor(child).getPanel());
} else if (EditorsProvider.hasEditorFor(child)) {
panel.add((JComponent) EditorsProvider.createEditorFor(child).getPanel());
}
}
}
......
......@@ -21,19 +21,20 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
import javax.swing.JComponent;
import org.openide.util.Lookup;
/**
*
* @author Nicolas Dumoulin <nicolas.dumoulin@cemagref.fr>
*/
public class PanelsProvider {
public class EditorsProvider {
private static PanelsProvider instance;
private static final Logger LOGGER = Logger.getLogger(PanelsProvider.class.getName());
private static EditorsProvider instance;
private static final Logger LOGGER = Logger.getLogger(EditorsProvider.class.getName());
private Map<Class, OhEditorProducer> editorProducers;
private PanelsProvider() {
private EditorsProvider() {
editorProducers = new HashMap<Class, OhEditorProducer>();
for (OhEditorProducer producer : Lookup.getDefault().lookupAll(OhEditorProducer.class)) {
for (Class type : producer.getCompatibleTypes()) {
......@@ -49,25 +50,21 @@ public class PanelsProvider {
LOGGER.info("Producers loaded: " + editorProducers);
}
private static PanelsProvider getDefault() {
private static EditorsProvider getDefault() {
if (instance == null) {
instance = new PanelsProvider();
instance = new EditorsProvider();
}
return instance;
}
public static Set<Class> getHandledTypes() {
return getDefault().editorProducers.keySet();
}
public static boolean isTypeHandled(OhObject ohObject) {
public static boolean hasEditorFor(OhObject ohObject) {
if (ohObject.getValue() != null) {
return getDefault().editorProducers.containsKey(ohObject.getValue().getClass());
}
return true;
}
public static OhEditorProducer getEditor(OhObject ohObject) {
public static AbstractOhEditor<Object, JComponent> createEditorFor(OhObject ohObject) {
OhEditorProducer editor = null;
if (ohObject.getValue() != null) {
editor = getDefault().editorProducers.get(ohObject.getValue().getClass());
......@@ -75,6 +72,6 @@ public class PanelsProvider {
if (editor == null) {
// TODO return an new DefaultObjectEditor ? should be avoided upstream
}
return editor;
return (editor==null) ? null : editor.getEditor(ohObject);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment