Commit 903834cf authored by Dumoulin Nicolas's avatar Dumoulin Nicolas
Browse files

specialization for nodes implementation

parent 9c20a47e
......@@ -17,7 +17,6 @@
package fr.cemagref.ohoui.ui.swing.basiccontrols;
import fr.cemagref.ohoui.structure.OhObject;
import fr.cemagref.ohoui.structure.OhObjectCollection;
import fr.cemagref.ohoui.structure.OhObjectComplex;
import java.awt.BorderLayout;
import java.awt.Component;
......@@ -52,11 +51,6 @@ public class DefaultObjectEditor extends AbstractOhEditor<Object, JComponent> {
panel.add(pagePanel, BorderLayout.NORTH);
pagePanel.setLayout(new BoxLayout(pagePanel, BoxLayout.PAGE_AXIS));
for (OhObject child : object) {
// No editors produced for collections, all edit features are provided
// by the tree view
if (child instanceof OhObjectCollection) {
continue;
}
// Editors retrieving for other types
List<Class> availableTypes = new ArrayList<Class>();
availableTypes.add(child.getDeclaredType());
......@@ -73,7 +67,7 @@ public class DefaultObjectEditor extends AbstractOhEditor<Object, JComponent> {
};
editor.setEnabled(false);
editor.addLabel(child.getName(), child.getDescription());
if (availableTypes.size() == 0) {
if (availableTypes.isEmpty()) {
editor.addComponent(new JLabel("null"), "No type have been found to affect a new instance in this variable.");
} else {
editor.addComponent(ControlsFactory.makeButton("general/New16",
......@@ -89,21 +83,29 @@ public class DefaultObjectEditor extends AbstractOhEditor<Object, JComponent> {
}
}
private void addEditorFor(OhObject object, int index) {
protected final void addPanelAt(JComponent component, int index) {
pagePanel.add(component, index);
}
protected final void registerEditor(AbstractOhEditor<Object, JComponent> editor) {
childrenEditors.add(editor);
}
protected void addEditorFor(OhObject object, int index) {
AbstractOhEditor<Object, JComponent> editor = EditorsProvider.createEditorFor(object);
if (editor != null) {
// TODO add button for reinstanciate object
pagePanel.add((JComponent) editor.getPanel(), index);
childrenEditors.add(editor);
addPanelAt((JComponent) editor.getPanel(), index);
registerEditor(editor);
} else {
// TODO it shouldn't occur, but as collections don't have editor, it can
pagePanel.add(new JPanel(), index);
addPanelAt(new JPanel(), index);
}
pagePanel.revalidate();
}
private void addEditorFor(OhObject object) {
addEditorFor(object, childrenEditors.size());
pagePanel.revalidate();
}
@Override
......@@ -183,7 +185,7 @@ public class DefaultObjectEditor extends AbstractOhEditor<Object, JComponent> {
pagePanel.remove(editorIndex);
// build the corresponding panel and add the panel in place
container.addEditorFor(ohObject, editorIndex);
// TODO notify the tree if a list is added for example
pagePanel.revalidate();
} catch (IllegalArgumentException ex) {
Exceptions.printStackTrace(ex);
} catch (IllegalAccessException ex) {
......
/*
* 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.swing;
import fr.cemagref.ohoui.structure.OhObject;
import fr.cemagref.ohoui.structure.OhObjectComplex;
import fr.cemagref.ohoui.ui.swing.basiccontrols.AbstractOhEditor;
import fr.cemagref.ohoui.ui.swing.basiccontrols.EditorsProvider;
import javax.swing.JComponent;
import javax.swing.JPanel;
/**
* Default implementation of editor for an ohObjectComplex, it produces an editor by
* assembling editors for each field.
*
* @author Nicolas Dumoulin <nicolas.dumoulin@cemagref.fr>
*/
public class DefaultObjectEditor extends fr.cemagref.ohoui.ui.swing.basiccontrols.DefaultObjectEditor {
public DefaultObjectEditor(OhObjectComplex<?> object) {
super(object);
}
@Override
protected void addEditorFor(OhObject object, int index) {
System.out.println("PLOP");
AbstractOhEditor<Object, JComponent> editor = EditorsProvider.createEditorFor(object);
if (editor != null) {
// TODO add button for reinstanciate object
addPanelAt((JComponent) editor.getPanel(), index);
registerEditor(editor);
} else {
// when a null collection or complex child is instancied, we have no editor
// TODO notify the tree if a list or complex object is added for example
addPanelAt(new JPanel(), index);
}
}
}
......@@ -30,7 +30,6 @@ import fr.cemagref.ohoui.structure.OhObject;
import fr.cemagref.ohoui.structure.OhObjectCollection;
import fr.cemagref.ohoui.structure.OhObjectComplex;
import fr.cemagref.ohoui.ui.swing.basiccontrols.AbstractOhEditor;
import fr.cemagref.ohoui.ui.swing.basiccontrols.DefaultObjectEditor;
import fr.cemagref.ohoui.ui.swing.basiccontrols.EditorsProvider;
import java.awt.CardLayout;
import java.awt.Dimension;
......
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