r416 - in trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util: . action
Author: tchemit Date: 2013-02-15 00:55:36 +0100 (Fri, 15 Feb 2013) New Revision: 416 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/416 Log: add action package Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUIModel.java Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUI.css (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUI.css 2013-02-14 23:55:36 UTC (rev 416) @@ -0,0 +1,61 @@ +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * 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/gpl-3.0.html>. + * #L% + */ +#globalPanel { + border: {new TitledBorder((String) null)}; +} + +#globalActionLabel { + border: {new EmptyBorder(5, 5, 5, 5)}; +} + +#globalProgressBar { + indeterminate: true; +} + +#taskPanel { + visible: false; + border: {new TitledBorder((String) null)}; +} + +#taskProgressBar { + indeterminate: false; +} + +#taskActionLabel { + border: {new EmptyBorder(5, 5, 5, 5)}; +} + +#informationPanel { + visible: false; + border: {new TitledBorder((String) null)}; +} + +#informationLabel { + border: {new EmptyBorder(5, 5, 5, 5)}; +} + +#okAction { + actionIcon: information; + text: "tutti.action.ok"; +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUI.css ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUI.jaxx (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUI.jaxx 2013-02-14 23:55:36 UTC (rev 416) @@ -0,0 +1,72 @@ +<!-- + #%L + Tutti :: UI + $Id$ + $HeadURL$ + %% + Copyright (C) 2012 - 2013 Ifremer + %% + 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/gpl-3.0.html>. + #L% + --> +<JDialog layout='{new BorderLayout()}' width='300' height='200' modal='true' undecorated='true' + implements='fr.ifremer.tutti.ui.swing.TuttiUI<TuttiActionUIModel, TuttiActionUIHandler>'> + <import> + + fr.ifremer.tutti.ui.swing.TuttiUI + fr.ifremer.tutti.ui.swing.TuttiUIContext + + javax.swing.border.EmptyBorder + + static org.nuiton.i18n.I18n._ + </import> + + <script><![CDATA[ + + public TuttiActionUI(JFrame frame, TuttiUIContext context) { + super(frame, true); + TuttiActionUIHandler handler = new TuttiActionUIHandler(context, this); + setContextValue(handler); + handler.beforeInitUI(); + } + + protected void $afterCompleteSetup() { + handler.afterInitUI(); + } + ]]></script> + + <TuttiActionUIHandler id='handler' + initializer='getContextValue(TuttiActionUIHandler.class)'/> + + <TuttiActionUIModel id='model' + initializer='getContextValue(TuttiActionUIModel.class)'/> + + + <JPanel id='globalPanel' constraints='BorderLayout.NORTH' + layout='{new BorderLayout()}'> + <JLabel id='globalActionLabel' constraints='BorderLayout.CENTER'/> + <JProgressBar id='globalProgressBar' constraints='BorderLayout.SOUTH'/> + </JPanel> + <JPanel id='taskPanel' constraints='BorderLayout.CENTER' + layout='{new BorderLayout()}'> + <JLabel id='taskActionLabel' constraints='BorderLayout.CENTER'/> + <JProgressBar id='taskProgressBar' constraints='BorderLayout.SOUTH'/> + </JPanel> + <!--JPanel id='informationPanel' constraints='BorderLayout.SOUTH' + layout='{new BorderLayout()}'> + <JLabel id='informationLabel' constraints='BorderLayout.CENTER'/> + <JButton id='okAction' constraints='BorderLayout.SOUTH' onActionPerformed='handler.closeAction()'/> + </JPanel--> +</JDialog> \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUI.jaxx ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUIHandler.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUIHandler.java 2013-02-14 23:55:36 UTC (rev 416) @@ -0,0 +1,185 @@ +package fr.ifremer.tutti.ui.swing.util.action; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * 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/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.ProgressionModel; +import fr.ifremer.tutti.ui.swing.AbstractTuttiAction; +import fr.ifremer.tutti.ui.swing.AbstractTuttiUIHandler; +import fr.ifremer.tutti.ui.swing.TuttiUIContext; +import jaxx.runtime.SwingUtil; +import jaxx.runtime.validator.swing.SwingValidator; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.SwingUtilities; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import static org.nuiton.i18n.I18n._; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class TuttiActionUIHandler extends AbstractTuttiUIHandler<TuttiActionUIModel, TuttiActionUI> { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(TuttiActionUIHandler.class); + + + public TuttiActionUIHandler(TuttiUIContext context, TuttiActionUI ui) { + super(context, ui); + } + + protected PropertyChangeListener progressionListener = new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + + String propertyName = evt.getPropertyName(); + if (ProgressionModel.PROPERTY_MESSAGE.equals(propertyName)) { + + // change message + ui.getTaskActionLabel().setText((String) evt.getNewValue()); + } else if (ProgressionModel.PROPERTY_TOTAL.equals(propertyName)) { + + // change total progressbar max + ui.getTaskProgressBar().setMaximum((Integer) evt.getNewValue()); + + } else if (ProgressionModel.PROPERTY_MESSAGE.equals(propertyName)) { + + // change value of progress bar + ui.getTaskProgressBar().setValue((Integer) evt.getNewValue()); + } + } + }; + + //------------------------------------------------------------------------// + //-- AbstractTuttiUIHandler methods --// + //------------------------------------------------------------------------// + + protected void hideAction() { + getModel().setProgressionModel(null); + ui.setVisible(false); + } + + @Override + public void beforeInitUI() { + TuttiActionUIModel model = new TuttiActionUIModel(); + ui.setContextValue(model); + + model.addPropertyChangeListener(TuttiActionUIModel.PROPERTY_ACTION, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + + // udpate global label + AbstractTuttiAction action = (AbstractTuttiAction) evt.getNewValue(); + + if (log.isInfoEnabled()) { + log.info("Action to use: " + action); + } + if (action == null || action.isFailed()) { + + // stoping action + + if (SwingUtilities.isEventDispatchThread()) { + + hideAction(); + } else { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + hideAction(); + } + }); + } + } else { + + // starting action + if (ui.getOwner() != null) { + + SwingUtil.center(ui.getOwner(), ui); + } + // new action + ui.getGlobalActionLabel().setText(_("tutti.message.action.running", action.getActionDescription())); + ui.pack(); + ui.setVisible(true); + } + } + }); + + model.addPropertyChangeListener(TuttiActionUIModel.PROPERTY_PROGRESSION_MODEL, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + + // change progression model + + ProgressionModel oldValue = (ProgressionModel) evt.getOldValue(); + ProgressionModel newValue = (ProgressionModel) evt.getNewValue(); + + if (log.isInfoEnabled()) { + log.info("progression model: " + newValue); + } + if (oldValue != null) { + oldValue.removePropertyChangeListener(progressionListener); + } + + if (newValue == null) { + + // remove progression model +// ui.getGlobalProgressBar().setVisible(true); + ui.getTaskPanel().setVisible(false); + } else { + + // use progression model +// ui.getGlobalProgressBar().setVisible(false); + ui.getTaskPanel().setVisible(true); + + newValue.addPropertyChangeListener(progressionListener); + } + } + }); + } + + @Override + public void afterInitUI() { + + initUI(ui); + } + + @Override + public void onCloseUI() { + + } + + @Override + public SwingValidator<TuttiActionUIModel> getValidator() { + return null; + } + + public void closeAction() { + getModel().clear(); + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUIHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUIModel.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUIModel.java 2013-02-14 23:55:36 UTC (rev 416) @@ -0,0 +1,71 @@ +package fr.ifremer.tutti.ui.swing.util.action; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * 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/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.ProgressionModel; +import fr.ifremer.tutti.ui.swing.AbstractTuttiAction; +import org.jdesktop.beans.AbstractSerializableBean; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class TuttiActionUIModel extends AbstractSerializableBean { + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_ACTION = "action"; + + public static final String PROPERTY_PROGRESSION_MODEL = "progressionModel"; + + protected AbstractTuttiAction action; + + protected ProgressionModel progressionModel; + + public ProgressionModel getProgressionModel() { + return progressionModel; + } + + public void setProgressionModel(ProgressionModel progressionModel) { + Object oldValue = getProgressionModel(); + this.progressionModel = progressionModel; + firePropertyChange(PROPERTY_PROGRESSION_MODEL, oldValue, progressionModel); + } + + public AbstractTuttiAction getAction() { + return action; + } + + public void setAction(AbstractTuttiAction action) { + Object oldValue = getAction(); + this.action = action; + firePropertyChange(PROPERTY_ACTION, oldValue, action); + } + + public void clear() { + setProgressionModel(null); + setAction(null); + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUIModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native
participants (1)
-
tchemit@users.forge.codelutin.com