Index: topia/src/java/org/codelutin/topia/ui/swing/ActionEntityPanel.java diff -u topia/src/java/org/codelutin/topia/ui/swing/ActionEntityPanel.java:1.2 topia/src/java/org/codelutin/topia/ui/swing/ActionEntityPanel.java:1.3 --- topia/src/java/org/codelutin/topia/ui/swing/ActionEntityPanel.java:1.2 Fri Sep 3 15:43:53 2004 +++ topia/src/java/org/codelutin/topia/ui/swing/ActionEntityPanel.java Fri Sep 10 15:37:35 2004 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * - * Mise a jour: $Date: 2004/09/03 15:43:53 $ + * Mise a jour: $Date: 2004/09/10 15:37:35 $ * par : $Author: mazelier $ */ @@ -52,21 +52,45 @@ import java.util.logging.Logger; import java.util.logging.Level; import java.awt.Insets; +import java.util.ArrayList; +import javax.swing.Box; +import javax.swing.JPanel; +import javax.swing.DefaultComboBoxModel; -public class ActionEntityPanel extends TopiaPanel{ // ActionEntityPanel +public class ActionEntityPanel extends JPanel{ // ActionEntityPanel protected UIContext uicontext = null; protected TopiaPersistenceService ps = null; + protected Box lastEntityBox = null; + protected JComboBox searchFieldCombo = null; + protected JButton searchButton = null; + protected JTextField searchText = null; + protected JLinkButton newLinkButton = null; - public ActionEntityPanel(UIContext uicontext, TopiaPersistenceService ps){ + public ActionEntityPanel(){ super(); + initUI(); + } + public ActionEntityPanel(UIContext uicontext, TopiaPersistenceService ps){ + this(); + + setUIContext(uicontext); + setTopiaPersistenceService(ps); + } + + public void setUIContext(UIContext uicontext){ this.uicontext = uicontext; - this.ps = ps; - init(); + if(ps != null){ + initData(); + } } - public void init() { + public void setTopiaPersistenceService(TopiaPersistenceService ps){ + this.ps = ps; + initData(); + } + protected void initUI(){ GridBagLayout layout = new GridBagLayout(); GridBagConstraints constraint = new GridBagConstraints(); @@ -77,59 +101,79 @@ constraint.fill=GridBagConstraints.HORIZONTAL; constraint.insets = new Insets(2,2,2,2); + lastEntityBox = Box.createVerticalBox(); + constraint.gridx=0; + add(lastEntityBox, constraint); - try{ - - TopiaQuery query = ps.newQuery().orderby("_creationDate_ desc"); - List listFields = ps.find(query); - constraint.gridwidth=3; - // add listFields of LinkButton to the Panel - for(Iterator i = listFields.iterator(); i.hasNext();){ - constraint.gridy++; - TopiaEntity field = (TopiaEntity)i.next(); - ShowAction fieldAction = new ShowAction(uicontext, field); - JLinkButton linkButton = new JLinkButton(fieldAction); - add(linkButton, constraint); - } - - constraint.gridy++; - constraint.gridwidth=1; - }catch(TopiaException eee){ - Logger.getLogger("ActionEntityPanel.init").log(Level.WARNING, "Impossible de recuperer le resultat de la requete"); - } // add the combo - constraint.gridx=0; - String [] items = ps.getFieldNames(); - JComboBox combo = new JComboBox(items); - add(combo, constraint); + constraint.gridx=1; + searchFieldCombo = new JComboBox(); + add(searchFieldCombo, constraint); // add the textfield - constraint.gridx=1; + constraint.gridx=2; constraint.weightx=0.1; constraint.ipadx=100; - JTextField textfield = new JTextField(); - add(textfield, constraint); + searchText = new JTextField(); + add(searchText, constraint); // add the button Search - constraint.gridx=2; + constraint.gridx=3; constraint.weightx=0.0; constraint.ipadx=10; - SearchAction searchAction = - new SearchAction(uicontext, ps, combo, textfield); - JButton button = new JButton(searchAction); - add(button, constraint); + searchButton = new JButton("Search"); + add(searchButton, constraint); // add the linkbutton new - constraint.gridx=0; constraint.gridy++; constraint.gridwidth=3; - NewAction newAction = new NewAction(uicontext, ps); - JLinkButton newLinkButton = new JLinkButton(newAction); + newLinkButton = new JLinkButton("New"); add(newLinkButton, constraint); + } + + /** + * PersistenceService must be set + */ + protected void initData() { + loadLast(); + + // change the combo model + searchFieldCombo.setModel(new DefaultComboBoxModel(ps.getFieldNames())); + + // add the button Search + SearchAction searchAction = + new SearchAction(uicontext, ps, searchFieldCombo, searchText); + searchButton.setAction(searchAction); + + NewAction newAction = new NewAction(uicontext, ps); + newLinkButton.setAction(newAction); + } + + /** + * PersistenceService must be set + */ + protected void loadLast(){ + lastEntityBox.removeAll(); + try{ + TopiaQuery query = ps.newQuery(); + //TopiaQuery query = ps.newQuery().orderby("_creationDate_ desc"); + List lastUsed = ps.find(query); + //List listFields = ps.findAll(); + // add listFields of LinkButton to the Panel + for(Iterator i = lastUsed.iterator(); i.hasNext();){ + TopiaEntity entity = (TopiaEntity)i.next(); + ShowAction showAction = new ShowAction(uicontext, entity); + JLinkButton linkButton = new JLinkButton(showAction); + lastEntityBox.add(linkButton); + } + }catch(TopiaException eee){ + eee.printStackTrace(); + Logger.getLogger("ActionEntityPanel.init").log(Level.WARNING, "Impossible de recuperer le resultat de la requete",eee); + } } } // ActionEntityPanel Index: topia/src/java/org/codelutin/topia/ui/swing/TopiaTaskPaneGroup.java diff -u topia/src/java/org/codelutin/topia/ui/swing/TopiaTaskPaneGroup.java:1.1 topia/src/java/org/codelutin/topia/ui/swing/TopiaTaskPaneGroup.java:1.2 --- topia/src/java/org/codelutin/topia/ui/swing/TopiaTaskPaneGroup.java:1.1 Fri Sep 3 15:46:22 2004 +++ topia/src/java/org/codelutin/topia/ui/swing/TopiaTaskPaneGroup.java Fri Sep 10 15:37:35 2004 @@ -23,9 +23,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ * - * Mise a jour: $Date: 2004/09/03 15:46:22 $ + * Mise a jour: $Date: 2004/09/10 15:37:35 $ * par : $Author: mazelier $ */ @@ -40,9 +40,11 @@ protected TopiaPersistenceService ps = null; protected String title = null; + protected UIContext uicontext = null; - public TopiaTaskPaneGroup(TopiaPersistenceService ps, String title){ + public TopiaTaskPaneGroup(UIContext uicontext, TopiaPersistenceService ps, String title){ super(); + this.uicontext=uicontext; this.ps=ps; this.title=title; init(); @@ -52,7 +54,6 @@ setOpaque(true); setText(title); - UIContext uicontext = new UIContext(); ActionEntityPanel panel = new ActionEntityPanel(uicontext, ps); add(panel); }