[Buix-commits] r611 - trunk/lutinui/src/main/java/org/codelutin/ui
Author: tchemit Date: 2008-04-25 22:12:42 +0000 (Fri, 25 Apr 2008) New Revision: 611 Added: trunk/lutinui/src/main/java/org/codelutin/ui/ShowUIAction.java Modified: trunk/lutinui/src/main/java/org/codelutin/ui/DialogUIDef.java trunk/lutinui/src/main/java/org/codelutin/ui/UIFactory.java Log: add generic show ui action Modified: trunk/lutinui/src/main/java/org/codelutin/ui/DialogUIDef.java =================================================================== --- trunk/lutinui/src/main/java/org/codelutin/ui/DialogUIDef.java 2008-04-25 22:11:57 UTC (rev 610) +++ trunk/lutinui/src/main/java/org/codelutin/ui/DialogUIDef.java 2008-04-25 22:12:42 UTC (rev 611) @@ -14,6 +14,10 @@ */ package org.codelutin.ui; +import static org.codelutin.i18n.I18n._; + +import javax.swing.ImageIcon; + /** * Definition of an ui, with his model, handler and ui class definitions. * <p/> @@ -23,6 +27,12 @@ */ public class DialogUIDef<M extends DialogUIModel, U extends DialogUI<H>, H extends DialogUIHandler<M, U>> implements java.io.Serializable { + public static <M extends DialogUIModel, U extends DialogUI<H>, H extends DialogUIHandler<M, U>> DialogUIDef<M, U, H> newDef(Class<H> handlerClass, Class<U> uiClass, Class<M> modelClass, String showActionLibelle, String showActionTip, String uiTitle) { + DialogUIDef<M, U, H> result; + result = new DialogUIDef<M, U, H>(handlerClass, uiClass, modelClass, showActionLibelle, showActionTip, uiTitle); + return result; + } + /** model class */ private final Class<M> modelClass; @@ -38,12 +48,28 @@ /** shared instance of ui */ protected U uiInstance; + /** unique name of ui def */ + protected final String name; + + protected final String uiTitle; + protected final String showActionLibelle; + + protected final String showActionTip; + + protected ImageIcon showUIActionIcon; + + private static final long serialVersionUID = 1L; - public DialogUIDef(Class<H> handlerClass, Class<U> uiClass, Class<M> modelClass) { + private DialogUIDef(Class<H> handlerClass, Class<U> uiClass, Class<M> modelClass, + String showActionLibelle, String showActionTip, String uiTitle) { this.handlerClass = handlerClass; this.uiClass = uiClass; this.modelClass = modelClass; + this.showActionLibelle = showActionLibelle; + this.name = uiClass.getSimpleName().toLowerCase(); + this.showActionTip = showActionTip; + this.uiTitle = uiTitle; } public Class<U> getUiClass() { @@ -62,6 +88,25 @@ return uiImplClass; } + public String getUiTitle() { + return _(uiTitle); + } + + public String getShowActionLibelle() { + return _(showActionLibelle); + } + + public String getShowActionTip() { + return _(showActionTip); + } + + public ImageIcon getShowUIActionIcon() { + if (showUIActionIcon == null) { + showUIActionIcon = UIHelper.createActionIcon("show-" + name); + } + return showUIActionIcon; + } + @SuppressWarnings({"unchecked"}) public void setUiImplClass(Class<?> uiImplClass) { this.uiImplClass = (Class<? extends U>) uiImplClass; Added: trunk/lutinui/src/main/java/org/codelutin/ui/ShowUIAction.java =================================================================== --- trunk/lutinui/src/main/java/org/codelutin/ui/ShowUIAction.java (rev 0) +++ trunk/lutinui/src/main/java/org/codelutin/ui/ShowUIAction.java 2008-04-25 22:12:42 UTC (rev 611) @@ -0,0 +1,68 @@ +/** + * # #% Copyright (C) 2008 Code Lutin, Tony Chemit + * 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 2 + * 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, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * # #% + */ +package org.codelutin.ui; + +/** @author chemit */ +public abstract class ShowUIAction<M extends DialogUIModel, U extends DialogUI<H>, H extends DialogUIHandler<M, U>, HH extends org.codelutin.ui.DialogUIHandler<?, ?>> extends AbstractUIAction<HH> { + + private static final long serialVersionUID = 1L; + + protected DialogUIDef<M, U, H> uiDef; + + protected transient UIFactory factory; + + protected abstract U initUI(java.awt.event.ActionEvent e); + + public <UU extends DialogUI<HH>> ShowUIAction(UU ui, DialogUIDef<M, U, H> uiDef, UIFactory factory, boolean showText) { + super(uiDef.getShowActionLibelle(), uiDef.getShowUIActionIcon(), ui); + this.uiDef = uiDef; + String name = (String) getValue(NAME); + putValue(DISPLAYED_MNEMONIC_INDEX_KEY, name.length() - 1); + putValue(ACCELERATOR_KEY, (int) name.charAt(name.length() - 1)); + if (!showText) { + putValue(NAME, null); + } + putValue(SHORT_DESCRIPTION, uiDef.getShowActionTip()); + this.factory = factory; + } + + public DialogUIDef<M, U, H> getUiDef() { + return uiDef; + } + + public void setUiDef(DialogUIDef<M, U, H> uiDef) { + this.uiDef = uiDef; + } + + public UIFactory getFactory() { + return factory; + } + + public void actionPerformed(java.awt.event.ActionEvent e) { + checkInit(); + U ui = initUI(e); + ui.setTitle(uiDef.getUiTitle()); + log.info(ui.getTitle()); + ui.setVisible(true); + } + + @Override + protected void checkInit() throws IllegalStateException { + super.checkInit(); + if (factory == null) { + throw new IllegalStateException("no factory found in " + this); + } + } +} \ No newline at end of file Modified: trunk/lutinui/src/main/java/org/codelutin/ui/UIFactory.java =================================================================== --- trunk/lutinui/src/main/java/org/codelutin/ui/UIFactory.java 2008-04-25 22:11:57 UTC (rev 610) +++ trunk/lutinui/src/main/java/org/codelutin/ui/UIFactory.java 2008-04-25 22:12:42 UTC (rev 611) @@ -154,7 +154,7 @@ close(); } - protected <M extends DialogUIModel, U extends DialogUI<H>, H extends DialogUIHandler<M, U>> U getUI(DialogUIDef<M, U, H> uiType, Object... params) { + public <M extends DialogUIModel, U extends DialogUI<H>, H extends DialogUIHandler<M, U>> U getUI(DialogUIDef<M, U, H> uiType, Object... params) { U result = uiType.uiInstance; if (result == null) { try {
participants (1)
-
tchemit@users.labs.libre-entreprise.org