This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository jaxx. See https://gitlab.nuiton.org/nuiton/jaxx.git commit 69c4470b36dddf1edfce93b19cec427037feaab1 Author: Tony CHEMIT <dev@tchemit.fr> Date: Sat Dec 31 13:05:22 2016 +0100 Remove application API (Fixes #4107) --- jaxx-application-api/LICENSE.txt | 165 --- jaxx-application-api/README.md | 0 jaxx-application-api/pom.xml | 100 -- .../src/license/THIRD-PARTY.properties | 21 - .../application/ApplicationBusinessException.java | 49 - .../jaxx/application/ApplicationConfiguration.java | 81 -- .../jaxx/application/ApplicationContext.java | 39 - .../jaxx/application/ApplicationDataUtil.java | 86 -- .../nuiton/jaxx/application/ApplicationIOUtil.java | 262 ---- .../application/ApplicationTechnicalException.java | 48 - .../nuiton/jaxx/application/bean/BinderCache.java | 60 - .../jaxx/application/bean/JavaBeanObject.java | 137 -- .../JavaBeanObjectPropagateChangeListener.java | 71 -- .../jaxx/application/bean/JavaBeanObjectUtil.java | 109 -- .../bean/RemoveablePropertyChangeListener.java | 35 - .../listener/PropagatePropertyChangeListener.java | 81 -- .../type/ApplicationProgressionModel.java | 113 -- jaxx-application-api/src/site/site.xml | 44 - jaxx-application-swing/LICENSE.txt | 165 --- jaxx-application-swing/README.md | 0 jaxx-application-swing/pom.xml | 199 --- .../src/license/THIRD-PARTY.properties | 26 - .../swing/AbstractApplicationFormUIModel.java | 289 ----- .../swing/AbstractApplicationUIHandler.java | 1316 -------------------- .../jaxx/application/swing/ApplicationUI.java | 143 --- .../swing/ApplicationUIConfiguration.java | 43 - .../application/swing/ApplicationUIContext.java | 88 -- .../swing/action/AbstractApplicationAction.java | 438 ------- .../swing/action/ApplicationActionEngine.java | 126 -- .../swing/action/ApplicationActionException.java | 56 - .../swing/action/ApplicationActionFactory.java | 94 -- .../swing/action/ApplicationActionSwingWorker.java | 201 --- .../swing/action/ApplicationActionUI.jaxx | 72 -- .../swing/action/ApplicationActionUI.jcss | 66 - .../swing/action/ApplicationActionUIHandler.java | 274 ---- .../swing/action/ApplicationActionUIModel.java | 73 -- .../swing/action/ApplicationUIAction.java | 235 ---- .../swing/actionng/ApplicationAction.java | 65 - .../swing/actionng/ApplicationActionEngine.java | 101 -- .../swing/actionng/ApplicationActionEvent.java | 95 -- .../swing/actionng/ApplicationActionListener.java | 47 - .../jaxx/application/swing/tab/CustomTab.java | 220 ---- .../swing/tab/DelegateTabContainerHandler.java | 120 -- .../application/swing/tab/TabContainerHandler.java | 76 -- .../application/swing/tab/TabContentModel.java | 44 - .../jaxx/application/swing/tab/TabHandler.java | 58 - .../swing/table/AbstractApplicationTableModel.java | 371 ------ .../swing/table/AbstractSelectTableAction.java | 98 -- .../ApplicationTableModelValidatorDataLocator.java | 76 -- .../application/swing/table/ColumnIdentifier.java | 103 -- .../swing/table/MoveToNextEditableCellAction.java | 100 -- .../swing/table/MoveToNextEditableRowAction.java | 91 -- .../table/MoveToPreviousEditableCellAction.java | 80 -- .../table/MoveToPreviousEditableRowAction.java | 71 -- .../swing/util/ActionListCellRenderer.java | 60 - .../swing/util/ApplicationColorHighlighter.java | 64 - .../swing/util/ApplicationErrorHelper.java | 116 -- .../swing/util/ApplicationExceptionHandler.java | 89 -- .../application/swing/util/ApplicationUIUtil.java | 208 ---- .../jaxx/application/swing/util/Cancelable.java | 34 - .../jaxx/application/swing/util/CloseableUI.java | 42 - .../i18n/jaxx-application-swing_en_GB.properties | 23 - .../i18n/jaxx-application-swing_es_ES.properties | 23 - .../i18n/jaxx-application-swing_fr_FR.properties | 23 - jaxx-application-swing/src/site/site.xml | 44 - pom.xml | 2 - 66 files changed, 7949 deletions(-) diff --git a/jaxx-application-api/LICENSE.txt b/jaxx-application-api/LICENSE.txt deleted file mode 100644 index cca7fc2..0000000 --- a/jaxx-application-api/LICENSE.txt +++ /dev/null @@ -1,165 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. diff --git a/jaxx-application-api/README.md b/jaxx-application-api/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/jaxx-application-api/pom.xml b/jaxx-application-api/pom.xml deleted file mode 100644 index 9cc40ef..0000000 --- a/jaxx-application-api/pom.xml +++ /dev/null @@ -1,100 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - #%L - Ifremer shared :: Application - %% - Copyright (C) 2013 Ifremer, CodeLutin, 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 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% - --> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.nuiton</groupId> - <artifactId>jaxx</artifactId> - <version>3.0-SNAPSHOT</version> - </parent> - - <groupId>org.nuiton.jaxx</groupId> - <artifactId>jaxx-application-api</artifactId> - <name>JAXX :: Application API</name> - - <dependencies> - - <!-- Commons --> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-lang3</artifactId> - </dependency> - <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - </dependency> - <dependency> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-vfs2</artifactId> - </dependency> - - <!-- Guava --> - <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - </dependency> - - <!-- Nuiton --> - <dependency> - <groupId>org.nuiton</groupId> - <artifactId>nuiton-version</artifactId> - </dependency> - <dependency> - <groupId>org.nuiton</groupId> - <artifactId>nuiton-utils</artifactId> - </dependency> - <dependency> - <groupId>org.nuiton</groupId> - <artifactId>nuiton-config</artifactId> - </dependency> - <dependency> - <groupId>org.nuiton.i18n</groupId> - <artifactId>nuiton-i18n</artifactId> - </dependency> - - <!-- SwingX --> - <dependency> - <groupId>org.swinglabs.swingx</groupId> - <artifactId>swingx-common</artifactId> - </dependency> - - - <!-- Test --> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> - - </dependencies> - -</project> diff --git a/jaxx-application-api/src/license/THIRD-PARTY.properties b/jaxx-application-api/src/license/THIRD-PARTY.properties deleted file mode 100644 index cc60d11..0000000 --- a/jaxx-application-api/src/license/THIRD-PARTY.properties +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by org.codehaus.mojo.license.AddThirdPartyMojo -#------------------------------------------------------------------------------- -# Already used licenses in project : -# - BSD License -# - COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 -# - Common Public License Version 1.0 -# - GNU Library or Lesser General Public License -# - Indiana University Extreme! Lab Software License, vesion 1.1.1 -# - Lesser General Public License (LGPL) -# - Lesser General Public License (LGPL) v 3.0 -# - Lesser General Public License (LPGL) -# - Lesser General Public License (LPGL) v 2.1 -# - MIT License -# - New BSD License -# - The Apache Software License, Version 2.0 -#------------------------------------------------------------------------------- -# Please fill the missing licenses for dependencies : -# -# -#Sun Nov 24 23:48:15 CET 2013 -commons-primitives--commons-primitives--1.0=The Apache Software License, Version 2.0 diff --git a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/ApplicationBusinessException.java b/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/ApplicationBusinessException.java deleted file mode 100644 index 6a5b4e7..0000000 --- a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/ApplicationBusinessException.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.nuiton.jaxx.application; - -/* - * #%L - * JAXX :: Application API - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -/** - * Application business exception, a such exeception should be shown to - * user in application. - * - * Created on 11/23/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class ApplicationBusinessException extends RuntimeException { - - private static final long serialVersionUID = 1L; - - public ApplicationBusinessException(String message) { - super(message); - } - - public ApplicationBusinessException(String message, Throwable cause) { - super(message, cause); - } - - public ApplicationBusinessException(Throwable cause) { - super(cause); - } -} diff --git a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/ApplicationConfiguration.java b/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/ApplicationConfiguration.java deleted file mode 100644 index 7e7ec37..0000000 --- a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/ApplicationConfiguration.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.nuiton.jaxx.application; - -/* - * #%L - * JAXX :: Application API - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.nuiton.config.ApplicationConfig; -import org.nuiton.config.ApplicationConfigHelper; -import org.nuiton.config.ApplicationConfigProvider; -import org.nuiton.version.Version; - -import javax.swing.KeyStroke; -import java.util.Set; - -/** - * Created on 11/24/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public abstract class ApplicationConfiguration { - - /** - * Delegate application config. - */ - protected final ApplicationConfig applicationConfig; - - public abstract String getApplicationName(); - - public abstract Version getVersion(); - - /** - * @deprecated since 2.13, use now {@code org.nuiton.jaxx.application.swing.ApplicationUIConfiguration#getShortcutClosePopup()} - */ - @Deprecated - public abstract KeyStroke getShortcutClosePopup(); - - public ApplicationConfiguration(ApplicationConfig applicationConfig) { - this.applicationConfig = applicationConfig; - } - - public ApplicationConfig getApplicationConfig() { - return applicationConfig; - } - - public static Set<ApplicationConfigProvider> loadApplicationConfig(ApplicationConfig applicationConfig) { - - // get all config providers - Set<ApplicationConfigProvider> providers = - ApplicationConfigHelper.getProviders(null, - null, - null, - true); - - // load all default options - ApplicationConfigHelper.loadAllDefaultOption(applicationConfig, providers); - - // load actions - ApplicationConfigHelper.loadAllActions(applicationConfig, providers); - - return providers; - } -} diff --git a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/ApplicationContext.java b/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/ApplicationContext.java deleted file mode 100644 index 04a8b81..0000000 --- a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/ApplicationContext.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.nuiton.jaxx.application; - -/* - * #%L - * JAXX :: Application API - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -/** - * Context of application, may contains config, data sources, ... - * - * Created on 11/23/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public interface ApplicationContext { - - /** - * @return the application configuration - */ - ApplicationConfiguration getConfiguration(); -} diff --git a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/ApplicationDataUtil.java b/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/ApplicationDataUtil.java deleted file mode 100644 index 0d3f39f..0000000 --- a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/ApplicationDataUtil.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.nuiton.jaxx.application; - -/* - * #%L - * JAXX :: Application API - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import com.google.common.base.Preconditions; -import org.apache.commons.beanutils.PropertyUtils; -import org.apache.commons.lang3.time.DurationFormatUtils; -import org.nuiton.jaxx.application.bean.JavaBeanObjectUtil; - -import java.util.Date; - -/** - * Useful methods on data. - * - * TODO Needs some javadoc. - * - * Created on 11/24/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - * @deprecated since 2.12, will not be replaced. - */ -@Deprecated -public class ApplicationDataUtil { - - /** - * @deprecated since 2.12, prefer use {@link JavaBeanObjectUtil#setProperty(Object, String, Object)} - */ - @Deprecated - public static void setProperty(Object bean, String property, Object value) { - Preconditions.checkNotNull(bean); - Preconditions.checkNotNull(property); - try { - PropertyUtils.setSimpleProperty(bean, property, value); - } catch (Exception e) { - throw new ApplicationTechnicalException(String.format("Property %1s not found on object of type %2s", property, bean.getClass().getName()), e); - } - } - - /** - * @deprecated since 2.12, prefer use {@link JavaBeanObjectUtil#getProperty(Object, String)}) - */ - @Deprecated - public static Object getProperty(Object bean, String property) { - Preconditions.checkNotNull(bean); - Preconditions.checkNotNull(property); - try { - return PropertyUtils.getSimpleProperty(bean, property); - } catch (Exception e) { - throw new ApplicationTechnicalException(String.format("Property %1s not found on object of type %2s", property, bean.getClass().getName()), e); - } - } - - public static String getDuration(Date startDate, - Date endDate, - String format) { - String duration = ""; - if (startDate != null && endDate != null && !startDate.after(endDate)) { - duration = DurationFormatUtils.formatPeriod( - startDate.getTime(), - endDate.getTime(), - format); - } - return duration; - } -} diff --git a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/ApplicationIOUtil.java b/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/ApplicationIOUtil.java deleted file mode 100644 index 335b847..0000000 --- a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/ApplicationIOUtil.java +++ /dev/null @@ -1,262 +0,0 @@ -package org.nuiton.jaxx.application; - -/* - * #%L - * JAXX :: Application API - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import com.google.common.base.Charsets; -import com.google.common.io.Files; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.vfs2.FileObject; -import org.apache.commons.vfs2.FileSelector; -import org.apache.commons.vfs2.FileSystemManager; -import org.apache.commons.vfs2.FileType; -import org.apache.commons.vfs2.VFS; -import org.nuiton.util.FileUtil; -import org.nuiton.util.ZipUtil; - -import java.io.Closeable; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.Reader; -import java.io.Writer; -import java.util.Collection; -import java.util.UUID; - -import static org.nuiton.i18n.I18n.t; - -/** - * Useful methods around IO, all method errors are boxes a - * {@link ApplicationTechnicalException}. - * - * Created on 11/24/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class ApplicationIOUtil { - - protected ApplicationIOUtil() { - // no instance - } - - public static void close(Closeable toClose, String errorMessage) { - - try { - toClose.close(); - } catch (IOException e) { - throw new ApplicationTechnicalException(errorMessage, e); - } - } - - public static void zip(File source, File archiveFile, String errorMessage) { - try { - ZipUtil.compress(archiveFile, source); - } catch (IOException e) { - throw new ApplicationTechnicalException(errorMessage, e); - } - } - - public static void zip(File source, File archiveFile, Collection<File> files, String errorMessage) { - try { - ZipUtil.compressFiles(archiveFile, source, files); - } catch (IOException e) { - throw new ApplicationTechnicalException(t(errorMessage, archiveFile), e); - } - } - - public static FileObject resolveFile(String file, String errorMessage) { - try { - FileSystemManager manager = VFS.getManager(); - return manager.resolveFile(file); - } catch (IOException e) { - throw new ApplicationTechnicalException(errorMessage, e); - } - } - - public static FileObject[] getChildren(FileObject objectFile, String errorMessage) { - try { - return objectFile.getChildren(); - } catch (IOException e) { - throw new ApplicationTechnicalException(errorMessage, e); - } - } - - public static FileObject getChild(FileObject objectFile, String name, String errorMessage) { - try { - return objectFile.getChild(name); - } catch (IOException e) { - throw new ApplicationTechnicalException(errorMessage, e); - } - } - - - public static FileType getType(FileObject objectFile, String errorMessage) { - try { - return objectFile.getType(); - } catch (IOException e) { - throw new ApplicationTechnicalException(errorMessage, e); - } - } - - public static void explode(FileObject archiveFile, - File target, - FileSelector fileSelector, String errorMessage) { - try { - FileSystemManager manager = VFS.getManager(); - FileObject targetObject = manager.toFileObject(target); - targetObject.copyFrom(archiveFile, fileSelector); - } catch (IOException e) { - throw new ApplicationTechnicalException(errorMessage, e); - } - } - - public static void forceMkdir(File dir, String errorMessage) { - try { - FileUtils.forceMkdir(dir); - } catch (IOException e) { - throw new ApplicationTechnicalException(errorMessage, e); - } - } - - public static void cleanDirectory(File dir, String errorMessage) { - try { - FileUtils.cleanDirectory(dir); - } catch (IOException e) { - throw new ApplicationTechnicalException(errorMessage, e); - } - } - - public static void deleteDirectory(File dir, String errorMessage) { - try { - FileUtils.deleteDirectory(dir); - } catch (IOException e) { - throw new ApplicationTechnicalException(errorMessage, e); - } - } - - public static void forceDeleteOnExit(File dir, String errorMessage) { - try { - FileUtils.forceDeleteOnExit(dir); - } catch (IOException e) { - throw new ApplicationTechnicalException(errorMessage, e); - } - } - - public static void copyDirectory(File source, File target, String errorMessage) { - try { - FileUtils.copyDirectory(source, target); - } catch (IOException e) { - throw new ApplicationTechnicalException(errorMessage, e); - } - } - - public static void copyFileToDirectory(File source, File target, String errorMessage) { - try { - FileUtils.copyFileToDirectory(source, target); - } catch (IOException e) { - throw new ApplicationTechnicalException(errorMessage, e); - } - } - - public static void copyFile(File source, File target, String errorMessage) { - try { - FileUtils.copyFile(source, target); - } catch (IOException e) { - throw new ApplicationTechnicalException(errorMessage, e); - } - } - - public static void deleteFile(File file, String errorMessage) { - try { - FileUtils.forceDelete(file); - } catch (IOException e) { - throw new ApplicationTechnicalException(errorMessage, e); - } - } - - public static String getBaseName(String file) { - return FilenameUtils.getBaseName(file); - } - - public static String getExtension(String file) { - return FilenameUtils.getExtension(file); - } - - public static Reader newReader(File file, String errorMessage) { - try { - return Files.newReader(file, Charsets.UTF_8); - - } catch (FileNotFoundException e) { - throw new ApplicationTechnicalException(t(errorMessage, file), e); - } - } - - public static Writer newWriter(File file, String errorMessage - ) { - try { - return Files.newWriter(file, Charsets.UTF_8); - - } catch (FileNotFoundException e) { - throw new ApplicationTechnicalException(t(errorMessage, file), e); - } - } - - public static File explodeZip(File rootDirectory, - File file, - String errorMessage) { - File tempDir = new File(rootDirectory, UUID.randomUUID().toString()); - try { - ZipUtil.uncompress(file, tempDir); - } catch (IOException e) { - throw new ApplicationTechnicalException(t(errorMessage, file), e); - } - return tempDir; - } - - public static String readContent(File file, String errorMessage) { - - try { - return FileUtils.readFileToString(file, Charsets.UTF_8); - - } catch (IOException e) { - throw new ApplicationTechnicalException(errorMessage, e); - } - } - - public static void writeContent(File file, String content, String errorMessage) { - try { - FileUtils.write(file, content, Charsets.UTF_8); - } catch (IOException e) { - throw new ApplicationTechnicalException(errorMessage, e); - } - } - - public static File createTemporaryDirectory(String prefix) { - try { - return FileUtil.createTempDirectory(prefix, null); - } catch (IOException e) { - throw new ApplicationTechnicalException("Could not create temporary directory", e); - } - } -} diff --git a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/ApplicationTechnicalException.java b/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/ApplicationTechnicalException.java deleted file mode 100644 index 129964b..0000000 --- a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/ApplicationTechnicalException.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.nuiton.jaxx.application; - -/* - * #%L - * JAXX :: Application API - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -/** - * Application Technical exception. - * - * Created on 11/23/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class ApplicationTechnicalException extends RuntimeException { - - private static final long serialVersionUID = 1L; - - public ApplicationTechnicalException(String message) { - super(message); - } - - public ApplicationTechnicalException(String message, Throwable cause) { - super(message, cause); - } - - public ApplicationTechnicalException(Throwable cause) { - super(cause); - } -} diff --git a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/bean/BinderCache.java b/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/bean/BinderCache.java deleted file mode 100644 index 9dcf693..0000000 --- a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/bean/BinderCache.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.nuiton.jaxx.application.bean; - -/* - * #%L - * JAXX :: Application API - * %% - * Copyright (C) 2008 - 2014 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import org.apache.commons.lang3.tuple.Pair; -import org.nuiton.jaxx.application.ApplicationTechnicalException; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderFactory; - -import java.util.concurrent.ExecutionException; - -/** - * To cache binders. - * - * Created on 8/12/14. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.10 - */ -public class BinderCache { - - public static final LoadingCache<Pair<Class<?>, Class<?>>, Binder> cache = CacheBuilder.newBuilder().build(new CacheLoader<Pair<Class<?>, Class<?>>, Binder>() { - @Override - public Binder load(Pair<Class<?>, Class<?>> key) throws Exception { - return BinderFactory.newBinder(key.getLeft(), key.getRight()); - } - }); - - public static <S, T> Binder<S, T> getBinder(Class<S> sourceType, Class<T> targetType) { - Pair of = Pair.of(sourceType, targetType); - try { - return cache.get(of); - } catch (ExecutionException e) { - throw new ApplicationTechnicalException("Could not get binder from cache", e); - } - } -} diff --git a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/bean/JavaBeanObject.java b/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/bean/JavaBeanObject.java deleted file mode 100644 index 99d1e3d..0000000 --- a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/bean/JavaBeanObject.java +++ /dev/null @@ -1,137 +0,0 @@ -package org.nuiton.jaxx.application.bean; - -/* - * #%L - * JAXX :: Application API - * %% - * Copyright (C) 2008 - 2014 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import java.beans.PropertyChangeListener; - -/** - * Created on 8/12/14. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.10 - */ -public interface JavaBeanObject { - - /** - * Add a PropertyChangeListener to the listener list. - * The listener is registered for all properties. - * The same listener object may be added more than once, and will be called - * as many times as it is added. - * If <code>listener</code> is null, no exception is thrown and no action - * is taken. - * - * @param listener The PropertyChangeListener to be added - */ - void addPropertyChangeListener(PropertyChangeListener listener); - - /** - * Remove a PropertyChangeListener from the listener list. - * This removes a PropertyChangeListener that was registered - * for all properties. - * If <code>listener</code> was added more than once to the same event - * source, it will be notified one less time after being removed. - * If <code>listener</code> is null, or was never added, no exception is - * thrown and no action is taken. - * - * @param listener The PropertyChangeListener to be removed - */ - void removePropertyChangeListener(PropertyChangeListener listener); - - /** - * Returns an array of all the listeners that were added to the - * PropertyChangeSupport object with addPropertyChangeListener(). - * <p> - * If some listeners have been added with a named property, then - * the returned array will be a mixture of PropertyChangeListeners - * and <code>PropertyChangeListenerProxy</code>s. If the calling - * method is interested in distinguishing the listeners then it must - * test each element to see if it's a - * <code>PropertyChangeListenerProxy</code>, perform the cast, and examine - * the parameter. - * - * <pre> - * PropertyChangeListener[] listeners = bean.getPropertyChangeListeners(); - * for (int i = 0; i < listeners.length; i++) { - * if (listeners[i] instanceof PropertyChangeListenerProxy) { - * PropertyChangeListenerProxy proxy = - * (PropertyChangeListenerProxy)listeners[i]; - * if (proxy.getPropertyName().equals("foo")) { - * // proxy is a PropertyChangeListener which was associated - * // with the property named "foo" - * } - * } - * } - * </pre> - * - * @return all of the <code>PropertyChangeListeners</code> added or an - * empty array if no listeners have been added - * @see java.beans.PropertyChangeListenerProxy - */ - PropertyChangeListener[] getPropertyChangeListeners(); - - /** - * Add a PropertyChangeListener for a specific property. The listener - * will be invoked only when a call on firePropertyChange names that - * specific property. - * The same listener object may be added more than once. For each - * property, the listener will be invoked the number of times it was added - * for that property. - * If <code>propertyName</code> or <code>listener</code> is null, no - * exception is thrown and no action is taken. - * - * @param propertyName The name of the property to listen on. - * @param listener The PropertyChangeListener to be added - */ - void addPropertyChangeListener(String propertyName, PropertyChangeListener listener); - - /** - * Remove a PropertyChangeListener for a specific property. - * If <code>listener</code> was added more than once to the same event - * source for the specified property, it will be notified one less time - * after being removed. - * If <code>propertyName</code> is null, no exception is thrown and no - * action is taken. - * If <code>listener</code> is null, or was never added for the specified - * property, no exception is thrown and no action is taken. - * - * @param propertyName The name of the property that was listened on. - * @param listener The PropertyChangeListener to be removed - */ - void removePropertyChangeListener(String propertyName, PropertyChangeListener listener); - - /** - * Returns an array of all the listeners which have been associated - * with the named property. - * - * @param propertyName The name of the property being listened to - * @return all of the <code>PropertyChangeListeners</code> associated with - * the named property. If no such listeners have been added, - * or if <code>propertyName</code> is null, an empty array is - * returned. - */ - PropertyChangeListener[] getPropertyChangeListeners(String propertyName); - - void firePropertyChanged(String propertyName, - Object oldValue, - Object newValue); -} diff --git a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/bean/JavaBeanObjectPropagateChangeListener.java b/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/bean/JavaBeanObjectPropagateChangeListener.java deleted file mode 100644 index 9764808..0000000 --- a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/bean/JavaBeanObjectPropagateChangeListener.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.nuiton.jaxx.application.bean; - -/* - * #%L - * JAXX :: Application API - * %% - * Copyright (C) 2008 - 2014 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; - -/** - * Created on 8/12/14. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.10 - */ -public class JavaBeanObjectPropagateChangeListener implements PropertyChangeListener { - - public static void listenAndPropagate(JavaBeanObject producer, - JavaBeanObject consumer, - String propertyNameToListen, - String propertyNameToForward) { - JavaBeanObjectPropagateChangeListener listener = - new JavaBeanObjectPropagateChangeListener(propertyNameToForward, - consumer); - producer.addPropertyChangeListener(propertyNameToListen, listener); - } - - public static void listenAndPropagateAll(JavaBeanObject producer, - JavaBeanObject consumer) { - JavaBeanObjectPropagateChangeListener listener = - new JavaBeanObjectPropagateChangeListener(null, consumer); - producer.addPropertyChangeListener(listener); - } - - private final String propertyName; - - private final JavaBeanObject editor; - - public JavaBeanObjectPropagateChangeListener(String propertyName, - JavaBeanObject editor) { - this.propertyName = propertyName; - this.editor = editor; - } - - @Override - public void propertyChange(PropertyChangeEvent evt) { - String name = propertyName == null ? evt.getPropertyName() : propertyName; - editor.firePropertyChanged(name, - evt.getOldValue(), - evt.getNewValue()); - } - -} diff --git a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/bean/JavaBeanObjectUtil.java b/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/bean/JavaBeanObjectUtil.java deleted file mode 100644 index 707742d..0000000 --- a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/bean/JavaBeanObjectUtil.java +++ /dev/null @@ -1,109 +0,0 @@ -package org.nuiton.jaxx.application.bean; - -/* - * #%L - * JAXX :: Application API - * %% - * Copyright (C) 2008 - 2014 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import com.google.common.base.Preconditions; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import org.apache.commons.beanutils.PropertyUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.jaxx.application.ApplicationTechnicalException; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeListenerProxy; - -/** - * Created on 8/14/14. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.10 - */ -public class JavaBeanObjectUtil { - - /** Logger. */ - private static final Log log = LogFactory.getLog(JavaBeanObjectUtil.class); - - public static void removeAllPropertyChangeListeners(Iterable<? extends JavaBeanObject> beans) { - for (JavaBeanObject bean : beans) { - removeAllPropertyChangeListeners(bean); - } - } - - public static void removeAllPropertyChangeListeners(JavaBeanObject bean) { - - removePropertyChangeListeners(bean, Predicates.alwaysTrue()); - - } - - public static void removeAllRemovablePropertyChangeListeners(JavaBeanObject bean) { - - removePropertyChangeListeners(bean, input -> input instanceof RemoveablePropertyChangeListener); - - } - - public static void removePropertyChangeListeners(JavaBeanObject bean, Predicate<PropertyChangeListener> predicate) { - - PropertyChangeListener[] propertyChangeListeners = bean.getPropertyChangeListeners(); - for (PropertyChangeListener listener : propertyChangeListeners) { - - if (listener instanceof PropertyChangeListenerProxy) { - - PropertyChangeListenerProxy listenerProxy = (PropertyChangeListenerProxy) listener; - listener = listenerProxy.getListener(); - - } - - if (predicate.apply(listener)) { - - if (log.isDebugEnabled()) { - log.debug("Remove listener: " + listener); - } - bean.removePropertyChangeListener(listener); - - } - - } - - } - - public static void setProperty(Object bean, String property, Object value) { - Preconditions.checkNotNull(bean); - Preconditions.checkNotNull(property); - try { - PropertyUtils.setSimpleProperty(bean, property, value); - } catch (Exception e) { - throw new ApplicationTechnicalException(String.format("Could not set property %1s not found on object of type %2s", property, bean.getClass().getName()), e); - } - } - - public static Object getProperty(Object bean, String property) { - Preconditions.checkNotNull(bean); - Preconditions.checkNotNull(property); - try { - return PropertyUtils.getSimpleProperty(bean, property); - } catch (Exception e) { - throw new ApplicationTechnicalException(String.format("Could not get property %1s on object of type %2s", property, bean.getClass().getName()), e); - } - } -} diff --git a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/bean/RemoveablePropertyChangeListener.java b/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/bean/RemoveablePropertyChangeListener.java deleted file mode 100644 index 106dbc7..0000000 --- a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/bean/RemoveablePropertyChangeListener.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.nuiton.jaxx.application.bean; - -/* - * #%L - * JAXX :: Application API - * %% - * Copyright (C) 2008 - 2014 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import java.beans.PropertyChangeListener; - -/** - * This contract is just used to mark some {@link PropertyChangeListener} we - * want when we reload some ui to remove. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.10 - */ -public abstract class RemoveablePropertyChangeListener implements PropertyChangeListener { -} diff --git a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/listener/PropagatePropertyChangeListener.java b/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/listener/PropagatePropertyChangeListener.java deleted file mode 100644 index bec28f6..0000000 --- a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/listener/PropagatePropertyChangeListener.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.nuiton.jaxx.application.listener; - -/* - * #%L - * JAXX :: Application API - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.jdesktop.beans.AbstractBean; -import org.nuiton.jaxx.application.bean.JavaBeanObjectPropagateChangeListener; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; - -/** - * To listen a bean and propagate some of properties. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - * @deprecated since 2.10, prefer use {@link JavaBeanObjectPropagateChangeListener} - */ -@Deprecated -public class PropagatePropertyChangeListener implements PropertyChangeListener { - - public interface PropagatePropertyChange { - void firePropertyChanged(String propertyName, - Object oldValue, - Object newValue); - } - - public static void listenAndPropagate(AbstractBean producer, - PropagatePropertyChange consumer, - String propertyNameToListen, - String propertyNameToForward) { - PropagatePropertyChangeListener listener = - new PropagatePropertyChangeListener(propertyNameToForward, - consumer); - producer.addPropertyChangeListener(propertyNameToListen, listener); - } - - public static void listenAndPropagateAll(AbstractBean producer, - PropagatePropertyChange consumer) { - PropagatePropertyChangeListener listener = - new PropagatePropertyChangeListener(null, consumer); - producer.addPropertyChangeListener(listener); - } - - private final String propertyName; - - private final PropagatePropertyChange editor; - - public PropagatePropertyChangeListener(String propertyName, - PropagatePropertyChange editor) { - this.propertyName = propertyName; - this.editor = editor; - } - - @Override - public void propertyChange(PropertyChangeEvent evt) { - String name = propertyName == null ? evt.getPropertyName() : propertyName; - editor.firePropertyChanged(name, - evt.getOldValue(), - evt.getNewValue()); - } -} diff --git a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/type/ApplicationProgressionModel.java b/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/type/ApplicationProgressionModel.java deleted file mode 100644 index a963869..0000000 --- a/jaxx-application-api/src/main/java/org/nuiton/jaxx/application/type/ApplicationProgressionModel.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.nuiton.jaxx.application.type; - -/* - * #%L - * JAXX :: Application API - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.jdesktop.beans.AbstractSerializableBean; - -/** - * Simple model for a progression long task. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class ApplicationProgressionModel extends AbstractSerializableBean { - - private static final long serialVersionUID = 1L; - - public static final String PROPERTY_TOTAL = "total"; - - public static final String PROPERTY_CURRENT = "current"; - - public static final String PROPERTY_RATE = "rate"; - - public static final String PROPERTY_MESSAGE = "message"; - - protected int total; - - protected int current; - - protected float rate; - - protected String message; - - public int getTotal() { - return total; - } - - public void setTotal(int total) { - Object oldValue = getTotal(); - this.total = total; - firePropertyChange(PROPERTY_TOTAL, oldValue, total); - setCurrent(0); - } - - public void adaptTotal(int total) { - int current = getCurrent(); - setTotal(total); - increments(current); - Object oldValue = getTotal(); - this.total = total; - firePropertyChange(PROPERTY_TOTAL, oldValue, total); - setCurrent(current); - } - - public int getCurrent() { - return current; - } - - public void setCurrent(int current) { - Object oldValue = getCurrent(); - this.current = current; - firePropertyChange(PROPERTY_CURRENT, oldValue, current); - } - - public void increments(int nb) { - setCurrent(current + nb); - setRate(getCurrent() / getTotal()); - } - - public float getRate() { - return rate; - } - - public void setRate(float rate) { - Object oldValue = getRate(); - this.rate = rate; - firePropertyChange(PROPERTY_RATE, oldValue, rate); - } - - public String getMessage() { - return message; - } - - public void increments(String message) { - increments(1); - setMessage(message); - } - - public void setMessage(String message) { - Object oldValue = getMessage(); - this.message = message; - firePropertyChange(PROPERTY_MESSAGE, oldValue, message); - } -} diff --git a/jaxx-application-api/src/site/site.xml b/jaxx-application-api/src/site/site.xml deleted file mode 100644 index 1a18b30..0000000 --- a/jaxx-application-api/src/site/site.xml +++ /dev/null @@ -1,44 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - #%L - JAXX :: Application API - %% - Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - %% - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser 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 Lesser Public License for more details. - You should have received a copy of the GNU General Lesser Public - License along with this program. If not, see - <http://www.gnu.org/licenses/lgpl-3.0.html>. - #L% - --> - -<project name="${project.name}" - xmlns="http://maven.apache.org/DECORATION/1.4.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/DECORATION/1.4.0 http://maven.apache.org/xsd/decoration-1.4.0.xsd"> - - <bannerLeft> - <name>${project.name}</name> - <src>${siteCommonResourcesUrl}/images/logos/jaxx-logo.png</src> - <href>index.html</href> - </bannerLeft> - - <body> - - <breadcrumbs> - <item name="${project.name}" href="index.html"/> - </breadcrumbs> - - <menu ref="parent"/> - - <menu ref="reports"/> - - </body> -</project> diff --git a/jaxx-application-swing/LICENSE.txt b/jaxx-application-swing/LICENSE.txt deleted file mode 100644 index cca7fc2..0000000 --- a/jaxx-application-swing/LICENSE.txt +++ /dev/null @@ -1,165 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. diff --git a/jaxx-application-swing/README.md b/jaxx-application-swing/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/jaxx-application-swing/pom.xml b/jaxx-application-swing/pom.xml deleted file mode 100644 index 19d4f10..0000000 --- a/jaxx-application-swing/pom.xml +++ /dev/null @@ -1,199 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - #%L - Ifremer shared :: Application Swing - %% - Copyright (C) 2013 Ifremer, CodeLutin, 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 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% - --> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.nuiton</groupId> - <artifactId>jaxx</artifactId> - <version>3.0-SNAPSHOT</version> - </parent> - - <groupId>org.nuiton.jaxx</groupId> - <artifactId>jaxx-application-swing</artifactId> - <name>JAXX :: Application Swing</name> - - <properties> - - <!-- jaxx configuration --> - <jaxx.addProjectClassPath>true</jaxx.addProjectClassPath> - <jaxx.addSourcesToClassPath>true</jaxx.addSourcesToClassPath> - <jaxx.defaultErrorUIFQN> - org.nuiton.jaxx.validator.swing.ui.ImageValidationUI - </jaxx.defaultErrorUIFQN> - <!--<jaxx.useUIManagerForIcon>true</jaxx.useUIManagerForIcon>--> - <jaxx.generateHelp>true</jaxx.generateHelp> - <jaxx.generateSearch>false</jaxx.generateSearch> - <jaxx.autoImportCss>true</jaxx.autoImportCss> - <jaxx.autoRecurseInCss>false</jaxx.autoRecurseInCss> - <jaxx.addAutoHandlerUI>true</jaxx.addAutoHandlerUI> - <jaxx.cssExtension>jcss</jaxx.cssExtension> - - <!-- FIXME ! --> - <i18n.failsIfWarning>false</i18n.failsIfWarning> - - </properties> - - <dependencies> - - <!-- Sibling --> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>jaxx-application-api</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>jaxx-runtime</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>jaxx-validator</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>jaxx-widgets</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>jaxx-widgets-number</artifactId> - <version>${project.version}</version> - </dependency> - - <!-- Commons --> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-lang3</artifactId> - </dependency> - <dependency> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </dependency> - <dependency> - <groupId>commons-httpclient</groupId> - <artifactId>commons-httpclient</artifactId> - <scope>runtime</scope> - </dependency> - - <!-- Guava --> - <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - </dependency> - - <!-- Nuiton --> - <dependency> - <groupId>org.nuiton</groupId> - <artifactId>nuiton-utils</artifactId> - </dependency> - <dependency> - <groupId>org.nuiton</groupId> - <artifactId>nuiton-decorator</artifactId> - </dependency> - <dependency> - <groupId>org.nuiton.i18n</groupId> - <artifactId>nuiton-i18n</artifactId> - </dependency> - <dependency> - <groupId>org.nuiton</groupId> - <artifactId>nuiton-csv</artifactId> - </dependency> - <dependency> - <groupId>org.nuiton</groupId> - <artifactId>nuiton-validator</artifactId> - </dependency> - - <!-- SwingX --> - <dependency> - <groupId>org.swinglabs.swingx</groupId> - <artifactId>swingx-core</artifactId> - </dependency> - <dependency> - <groupId>org.swinglabs.swingx</groupId> - <artifactId>swingx-common</artifactId> - </dependency> - <dependency> - <groupId>org.swinglabs.swingx</groupId> - <artifactId>swingx-autocomplete</artifactId> - </dependency> - - <!-- Logging --> - <!--dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-jcl</artifactId> - <scope>runtime</scope> - </dependency> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <scope>runtime</scope> - </dependency--> - - <!-- Test --> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> - - </dependencies> - - <build> - - <plugins> - - <plugin> - <groupId>org.nuiton.jaxx</groupId> - <artifactId>jaxx-maven-plugin</artifactId> - <version>${project.version}</version> - <executions> - <execution> - <goals> - <goal>generate</goal> - </goals> - </execution> - </executions> - </plugin> - - <plugin> - <groupId>org.nuiton.i18n</groupId> - <artifactId>i18n-maven-plugin</artifactId> - <executions> - <execution> - <id>scan-sources</id> - <goals> - <goal>parserJava</goal> - <goal>gen</goal> - </goals> - </execution> - </executions> - </plugin> - - </plugins> - </build> - -</project> diff --git a/jaxx-application-swing/src/license/THIRD-PARTY.properties b/jaxx-application-swing/src/license/THIRD-PARTY.properties deleted file mode 100644 index de1b7e2..0000000 --- a/jaxx-application-swing/src/license/THIRD-PARTY.properties +++ /dev/null @@ -1,26 +0,0 @@ -# Generated by org.codehaus.mojo.license.AddThirdPartyMojo -#------------------------------------------------------------------------------- -# Already used licenses in project : -# - Apache License -# - Apache License 2.0 -# - BSD License -# - COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 -# - Common Public License Version 1.0 -# - GNU General Public License - Version 2 with the class path exception -# - GNU Library or Lesser General Public License -# - Indiana University Extreme! Lab Software License, vesion 1.1.1 -# - Lesser General Public License (LGPL) -# - Lesser General Public License (LGPL) v 3.0 -# - Lesser General Public License (LPGL) -# - Lesser General Public License (LPGL) v 2.1 -# - MIT License -# - MPL 1.1 -# - New BSD License -# - The Apache Software License, Version 2.0 -#------------------------------------------------------------------------------- -# Please fill the missing licenses for dependencies : -# -# -#Sun Aug 03 12:16:24 CEST 2014 -commons-codec--commons-codec--1.2=The Apache Software License, Version 2.0 -commons-primitives--commons-primitives--1.0=The Apache Software License, Version 2.0 diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/AbstractApplicationFormUIModel.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/AbstractApplicationFormUIModel.java deleted file mode 100644 index 146d6d7..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/AbstractApplicationFormUIModel.java +++ /dev/null @@ -1,289 +0,0 @@ -package org.nuiton.jaxx.application.swing; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jdesktop.beans.AbstractSerializableBean; -import org.nuiton.jaxx.application.ApplicationTechnicalException; -import org.nuiton.jaxx.application.bean.BinderCache; -import org.nuiton.jaxx.application.bean.JavaBeanObject; -import org.nuiton.util.beans.Binder; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.util.Set; - -/** - * A ui form model. - * - * Created on 8/15/14. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.10 - */ -public abstract class AbstractApplicationFormUIModel<E, B extends AbstractApplicationFormUIModel<E, B>> extends AbstractSerializableBean implements JavaBeanObject { - - private static final long serialVersionUID = 1L; - - /** Logger. */ - private static final Log log = LogFactory.getLog(AbstractApplicationFormUIModel.class); - - public static final String PROPERTY_MODIFY = "modify"; - - public static final String PROPERTY_VALID = "valid"; - - public static final String PROPERTY_CREATE = "create"; - - public static final ImmutableSet<String> MODIFY_IGNORE_PROPERTIES = - ImmutableSet.copyOf(Sets.newHashSet( - PROPERTY_MODIFY, - PROPERTY_VALID, - PROPERTY_CREATE)); - - /** - * Modify state of the form. - */ - private boolean modify; - - /** - * Valid state of the form. - */ - private boolean valid; - - /** - * Create state of the form (at true when editing a new object). - */ - private boolean create; - - /** - * To bind for incoming object inside the form. - */ - private final Binder<E, B> fromBeanBinder; - - /** - * To bind fro the from to outside world. - */ - private final Binder<B, E> toBeanBinder; - - /** - * Used to copy the form to outside world. - * - * @return a new instance of outisde world object. - */ - protected abstract E newEntity(); - - protected AbstractApplicationFormUIModel() { - fromBeanBinder = null; - toBeanBinder = null; - } - - protected AbstractApplicationFormUIModel(Class<E> entityType, - Class<B> uiModelType) { - this(BinderCache.getBinder(entityType, uiModelType), - BinderCache.getBinder(uiModelType, entityType)); - } - - protected AbstractApplicationFormUIModel(Binder<E, B> fromBeanBinder, - Binder<B, E> toBeanBinder) { - this.fromBeanBinder = fromBeanBinder; - this.toBeanBinder = toBeanBinder; - } - - /** - * Method to override the copy of incoming entity into the form. - * - * By default, invoke the simple binder copy (method {@link #fromBean(Object)}. - * - * @param entity incoming entity to copy inside the form - */ - public void fromEntity(E entity) { - fromBean(entity); - } - - /** - * Method to override the copy of the form to outside world ({@code entity}). - * - * By default, invoke the simple binder copy (method {@link #toBean(Object)}. - * - * @param entity the outside world object to fill - */ - public void toEntity(E entity) { - toBean(entity); - } - - /** - * <strong>Note:</strong> the method is {@code final}, if you need to customize something, do it in the - * {@link #toEntity(Object)} method. - * - * @return a new instance of object to persist from this form - */ - public final E toEntity() { - E result = newEntity(); - toEntity(result); - return result; - } - - /** - * @param bean object to copy into form using the {@link #fromBeanBinder} binder - */ - public final void fromBean(E bean) { - fromBeanBinder.copy(bean, (B) this); - } - - /** - * @return the new instance of bean binded from form to outside world - */ - public final E toBean() { - E result = newEntity(); - toBean(result); - return result; - } - - /** - * @param bean the bean to bind - * @return the binded form to the given {@code result} - */ - public final E toBean(E bean) { - toBeanBinder.copy((B) this, bean); - return bean; - } - - public boolean isModify() { - return modify; - } - - public void setModify(boolean modify) { - Object oldValue = isModify(); - this.modify = modify; - firePropertyChange(PROPERTY_MODIFY, oldValue, modify); - } - - public boolean isValid() { - return valid; - } - - public void setValid(boolean valid) { - Object oldValue = isValid(); - this.valid = valid; - firePropertyChange(PROPERTY_VALID, oldValue, valid); - } - - public boolean isCreate() { - return create; - } - - public void setCreate(boolean create) { - Object oldValue = isCreate(); - this.create = create; - firePropertyChange(PROPERTY_CREATE, oldValue, create); - } - - - /** - * @return set of property names that will not change the modify state. - */ - protected Set<String> getModifyIgnorePropertyNames() { - return MODIFY_IGNORE_PROPERTIES; - } - - //------------------------------------------------------------------------// - //-- PropagatePropertyChangeListener methods --// - //------------------------------------------------------------------------// - - @Override - public void firePropertyChanged(String propertyName, - Object oldValue, - Object newValue) { - firePropertyChange(propertyName, oldValue, newValue); - } - - //------------------------------------------------------------------------// - //-- To listen bean changes and reflect it to the modifiy state --// - //------------------------------------------------------------------------// - - public final <B extends JavaBeanObject> void listenModelIsModify(B... javaBeanObjects) { - - ModifyPropertyChangeListener listener = new ModifyPropertyChangeListener(this, getModifyIgnorePropertyNames()); - for (B javaBeanObject : javaBeanObjects) { - javaBeanObject.addPropertyChangeListener(listener); - } - - } - - protected <B extends JavaBeanObject> void listenAndModifyModel(Iterable<B> javaBeanObjects) { - - ModifyPropertyChangeListener listener = new ModifyPropertyChangeListener(this, getModifyIgnorePropertyNames()); - for (B javaBeanObject : javaBeanObjects) { - javaBeanObject.addPropertyChangeListener(listener); - } - - } - - //------------------------------------------------------------------------// - //-- Transform methods --// - //------------------------------------------------------------------------// - - protected static <E, B extends AbstractApplicationFormUIModel<E, B>> Function<B, E> modelToEntity() { - return AbstractApplicationFormUIModel::toEntity; - } - - protected static <E, B extends AbstractApplicationFormUIModel<E, B>> Function<E, B> entityToModel(final Class<B> modelType) { - return entity -> { - try { - B model = modelType.newInstance(); - model.fromEntity(entity); - return model; - } catch (Exception e) { - throw new ApplicationTechnicalException("Can't create new model " + modelType.getName(), e); - } - - }; - } - - protected static class ModifyPropertyChangeListener implements PropertyChangeListener { - - private final AbstractApplicationFormUIModel consumer; - - private final Set<String> propertiesToIgnore; - - public ModifyPropertyChangeListener(AbstractApplicationFormUIModel consumer, Set<String> propertiesToIgnore) { - this.consumer = consumer; - this.propertiesToIgnore = propertiesToIgnore; - } - - @Override - public void propertyChange(PropertyChangeEvent evt) { - String propertyName = evt.getPropertyName(); - if (!propertiesToIgnore.contains(propertyName)) { - if (log.isInfoEnabled()) { - log.info("A property changed: " + evt); - } - consumer.setModify(true); - } - } - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/AbstractApplicationUIHandler.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/AbstractApplicationUIHandler.java deleted file mode 100644 index bbf4083..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/AbstractApplicationUIHandler.java +++ /dev/null @@ -1,1316 +0,0 @@ -package org.nuiton.jaxx.application.swing; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import org.nuiton.jaxx.runtime.JAXXUtil; -import org.nuiton.jaxx.runtime.SwingUtil; -import org.nuiton.jaxx.runtime.spi.UIHandler; -import org.nuiton.jaxx.runtime.swing.JAXXWidgetUtil; -import org.nuiton.jaxx.runtime.swing.editor.FileEditor; -import org.nuiton.jaxx.runtime.swing.editor.NumberEditor; -import org.nuiton.jaxx.runtime.swing.editor.SimpleTimeEditor; -import org.nuiton.jaxx.runtime.swing.editor.bean.BeanComboBox; -import org.nuiton.jaxx.runtime.swing.editor.bean.BeanDoubleList; -import org.nuiton.jaxx.runtime.swing.editor.bean.BeanFilterableComboBox; -import org.nuiton.jaxx.runtime.swing.editor.bean.BeanUIUtil; -import org.nuiton.jaxx.widgets.number.NumberCellEditor; -import org.nuiton.jaxx.runtime.swing.editor.gis.DmdCoordinateEditor; -import org.nuiton.jaxx.runtime.swing.editor.gis.DmsCoordinateEditor; -import org.nuiton.jaxx.runtime.swing.renderer.DecoratorListCellRenderer; -import org.nuiton.jaxx.runtime.swing.renderer.DecoratorTableCellRenderer; -import org.nuiton.jaxx.validator.swing.SwingValidator; -import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jdesktop.swingx.JXDatePicker; -import org.jdesktop.swingx.JXTable; -import org.jdesktop.swingx.autocomplete.ComboBoxCellEditor; -import org.jdesktop.swingx.autocomplete.ObjectToStringConverter; -import org.jdesktop.swingx.table.TableColumnExt; -import org.nuiton.decorator.Decorator; -import org.nuiton.decorator.JXPathDecorator; -import org.nuiton.jaxx.application.ApplicationConfiguration; -import org.nuiton.jaxx.application.bean.JavaBeanObjectUtil; -import org.nuiton.jaxx.application.swing.action.AbstractApplicationAction; -import org.nuiton.jaxx.application.swing.action.ApplicationActionUI; -import org.nuiton.jaxx.application.swing.action.ApplicationUIAction; -import org.nuiton.jaxx.application.swing.table.ColumnIdentifier; -import org.nuiton.jaxx.application.swing.util.ApplicationUIUtil; -import org.nuiton.jaxx.application.swing.util.Cancelable; -import org.nuiton.jaxx.application.type.ApplicationProgressionModel; -import org.nuiton.validator.bean.AbstractValidator; -import org.nuiton.validator.bean.list.BeanListValidator; -import org.nuiton.validator.bean.simple.SimpleBeanValidator; - -import javax.swing.AbstractAction; -import javax.swing.AbstractButton; -import javax.swing.Action; -import javax.swing.DefaultComboBoxModel; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JOptionPane; -import javax.swing.JPopupMenu; -import javax.swing.JRootPane; -import javax.swing.JScrollPane; -import javax.swing.JSpinner; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.JViewport; -import javax.swing.KeyStroke; -import javax.swing.ListCellRenderer; -import javax.swing.ListSelectionModel; -import javax.swing.ScrollPaneConstants; -import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; -import javax.swing.UIManager; -import javax.swing.border.LineBorder; -import javax.swing.event.ListSelectionEvent; -import javax.swing.table.TableCellEditor; -import javax.swing.table.TableCellRenderer; -import javax.swing.table.TableColumnModel; -import javax.swing.text.JTextComponent; -import java.awt.Color; -import java.awt.Component; -import java.awt.Container; -import java.awt.Dialog; -import java.awt.Dimension; -import java.awt.Frame; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; -import java.awt.event.HierarchyEvent; -import java.awt.event.ItemEvent; -import java.awt.event.KeyEvent; -import java.awt.event.MouseEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.File; -import java.io.Serializable; -import java.text.ParseException; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static org.nuiton.i18n.I18n.t; - -/** - * Handler of any ui. - * - * Created on 11/23/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public abstract class AbstractApplicationUIHandler<M, UI extends ApplicationUI<M, ?>> implements UIHandler<UI> { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(AbstractApplicationUIHandler.class); - - public abstract void onCloseUI(); - - /** - * @return a single validator :( - * @deprecated since 2.10, prefer use now the {@link #getSimpleValidators()} and {@link #getListValidators()} initialized in {@link #initUI(ApplicationUI)} method. - */ - @Deprecated - public abstract SwingValidator<M> getValidator(); - - public abstract Component getTopestUI(); - - public abstract <E> Decorator<E> getDecorator(Class<E> beanType, String decoratorContext); - - /** - * Hook to prepare popup just before showing it. - * - * The right place to update actions accessibility; a quite better design - * than trying to update each time something change in the table... - * - * @param modelRowIndex selected row index (or lowest selected one) - * @param modelColumnIndex selected column index - * @since 2.6 - */ - protected void beforeOpenPopup(int modelRowIndex, int modelColumnIndex) { - // by default do nothing - } - - /** - * Global application context. - */ - private ApplicationUIContext context; - - /** - * UI handled. - */ - protected UI ui; - - /** - * Simple validators detected in {@link #initUI(ApplicationUI)} method. - * - * @since 2.10 - */ - private Set<SimpleBeanValidator> simpleValidators; - - /** - * List validators detected in {@link #initUI(ApplicationUI)} method. - * - * @since 2.10 - */ - private Set<BeanListValidator> listValidators; - - //------------------------------------------------------------------------// - //-- Public methods --// - //------------------------------------------------------------------------// - - /** - * @deprecated since 2.10, should move this to {@link SwingUtil#newComboModel(Object...)} - */ - @Deprecated - public DefaultComboBoxModel newComboModel(Object... items) { - return SwingUtil.newComboModel(items); - } - - public final M getModel() { - return ui.getModel(); - } - - public final UI getUI() { - return ui; - } - - public Set<SimpleBeanValidator> getSimpleValidators() { - return simpleValidators; - } - - public Set<BeanListValidator> getListValidators() { - return listValidators; - } - - @Override - public void beforeInit(UI ui) { - this.ui = ui; - } - - public ApplicationUIContext getContext() { - if (context == null) { - context = ApplicationUIUtil.getApplicationContext(ui); - } - return context; - } - - public void setText(KeyEvent event, String property) { - JTextComponent field = (JTextComponent) event.getSource(); - String value = field.getText(); - JavaBeanObjectUtil.setProperty(getModel(), property, value); - } - - public void setFile(ActionEvent event, String property) { - FileEditor field = (FileEditor) event.getSource(); - File value = field.getSelectedFile(); - JavaBeanObjectUtil.setProperty(getModel(), property, value); - } - - public void setBoolean(ItemEvent event, String property) { - boolean value = event.getStateChange() == ItemEvent.SELECTED; - JavaBeanObjectUtil.setProperty(getModel(), property, value); - } - - public void setDate(ActionEvent event, String property) { - JXDatePicker field = (JXDatePicker) event.getSource(); - Date value = field.getDate(); - JavaBeanObjectUtil.setProperty(getModel(), property, value); - } - - public void selectListData(ListSelectionEvent event, String property) { - if (!event.getValueIsAdjusting()) { - JList list = (JList) event.getSource(); - ListSelectionModel selectionModel = list.getSelectionModel(); - - selectionModel.setValueIsAdjusting(true); - try { - List<Object> selectedList = Lists.newLinkedList(); - - for (int index : list.getSelectedIndices()) { - Object o = list.getModel().getElementAt(index); - selectedList.add(o); - } - JavaBeanObjectUtil.setProperty(getModel(), property, selectedList); - } finally { - selectionModel.setValueIsAdjusting(false); - } - } - } - - public void openDialog(ApplicationUI dialogContent, - String title, Dimension dim) { - Component topestUI = getTopestUI(); - - JDialog result; - if (topestUI instanceof Frame) { - result = new JDialog((Frame) topestUI, title, true); - } else { - result = new JDialog((Dialog) topestUI, title, true); - } - - result.add((Component) dialogContent); - result.setResizable(true); - - result.setSize(dim); - - final AbstractApplicationUIHandler handler = dialogContent.getHandler(); - - if (handler instanceof Cancelable) { - - // add a auto-close action - JRootPane rootPane = result.getRootPane(); - - KeyStroke shortcutClosePopup = getContext().getConfiguration().getShortcutClosePopup(); - - rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( - shortcutClosePopup, "close"); - rootPane.getActionMap().put("close", new AbstractAction() { - private static final long serialVersionUID = 1L; - - @Override - public void actionPerformed(ActionEvent e) { - ((Cancelable) handler).cancel(); - } - }); - } - - result.addWindowListener(new WindowAdapter() { - - @Override - public void windowClosed(WindowEvent e) { - Component ui = (Component) e.getSource(); - if (log.isDebugEnabled()) { - log.debug("Destroy ui " + ui); - } - JAXXUtil.destroy(ui); - } - }); - SwingUtil.center(getContext().getMainUI(), result); - result.setVisible(true); - } - - public void closeDialog() { - getParentContainer(JDialog.class).setVisible(false); - } - - public <U extends Container> U getParentContainer(Class<U> uiType) { - return SwingUtil.getParentContainer(ui, uiType); - } - - public static final String CONFIRMATION_FORMAT = "<html>%s<hr/><br/>%s</html>"; - - public int askSaveBeforeLeaving(String message) { - String htmlMessage = String.format( - CONFIRMATION_FORMAT, - message, - t("jaxx.application.common.askSaveBeforeLeaving.help")); - return JOptionPane.showConfirmDialog( - getTopestUI(), - htmlMessage, - t("jaxx.application.common.askSaveBeforeLeaving.title"), - JOptionPane.YES_NO_CANCEL_OPTION, - JOptionPane.QUESTION_MESSAGE); - } - - public boolean askCancelEditBeforeLeaving(String message) { - String htmlMessage = String.format( - CONFIRMATION_FORMAT, - message, - t("jaxx.application.common.askCancelEditBeforeLeaving.help")); - int i = JOptionPane.showConfirmDialog( - getTopestUI(), - htmlMessage, - t("jaxx.application.common.askCancelEditBeforeLeaving.title"), - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.QUESTION_MESSAGE); - - return i == JOptionPane.OK_OPTION; - } - - public void showSuccessMessage(String title, String message) { - - Component topestUI = getTopestUI(); - boolean alwaysOnTop = false; - - if (topestUI instanceof JDialog) { - alwaysOnTop = ((JDialog) topestUI).isAlwaysOnTop(); - } - - if (alwaysOnTop) { - ((JDialog) topestUI).setAlwaysOnTop(false); - } - try { - - JOptionPane.showMessageDialog( - topestUI, - message, - title, - JOptionPane.INFORMATION_MESSAGE, - UIManager.getIcon("info") - ); - } finally { - if (alwaysOnTop) { - ((JDialog) topestUI).setAlwaysOnTop(true); - } - } - } - - protected void addHighlighters(final JXTable table) { - - } - - public void autoSelectRowInTable(MouseEvent e, JPopupMenu popup) { - - boolean rightClick = SwingUtilities.isRightMouseButton(e); - - if (rightClick || SwingUtilities.isLeftMouseButton(e)) { - - // get the coordinates of the mouse click - Point p = e.getPoint(); - - JXTable source = (JXTable) e.getSource(); - - int[] selectedRows = source.getSelectedRows(); - int[] selectedColumns = source.getSelectedColumns(); - - // get the row index at this point - int rowIndex = source.rowAtPoint(p); - - // get the column index at this point - int columnIndex = source.columnAtPoint(p); - - if (log.isDebugEnabled()) { - log.debug("At point [" + p + "] found Row " + rowIndex + ", Column " + columnIndex); - } - - boolean canContinue = true; - - if (source.isEditing()) { - - // stop editing - boolean stopEdit = source.getCellEditor().stopCellEditing(); - if (!stopEdit) { - if (log.isWarnEnabled()) { - log.warn("Could not stop edit cell..."); - } - canContinue = false; - } - } - - if (canContinue) { - - // select row (could empty selection) - if (rowIndex == -1) { - source.clearSelection(); - } else if (!ArrayUtils.contains(selectedRows, rowIndex)) { - if (ListSelectionModel.MULTIPLE_INTERVAL_SELECTION == source.getSelectionMode()) { - // add to selection - source.addRowSelectionInterval(rowIndex, rowIndex); - } else { - // set selection - source.setRowSelectionInterval(rowIndex, rowIndex); - } - } - - // select column (could empty selection) - if (columnIndex == -1) { - source.clearSelection(); - } else if (!ArrayUtils.contains(selectedColumns, columnIndex)) { - source.setColumnSelectionInterval(columnIndex, columnIndex); - } - - if (rightClick) { - - // use now model coordinate - int modelRowIndex = rowIndex == -1 ? -1 : source.convertRowIndexToModel(rowIndex); - int modelColumnIndex = columnIndex == -1 ? -1 : source.convertColumnIndexToModel(columnIndex); - - beforeOpenPopup(modelRowIndex, modelColumnIndex); - - // on right click show popup - popup.show(source, e.getX(), e.getY()); - } - } - } - } - - public void openRowMenu(KeyEvent e, JPopupMenu popup) { - - if (e.getKeyCode() == KeyEvent.VK_CONTEXT_MENU) { - - JXTable source = (JXTable) e.getSource(); - - // get the lowest selected row - int[] selectedRows = source.getSelectedRows(); - int lowestRow = -1; - for (int row : selectedRows) { - lowestRow = Math.max(lowestRow, row); - } - // get the selected column - int selectedColumn = source.getSelectedColumn(); - Rectangle r = source.getCellRect(lowestRow, selectedColumn, true); - - // get the point in the middle lower of the cell - Point p = new Point(r.x + r.width / 2, r.y + r.height); - - if (log.isDebugEnabled()) { - log.debug("Row " + lowestRow + " found t point [" + p + "]"); - } - - boolean canContinue = true; - - if (source.isEditing()) { - - // stop editing - boolean stopEdit = source.getCellEditor().stopCellEditing(); - if (!stopEdit) { - if (log.isWarnEnabled()) { - log.warn("Could not stop edit cell..."); - } - canContinue = false; - } - } - - if (canContinue) { - - // use now model coordinate - int rowIndex = source.convertRowIndexToModel(lowestRow); - int columnIndex = source.convertColumnIndexToModel(selectedColumn); - beforeOpenPopup(rowIndex, columnIndex); - - popup.show(source, p.x, p.y); - } - } - } - - //------------------------------------------------------------------------// - //-- Init methods --// - //------------------------------------------------------------------------// - - protected void initUIComponent(Object component) { - if (component instanceof NumberEditor) { - - initNumberEditor((NumberEditor) component); - } else if (component instanceof JXDatePicker) { - - initDatePicker((JXDatePicker) component); - } else if (component instanceof SimpleTimeEditor) { - - initTimeEditor((SimpleTimeEditor) component); - } else if (component instanceof JLabel) { - - initLabel((JLabel) component); - } else if (component instanceof JTextField) { - - initTextField((JTextField) component); - } else if (component instanceof AbstractButton) { - - initButton((AbstractButton) component); - } else if (component instanceof JScrollPane) { - - initScrollPane((JScrollPane) component); - } else if (component instanceof DmsCoordinateEditor) { - - initCoordinateDMSEditor((DmsCoordinateEditor) component); - } else if (component instanceof DmdCoordinateEditor) { - - initCoordinateDMDEditor((DmdCoordinateEditor) component); - } else if (component instanceof SimpleBeanValidator) { - - simpleValidators.add((SimpleBeanValidator) component); - } else if (component instanceof BeanListValidator) { - - listValidators.add((BeanListValidator) component); - } - } - - protected void initUI(UI ui) { - - simpleValidators = Sets.newHashSet(); - listValidators = Sets.newHashSet(); - - for (Map.Entry<String, Object> entry : ui.get$objectMap().entrySet()) { - Object component = entry.getValue(); - initUIComponent(component); - } - - simpleValidators = Collections.unmodifiableSet(simpleValidators); - listValidators = Collections.unmodifiableSet(listValidators); - - initValidators(simpleValidators, listValidators); - - //FIXME This does not work if there is more than one ui - initComponentToFocus((Component) ui); - } - - protected void initComponentToFocus(Component ui) { - ui.addHierarchyListener(e -> { - JComponent component = getComponentToFocus(); - if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) > 0 - && e.getChanged().isShowing() - && component != null) { - component.requestFocus(); - } - }); - } - - protected abstract JComponent getComponentToFocus(); - - protected void initTextField(JTextField jTextField) { - - if (isAutoSelectOnFocus(jTextField)) { - addAutoSelectOnFocus(jTextField); - } - } - - protected void initLabel(JLabel jLabel) { - - // by default do nothing more - } - - protected void initButton(AbstractButton abstractButton) { - - Class actionName = (Class) abstractButton.getClientProperty("applicationAction"); - if (actionName != null) { - Action action = getContext().getActionFactory().createUIAction(this, abstractButton, actionName); - abstractButton.setAction(action); - } - - if (abstractButton.getAction() != null) { - // get the _applicationActionKey property - String key = (String) abstractButton.getClientProperty("applicationActionKey"); - if (key != null) { - affectKeyStroke(abstractButton, key); - } - } - } - - protected void affectKeyStroke(AbstractButton abstractButton, String key) { - - if (abstractButton.getAction() == null) { - log.warn("the buton '" + abstractButton.getName() + "' has no action. can't affect key stroke."); - return; - } - - KeyStroke keyStroke = KeyStroke.getKeyStroke(key); - - if (keyStroke == null) { - - if (log.isWarnEnabled()) { - log.warn("Could not transform keyStroke: " + key); - } - - } else { - - // affect this key stroke to the button's action - abstractButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, key); - abstractButton.getActionMap().put(key, abstractButton.getAction()); - - boolean modifyText = true; - boolean modifyTip = false; - ApplicationConfiguration configuration = context.getConfiguration(); - if (configuration instanceof ApplicationUIConfiguration) { - ApplicationUIConfiguration applicationUIConfiguration = (ApplicationUIConfiguration) configuration; - - modifyText = applicationUIConfiguration.isShowKeyStrokeOnText(); - modifyTip = applicationUIConfiguration.isShowKeyStrokeOnTip(); - - } - - // modify text - String text = abstractButton.getText(); - if (modifyText && !StringUtils.isBlank(text)) { - text += " (" + key.toUpperCase() + ")"; - abstractButton.setText(text); - } - - // modify tip - String tip = abstractButton.getToolTipText(); - if (modifyTip && !StringUtils.isBlank(tip)) { - tip += " (" + key.toUpperCase() + ")"; - abstractButton.setToolTipText(tip); - } - - } - - - } - - /** - * Prépare un component de choix d'entités pour un type d'entité donné et - * pour un service de persistance donné. - * - * @param comboBox le component graphique à initialiser - */ - protected <E> void initBeanFilterableComboBox( - BeanFilterableComboBox<E> comboBox, - List<E> data, - E selectedData) { - - initBeanFilterableComboBox(comboBox, data, selectedData, null); - } - - protected <E> void initBeanFilterableComboBox( - BeanFilterableComboBox<E> comboBox, - List<E> data, - E selectedData, - String decoratorContext) { - - Preconditions.checkNotNull(comboBox, "No comboBox!"); - - Class<E> beanType = comboBox.getBeanType(); - - Preconditions.checkNotNull(beanType, "No beanType on the combobox!"); - - Decorator<E> decorator = getDecorator(beanType, decoratorContext); - - if (data == null) { - data = Lists.newArrayList(); - } - - if (log.isDebugEnabled()) { - log.debug("entity comboBox list [" + beanType.getName() + "] : " + data.size()); - } - - comboBox.setI18nPrefix(getContext().getI18nPrefix()); - - // add data list to combo box - comboBox.init((JXPathDecorator<E>) decorator, data); - - comboBox.setSelectedItem(selectedData); - - if (log.isDebugEnabled()) { - log.debug("combo [" + beanType.getName() + "] : " + - comboBox.getData().size()); - } - } - - protected <E> void initBeanComboBox(BeanComboBox<E> comboBox, - List<E> data, - E selectedData) { - - initBeanComboBox(comboBox, data, selectedData, null); - } - - protected <E> void initBeanComboBox(BeanComboBox<E> comboBox, - List<E> data, - E selectedData, - String decoratorContext) { - - Preconditions.checkNotNull(comboBox, "No comboBox!"); - - Class<E> beanType = comboBox.getBeanType(); - - Preconditions.checkNotNull(beanType, "No beanType on the combobox!"); - - Decorator<E> decorator = getDecorator(beanType, decoratorContext); - - if (data == null) { - data = Lists.newArrayList(); - } - - if (log.isDebugEnabled()) { - log.debug("entity comboBox list [" + beanType.getName() + "] : " + data.size()); - } - - comboBox.setI18nPrefix(getContext().getI18nPrefix()); - - // add data list to combo box - comboBox.init((JXPathDecorator<E>) decorator, data); - - comboBox.setSelectedItem(selectedData); - - if (log.isDebugEnabled()) { - log.debug("combo [" + beanType.getName() + "] : " + - comboBox.getData().size()); - } - } - - /** - * Prépare un component de choix d'entités pour un type d'entité donné et - * pour un service de persistance donné. - * - * @param list le component graphique à initialiser - * @param data la liste des données à mettre dans la liste de gauche - * @param selectedData la liste des données à mettre dans la liste de droite - */ - protected <E> void initBeanList(BeanDoubleList<E> list, - List<E> data, - List<E> selectedData, - Decorator<E> selectedDecorator) { - - Preconditions.checkNotNull(list, "No list!"); - - Class<E> beanType = list.getBeanType(); - Preconditions.checkNotNull(beanType, "No beanType on the double list!"); - - Decorator<E> decorator = getDecorator(beanType, null); - - if (log.isDebugEnabled()) { - log.debug("entity list [" + beanType.getName() + "] : " + - (data == null ? 0 : data.size())); - } - - list.setI18nPrefix(getContext().getI18nPrefix()); - - // add data list to combo box - list.init((JXPathDecorator<E>) decorator, - (JXPathDecorator<E>) selectedDecorator, - data, - selectedData); - - if (log.isDebugEnabled()) { - log.debug("Jlist [" + beanType.getName() + "] : " + - list.getUniverseList().getModel().getSize()); - } - } - - /** - * Prépare un component de choix d'entités pour un type d'entité donné et - * pour un service de persistance donné. - * - * @param list le component graphique à initialiser - * @param data la liste des données à mettre dans la liste de gauche - * @param selectedData la liste des données à mettre dans la liste de droite - */ - protected <E> void initBeanList(BeanDoubleList<E> list, - List<E> data, - List<E> selectedData) { - - initBeanList(list, data, selectedData, null); - } - - protected void initNumberEditor(NumberEditor editor) { - if (log.isDebugEnabled()) { - log.debug("init number editor " + editor.getName()); - } - editor.init(); - - // Force binding if value is already in model - Number model = editor.getModel(); - if (model != null) { - editor.setModel(null); - editor.setModel(model); - } - - if (isAutoSelectOnFocus(editor)) { - - addAutoSelectOnFocus(editor.getTextField()); - } - } - - protected void initTimeEditor(SimpleTimeEditor editor) { - if (log.isDebugEnabled()) { - log.debug("init time editor " + editor.getName() + - " for property " + editor.getModel().getProperty()); - } - editor.init(); - - if (isAutoSelectOnFocus(editor)) { - addAutoSelectOnFocus(((JSpinner.DefaultEditor) editor.getHour().getEditor()).getTextField()); - addAutoSelectOnFocus(((JSpinner.DefaultEditor) editor.getMinute().getEditor()).getTextField()); - } - } - - protected void initCoordinateDMSEditor(DmsCoordinateEditor editor) { - Object property = editor.getClientProperty("longitudeEditor"); - boolean longitudeEditor = property != null && Boolean.valueOf(property.toString()); - editor.init(longitudeEditor); - } - - protected void initCoordinateDMDEditor(DmdCoordinateEditor editor) { - Object property = editor.getClientProperty("longitudeEditor"); - boolean longitudeEditor = property != null && Boolean.valueOf(property.toString()); - editor.init(longitudeEditor); - } - - protected void initDatePicker(final JXDatePicker picker) { - - if (log.isDebugEnabled()) { - log.debug("disable JXDatePicker editor" + picker.getName()); - } - String dateFormat = getContext().getDateFormat(); - picker.setFormats(dateFormat); - picker.setToolTipText(t("jaxx.application.common.datefield.tip", dateFormat)); - picker.getEditor().addFocusListener(new FocusAdapter() { - - @Override - public void focusLost(FocusEvent e) { - try { - picker.commitEdit(); - - } catch (ParseException ex) { - if (log.isDebugEnabled()) { - log.debug("format error", ex); - } - picker.requestFocus(); - } - } - }); - - if (isAutoSelectOnFocus(picker)) { - addAutoSelectOnFocus(picker.getEditor()); - } - } - - protected void initScrollPane(JScrollPane scrollPane) { - Boolean onlyVerticalScrollable = (Boolean) scrollPane.getClientProperty("onlyVerticalScrollable"); - if (onlyVerticalScrollable != null && onlyVerticalScrollable) { - scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); - scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); - - final JViewport viewport = scrollPane.getViewport(); - viewport.addChangeListener(e -> { - Dimension newDimension = new Dimension(viewport.getExtentSize().width, - viewport.getViewSize().height); - viewport.setViewSize(newDimension); - }); - } - } - - protected void initValidators(Set<SimpleBeanValidator> simpleValidators, Set<BeanListValidator> listValidators) { - - M model = getModel(); - if (useSimpleValidators() || useListValidators()) { - - Set<AbstractValidator> validators = Sets.newHashSet(); - validators.addAll(simpleValidators); - validators.addAll(listValidators); - - ValidatorsValidPropertyChangeListener listener = new ValidatorsValidPropertyChangeListener((AbstractApplicationFormUIModel) model, validators); - for (AbstractValidator validator : validators) { - - if (log.isInfoEnabled()) { - log.info("Listen valid state of validator: " + validator); - } - validator.addPropertyChangeListener(SimpleBeanValidator.VALID_PROPERTY, listener); - - } - - } - - } - - protected boolean useListValidators() { - return getModel() instanceof AbstractApplicationFormUIModel && !listValidators.isEmpty(); - } - - protected boolean useSimpleValidators() { - return getModel() instanceof AbstractApplicationFormUIModel && !simpleValidators.isEmpty(); - } - - protected boolean isAutoSelectOnFocus(JComponent comp) { - Object selectOnFocus = comp.getClientProperty("selectOnFocus"); - return selectOnFocus != null && Boolean.valueOf(selectOnFocus.toString()); - } - - protected void addAutoSelectOnFocus(JTextField jTextField) { - jTextField.addFocusListener(new FocusAdapter() { - @Override - public void focusGained(final FocusEvent e) { - SwingUtilities.invokeLater(() -> { - JTextField source = (JTextField) e.getSource(); - source.selectAll(); - }); - - } - }); - } - - /** - * @deprecated since 2.11, use now {@link #quitScreen(boolean, boolean, String, String, Action, boolean)} - */ - @Deprecated - protected boolean quitScreen(boolean modelIsValid, - boolean modelIsModify, - String askGiveUpMessage, - String askSaveMessage, - Action saveAction) { - - return quitScreen(modelIsValid, - modelIsModify, - askGiveUpMessage, - askSaveMessage, - saveAction, - false); - - } - - /** - * @deprecated since 2.11, use now {@link #quitScreen(boolean, boolean, String, String, Action, boolean)} - */ - @Deprecated - protected boolean quitInternalScreen(boolean modelIsValid, - boolean modelIsModify, - String askGiveUpMessage, - String askSaveMessage, - Action saveAction) { - - return quitScreen(modelIsValid, - modelIsModify, - askGiveUpMessage, - askSaveMessage, - saveAction, - true); - - } - - protected boolean quitScreen(boolean modelIsValid, - boolean modelIsModify, - String askGiveUpMessage, - String askSaveMessage, - Action saveAction, - boolean runInternal) { - boolean result; - - if (!modelIsValid) { - - // model is not valid - // ask user to qui or not - result = askCancelEditBeforeLeaving(askGiveUpMessage); - - } else if (modelIsModify) { - - // something is modify ask user what to do - int answer = askSaveBeforeLeaving(askSaveMessage); - switch (answer) { - case JOptionPane.YES_OPTION: - - // ok save - if (runInternal) { - - ApplicationUIAction uiAction = (ApplicationUIAction) saveAction; - getContext().getActionEngine().runFullInternalAction(uiAction.getLogicAction()); - - } else { - - saveAction.actionPerformed(null); - - } - result = true; - break; - case JOptionPane.NO_OPTION: - - // do not save but can still quit the screen (so nothing to do) - result = true; - break; - default: - // do not save and stay here (so nothing to do) - result = false; - - } - } else { - - // model is valid and not modify, can safely quit screen - result = true; - } - return result; - } - - //------------------------------------------------------------------------// - //-- Decorator API --// - //------------------------------------------------------------------------// - - protected String decorate(Serializable object) { - return decorate(object, null); - } - - protected String decorate(Serializable object, String context) { - String result = ""; - if (object != null) { - result = getDecorator(object.getClass(), context).toString(object); - } - return result; - } - - //------------------------------------------------------------------------// - //-- List API --// - //------------------------------------------------------------------------// - - protected <O> ListCellRenderer newListCellRender(Class<O> type) { - - return newListCellRender(type, null); - } - - protected <O> ListCellRenderer newListCellRender(Class<O> type, String name) { - - Decorator<O> decorator = getDecorator(type, name); - return newListCellRender(decorator); - } - - protected <O> ListCellRenderer newListCellRender(Decorator<O> decorator) { - - Preconditions.checkNotNull(decorator); - - return new DecoratorListCellRenderer(decorator); - } - - //FIXME Move this in JAXX - protected <B> void changeValidatorContext(String newContext, - SwingValidator<B> validator) { - B bean = validator.getBean(); - validator.setContext(newContext); - validator.setBean(bean); - } - - //------------------------------------------------------------------------// - //-- Table API --// - //------------------------------------------------------------------------// - - protected <R> TableColumnExt addColumnToModel(TableColumnModel model, - TableCellEditor editor, - TableCellRenderer renderer, - ColumnIdentifier<R> identifier) { - - TableColumnExt col = new TableColumnExt(model.getColumnCount()); - col.setCellEditor(editor); - col.setCellRenderer(renderer); - String label = t(identifier.getHeaderI18nKey()); - - col.setHeaderValue(label); - String tip = t(identifier.getHeaderTipI18nKey()); - - col.setToolTipText(tip); - - col.setIdentifier(identifier); - model.addColumn(col); - // by default no column is sortable, must specify it - col.setSortable(false); - return col; - } - - protected <R> TableColumnExt addColumnToModel(TableColumnModel model, - ColumnIdentifier<R> identifier) { - - return addColumnToModel(model, null, null, identifier); - } - - protected <R> TableColumnExt addFloatColumnToModel(TableColumnModel model, - ColumnIdentifier<R> identifier, - String numberPattern, - boolean sign, - JTable table) { - - NumberCellEditor<Float> editor = new NumberCellEditor<>(Float.class, sign); - editor.getNumberEditor().setSelectAllTextOnError(true); - editor.getNumberEditor().getTextField().setBorder(new LineBorder(Color.GRAY, 2)); - editor.getNumberEditor().setNumberPattern(numberPattern); - - TableCellRenderer renderer = - newNumberCellRenderer(table.getDefaultRenderer(Number.class)); - - return addColumnToModel(model, editor, renderer, identifier); - } - - protected <R> TableColumnExt addFloatColumnToModel(TableColumnModel model, - ColumnIdentifier<R> identifier, - String numberPattern, - JTable table) { - - return addFloatColumnToModel(model, identifier, numberPattern, false, table); - } - - protected <R> TableColumnExt addIntegerColumnToModel(TableColumnModel model, - ColumnIdentifier<R> identifier, - String numberPattern, - boolean sign, - JTable table) { - - NumberCellEditor<Integer> editor = new NumberCellEditor<>(Integer.class, sign); - editor.getNumberEditor().setSelectAllTextOnError(true); - editor.getNumberEditor().getTextField().setBorder(new LineBorder(Color.GRAY, 2)); - editor.getNumberEditor().setNumberPattern(numberPattern); - - TableCellRenderer renderer = newNumberCellRenderer(table.getDefaultRenderer(Number.class)); - return addColumnToModel(model, editor, renderer, identifier); - } - - protected <R> TableColumnExt addIntegerColumnToModel(TableColumnModel model, - ColumnIdentifier<R> identifier, - String numberPattern, - JTable table) { - - return addIntegerColumnToModel(model, identifier, numberPattern, false, table); - } - - protected TableCellRenderer newNumberCellRenderer(final TableCellRenderer defaultRenderer) { - return (table, value, isSelected, hasFocus, row, column) -> { - Component result1 = defaultRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - if (result1 instanceof JLabel) { - JLabel jLabel = (JLabel) result1; - jLabel.setHorizontalTextPosition(SwingConstants.RIGHT); - - } - return result1; - }; - } - - - protected <R> TableColumnExt addBooleanColumnToModel(TableColumnModel model, - ColumnIdentifier<R> identifier, - JTable table) { - - return addColumnToModel(model, - table.getDefaultEditor(Boolean.class), - table.getDefaultRenderer(Boolean.class), - identifier); - } - - protected <R, B> TableColumnExt addComboDataColumnToModel(TableColumnModel model, - ColumnIdentifier<R> identifier, - Decorator<B> decorator, - List<B> data) { - JComboBox comboBox = new JComboBox(); - comboBox.setRenderer(newListCellRender(decorator)); - - List<B> dataToList = Lists.newArrayList(data); - - // add a null value at first position - if (!dataToList.isEmpty() && dataToList.get(0) != null) { - dataToList.add(0, null); - } - SwingUtil.fillComboBox(comboBox, dataToList, null); - - ObjectToStringConverter converter = BeanUIUtil.newDecoratedObjectToStringConverter(decorator); - BeanUIUtil.decorate(comboBox, converter); - ComboBoxCellEditor editor = new ComboBoxCellEditor(comboBox); - - return addColumnToModel(model, - editor, - newTableCellRender(decorator), - identifier); - } - - protected <O> TableCellRenderer newTableCellRender(Class<O> type) { - - return newTableCellRender(type, null); - } - - protected <O> TableCellRenderer newTableCellRender(Class<O> type, String name) { - - Decorator<O> decorator = getDecorator(type, name); - - return newTableCellRender(decorator); - } - - protected <O> TableCellRenderer newTableCellRender(Decorator<O> decorator) { - - Preconditions.checkNotNull(decorator); - - return new DecoratorTableCellRenderer(decorator, true); - } - - protected void incrementsMessage(String message) { - - ApplicationActionUI actionUI = getContext().getActionUI(); - if (actionUI != null) { - ApplicationProgressionModel progressionModel = actionUI.getModel().getProgressionModel(); - if (progressionModel != null) - - progressionModel.increments(message); - } - } - - /** - * - */ - private static class ValidatorsValidPropertyChangeListener implements PropertyChangeListener { - - private final AbstractApplicationFormUIModel model; - - private final Set<AbstractValidator> validators; - - public ValidatorsValidPropertyChangeListener(AbstractApplicationFormUIModel model, - Set<AbstractValidator> validators) { - this.model = model; - this.validators = validators; - } - - @Override - public void propertyChange(PropertyChangeEvent evt) { - - boolean valid = true; - for (AbstractValidator validator : validators) { - if (!validator.isValid()) { - valid = false; - break; - } - } - - model.setValid(valid); - - } - } - - protected static class RunFullInternalActionListener implements PropertyChangeListener { - - private final ApplicationUIContext context; - - private final AbstractApplicationAction uiAction; - - public RunFullInternalActionListener(ApplicationUIContext context, AbstractApplicationUIHandler handler, Class actionName) { - this.context = context; - this.uiAction = context.getActionFactory().createLogicAction(handler, actionName); - } - - protected boolean doPropertyChange(PropertyChangeEvent evt) { - return true; - } - - @Override - public void propertyChange(PropertyChangeEvent evt) { - - boolean doPropertyChange = doPropertyChange(evt); - - if (doPropertyChange) { - if (log.isInfoEnabled()) { - log.info("Execute action start: " + uiAction); - } - - context.getActionEngine().runFullInternalAction(uiAction); - - if (log.isInfoEnabled()) { - log.info("Execute action end: " + uiAction); - } - } - - } - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/ApplicationUI.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/ApplicationUI.java deleted file mode 100644 index c82f1b6..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/ApplicationUI.java +++ /dev/null @@ -1,143 +0,0 @@ -package org.nuiton.jaxx.application.swing; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.nuiton.jaxx.runtime.JAXXObject; - -/** - * Contract to place on each ui. - * - * Created on 11/23/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public interface ApplicationUI<M, H extends AbstractApplicationUIHandler<M, ?>> extends JAXXObject { - - M getModel(); - - H getHandler(); - - /** - * Pattern to use for short numeric values in editors with max 1 digits. - * - * @since 0.2 - */ - String INT_1_DIGITS_PATTERN = "\\d{0,1}"; - - /** - * Pattern to use for short numeric values in editors with max 2 digits. - * - * @since 0.1 - */ - String INT_2_DIGITS_PATTERN = "\\d{0,2}"; - - /** - * Pattern to use for signed numeric values in editors with max 2 digits. - * - * @since 2.8 - */ - String SIGNED_INT_2_DIGITS_PATTERN = "-?\\d{0,2}"; - - /** - * Pattern to use for short numeric values in editors with max 3 digits. - * - * @since 0.1 - */ - String INT_3_DIGITS_PATTERN = "\\d{0,3}"; - - /** - * Pattern to use for singed numeric values in editors with max 3 digits. - * - * @since 2.8 - */ - String SIGNED_INT_3_DIGITS_PATTERN = "-?\\d{0,3}"; - - /** - * Pattern to use for short numeric values in editors with max 4 digits. - * - * @since 0.2 - */ - String INT_4_DIGITS_PATTERN = "\\d{0,4}"; - - /** - * Pattern to use for integer numeric values in editors with max 6 digits. - * - * @since 0.1 - */ - String INT_6_DIGITS_PATTERN = "\\d{0,6}"; - - /** - * Pattern to use for integer numeric values in editors with max 7 digits. - * - * @since 0.1 - */ - String INT_7_DIGITS_PATTERN = "\\d{0,7}"; - - /** - * Pattern to use for integer numeric values in editors with max 10 digits. - * - * @since 2.10 - */ - String INT_10_DIGITS_PATTERN = "\\d{0,10}"; - - /** - * Pattern to use for decimal numeric values with 1 decimal digits in - * editors. - * - * @since 0.1 - */ - String DECIMAL1_PATTERN = "\\d{0,6}(\\.\\d{0,1})?"; - - /** - * Pattern to use for decimal numeric values with 2 decimal digits in - * editors. - * - * @since 0.1 - */ - String DECIMAL2_PATTERN = "\\d{0,6}(\\.\\d{0,2})?"; - - /** - * Pattern to use for decimal numeric values with 3 decimal digits in - * editors. - * - * @since 0.1 - */ - String DECIMAL3_PATTERN = "\\d{0,6}(\\.\\d{0,3})?"; - - /** - * Pattern to use for decimal numeric values with 4 decimal digits in - * editors. - * - * @since 2.6 - */ - String DECIMAL4_PATTERN = "\\d{0,6}(\\.\\d{0,4})?"; - - /** - * Pattern to use for decimal numeric values with 2 digits + 3 decimal digits in - * editors. - * - * @since 2.8 - */ - String DECIMAL2_DIGITS_PATTERN = "\\d{0,2}(\\.\\d*)?"; -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/ApplicationUIConfiguration.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/ApplicationUIConfiguration.java deleted file mode 100644 index 9061842..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/ApplicationUIConfiguration.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.nuiton.jaxx.application.swing; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import javax.swing.KeyStroke; - -/** - * Contract to place on ui configuration. - * - * Created on 9/19/14. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.13 - */ -public interface ApplicationUIConfiguration { - - KeyStroke getShortcutClosePopup(); - - boolean isShowKeyStrokeOnText(); - - boolean isShowKeyStrokeOnTip(); - -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/ApplicationUIContext.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/ApplicationUIContext.java deleted file mode 100644 index 4828278..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/ApplicationUIContext.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.nuiton.jaxx.application.swing; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.nuiton.jaxx.application.ApplicationContext; -import org.nuiton.jaxx.application.swing.action.ApplicationActionEngine; -import org.nuiton.jaxx.application.swing.action.ApplicationActionFactory; -import org.nuiton.jaxx.application.swing.action.ApplicationActionUI; -import org.nuiton.jaxx.application.swing.action.ApplicationUIAction; -import org.nuiton.jaxx.application.swing.util.ApplicationErrorHelper; - -import java.awt.Color; -import java.awt.Component; - -/** - * Created on 11/24/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public interface ApplicationUIContext extends ApplicationContext { - - /** - * @return the main ui of the application. - */ - Component getMainUI(); - - /** - * @return the ui used to display long action. - */ - ApplicationActionUI getActionUI(); - - /** - * Wait until the action ui is not null and then returns it. - * - * @return the ui used to display long action. - */ - ApplicationActionUI getExistingActionUI(); - - Component getBodyUI(); - - Component getStatusUI(); - - boolean isBusy(); - - void setBusy(boolean busy); - - boolean isHideBody(); - - void setHideBody(boolean b); - - Color getColorBlockingLayer(); - - ApplicationActionFactory getActionFactory(); - - ApplicationActionEngine getActionEngine(); - - ApplicationErrorHelper getErrorHelper(); - - String getI18nPrefix(); - - String getDateFormat(); - - /** Is the action already running? If yes, it will not run again (cf https://forge.nuiton.org/issues/3499) */ - boolean isActionInProgress(ApplicationUIAction action); - - void setActionInProgress(ApplicationUIAction action, boolean actionInProgress); -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/AbstractApplicationAction.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/AbstractApplicationAction.java deleted file mode 100644 index 1da7ab4..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/AbstractApplicationAction.java +++ /dev/null @@ -1,438 +0,0 @@ -package org.nuiton.jaxx.application.swing.action; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import com.google.common.base.Preconditions; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jdesktop.beans.AbstractBean; -import org.nuiton.decorator.Decorator; -import org.nuiton.jaxx.application.ApplicationConfiguration; -import org.nuiton.jaxx.application.swing.AbstractApplicationUIHandler; -import org.nuiton.jaxx.application.swing.ApplicationUI; -import org.nuiton.jaxx.application.swing.ApplicationUIContext; -import org.nuiton.jaxx.application.type.ApplicationProgressionModel; -import org.nuiton.jaxx.runtime.JaxxFileChooser; - -import javax.swing.JOptionPane; -import java.awt.Component; -import java.io.File; -import java.util.Arrays; - -import static org.nuiton.i18n.I18n.t; - -/** - * Tutti base action. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public abstract class AbstractApplicationAction<M extends AbstractBean, UI extends ApplicationUI<M, ?>, H extends AbstractApplicationUIHandler<M, UI>> - extends AbstractBean { - - /** Logger. */ - private static final Log log = LogFactory.getLog(AbstractApplicationAction.class); - - public static final String PROPERTY_DONE = "done"; - - public static final String MESAGE_FORMAT = "<html>%s</html>"; - - protected final H handler; - - protected String actionDescription; - - protected final boolean hideBody; - - protected final Object lock = new Object(); - - public abstract void doAction(); - - protected AbstractApplicationAction(H handler, boolean hideBody) { - this.handler = handler; - this.hideBody = hideBody; - } - - public boolean prepareAction() { - // by default nothing to prepare - return true; - } - - protected void releaseAction() { - // by default nothing to clean - firePropertyChange(PROPERTY_DONE, null, true); - } - - public void postSuccessAction() { - // by default nothing to do after action - } - - public void postFailedAction(Throwable error) { - // by default nothing to do after action - } - - public H getHandler() { - return handler; - } - - public M getModel() { - return handler.getModel(); - } - - public final UI getUI() { - return handler.getUI(); - } - - public ApplicationUIContext getContext() { - return handler.getContext(); - } - - public String getActionDescription() { - return actionDescription; - } - - public void setActionDescription(String actionDescription) { - this.actionDescription = actionDescription; - } - - public void setProgressionModel(ApplicationProgressionModel progressionModel) { - getContext().getActionUI().getModel().setProgressionModel(progressionModel); - } - - protected ApplicationProgressionModel getProgressionModel() { - return getContext().getActionUI().getModel().getProgressionModel(); - } - - public boolean isHideBody() { - return hideBody; - } - - protected ApplicationConfiguration getConfig() { - return getContext().getConfiguration(); - } - - protected abstract void sendMessage(String message); - - protected <O> Decorator<O> getDecorator(Class<O> type, String name) { - Decorator<O> decorator = handler.getDecorator(type, name); - Preconditions.checkNotNull(decorator); - return decorator; - } - - protected String decorate(Object object) { - return getDecorator(object.getClass(), null).toString(object); - } - - protected String decorate(Object object, String context) { - return getDecorator(object.getClass(), context).toString(object); - } - - /** - * Choisir un fichier via un sélecteur graphique de fichiers. - * - * @param title le titre du dialogue de sélection - * @param buttonLabel le label du boutton d'acceptation - * @param filters les filtres + descriptions sur le sélecteur de - * fichiers - * @return le fichier choisi ou le fichier incoming si l'opération a été - * annulée - */ - protected File chooseFile(String title, - String buttonLabel, - String... filters) { - - File file = JaxxFileChooser.forLoadingFile() - .setTitle(title) - .setParent((Component) getUI()) - .setApprovalText(buttonLabel) - .setPatternOrDescriptionFilters(Arrays.asList(filters)) - .choose(); - -// File file = FileChooserUtil.getFile(title, -// buttonLabel, -// getContext().getMainUI(), -// filters); - if (log.isDebugEnabled()) { - log.debug(title + " : " + file); - } - if (file != null) { - File newDir = file.isDirectory() ? file : file.getParentFile(); - JaxxFileChooser.setCurrentDirectory(newDir); - } - return file; - } - - /** - * Sauver un fichier via un sélecteur graphique de fichiers. - * - * @param title le titre du dialogue de sélection - * @param buttonLabel le label du boutton d'acceptation - * @param filters les filtres + descriptions sur le sélecteur de - * fichiers - * @return le fichier choisi ou {@code null} si pas de fichier choisi ou - * pas voulu écrasé un fichier existant. - */ - protected File saveFile(File defaultFile, - String filename, - String extension, - String title, - String buttonLabel, - String... filters) { - - if (defaultFile != null && JaxxFileChooser.isCurrentDirectoryDefault()) { - - // set default directory to this one - JaxxFileChooser.setCurrentDirectory(defaultFile); - } - return saveFile(filename, extension, title, buttonLabel, filters); - } - - /** - * Sauver un fichier via un sélecteur graphique de fichiers. - * - * @param title le titre du dialogue de sélection - * @param buttonLabel le label du boutton d'acceptation - * @param filters les filtres + descriptions sur le sélecteur de - * fichiers - * @return le fichier choisi ou {@code null} si pas de fichier choisi ou - * pas voulu écrasé un fichier existant. - */ - protected File saveFile(String filename, - String extension, - String title, - String buttonLabel, - String... filters) { - - boolean withExtension = StringUtils.isNotBlank(extension); - String filenameSuffix = withExtension ? "." + extension : ""; - - File file = JaxxFileChooser.forSaving() - .setTitle(title) - .setParent((Component) getUI()) - .setApprovalText(buttonLabel) - .setPatternOrDescriptionFilters(Arrays.asList(filters)) - .setFilename(filename + filenameSuffix) - .choose(); - - //File file = FileChooserUtil.saveFile(filename + filenameSuffix, title, buttonLabel, getContext().getMainUI(), filters); - if (log.isDebugEnabled()) { - log.debug(title + " : " + file); - } - if (file != null) { - Preconditions.checkState(!file.isDirectory()); - - // add extension if missing - if (withExtension && !file.getName().endsWith(filenameSuffix)) { - file = new File(file.getParentFile(), file.getName() + filenameSuffix); - } - - // ask user to confirm overwrite. - boolean confirm = askOverwriteFile(file); - - if (confirm) { - - // on conserve le répertoire (pour une prochaine utilisation) - JaxxFileChooser.setCurrentDirectory(file.getParentFile()); - } else { - - // l'utilisateur n'a pas confirmé l'écrasement - // donc pas de fichier en retour - file = null; - } - } - - return file; - } - - /** - * Sauver un fichier via un sélecteur graphique de fichiers, en précisant - * le répertoire où sauvegarder le fichier. - * - * @param startDirectory le répertoire à utiliser pour choisir le fichier - * @param keepCurrentDirectory un drapeau pour dire si on veut ou pas conserver le répertoire choisit comme nouveau répertoire par défaut - * @param title le titre du dialogue de sélection - * @param buttonLabel le label du boutton d'acceptation - * @param filters les filtres + descriptions sur le sélecteur de - * fichiers - * @return le fichier choisi ou {@code null} si pas de fichier choisi ou - * pas voulu écrasé un fichier existant. - * @since 2.17 - */ - protected File saveFileWithStartDirectory(File startDirectory, - boolean keepCurrentDirectory, - String filename, - String extension, - String title, - String buttonLabel, - String... filters) { - - boolean withExtension = StringUtils.isNotBlank(extension); - String filenameSuffix = withExtension ? "." + extension : ""; - - File file = JaxxFileChooser.forSaving() - .setStartDirectory(startDirectory) - .setKeepCurrentDirectory(keepCurrentDirectory) - .setTitle(title) - .setParent((Component) getUI()) - .setApprovalText(buttonLabel) - .setPatternOrDescriptionFilters(Arrays.asList(filters)) - .setFilename(filename + filenameSuffix) - .choose(); - - //File file = FileChooserUtil.saveFile(filename + filenameSuffix, title, buttonLabel, getContext().getMainUI(), filters); - if (log.isDebugEnabled()) { - log.debug(title + " : " + file); - } - if (file != null) { - Preconditions.checkState(!file.isDirectory()); - - // add extension if missing - if (withExtension && !file.getName().endsWith(filenameSuffix)) { - file = new File(file.getParentFile(), file.getName() + filenameSuffix); - } - - // ask user to confirm overwrite. - boolean confirm = askOverwriteFile(file); - - if (confirm) { - - if (keepCurrentDirectory) { - - // on conserve le répertoire (pour une prochaine utilisation) - JaxxFileChooser.setCurrentDirectory(file.getParentFile()); - - } - - } else { - - // l'utilisateur n'a pas confirmé l'écrasement - // donc pas de fichier en retour - file = null; - } - } - - return file; - } - - protected boolean askOverwriteFile(File file) { - boolean result; - if (file.exists()) { - - // file exists ask user to overwrite - String htmlMessage = String.format( - AbstractApplicationUIHandler.CONFIRMATION_FORMAT, - t("jaxx.application.common.askOverwriteFile.message", file), - t("jaxx.application.common.askOverwriteFile.help")); - - Component ui = getDialogParentComponent(); - - result = JOptionPane.showConfirmDialog( - ui, - htmlMessage, - t("jaxx.application.common.askOverwriteFile.title"), - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION; - } else { - - // file does not exist - result = true; - } - return result; - } - - protected boolean askBeforeDelete(String title, String message) { - String htmlMessage = String.format( - AbstractApplicationUIHandler.CONFIRMATION_FORMAT, - message, - t("jaxx.application.common.askBeforeDelete.help")); - Component ui = getDialogParentComponent(); - int i = JOptionPane.showConfirmDialog( - ui, - htmlMessage, - title, - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.QUESTION_MESSAGE); - - return i == JOptionPane.OK_OPTION; - } - - protected void displayInfoMessage(String title, String message) { - String htmlMessage = String.format(MESAGE_FORMAT, message); - Component ui = getDialogParentComponent(); - JOptionPane.showMessageDialog( - ui, - htmlMessage, - title, - JOptionPane.INFORMATION_MESSAGE); - } - - protected void displayWarningMessage(String title, String message) { - String htmlMessage = String.format(MESAGE_FORMAT, message); - - Component ui = getDialogParentComponent(); - JOptionPane.showMessageDialog( - ui, - htmlMessage, - title, - JOptionPane.WARNING_MESSAGE); - } - - protected void displayErrorMessage(String title, String message) { - String htmlMessage = String.format(MESAGE_FORMAT, message); - Component ui = getDialogParentComponent(); - JOptionPane.showMessageDialog( - ui, - htmlMessage, - title, - JOptionPane.ERROR_MESSAGE); - } - - protected Component getDialogParentComponent() { - Component ui = getContext().getMainUI(); - if (ui==null) { - ui = getHandler().getTopestUI(); - } - return ui; - } - - protected void createProgressionModelIfRequired(int total) { - ApplicationProgressionModel progressionModel = getProgressionModel(); - if (progressionModel == null) { - progressionModel = new ApplicationProgressionModel(); - progressionModel.setTotal(total); - progressionModel.setMessage(""); - progressionModel.setCurrent(0); - setProgressionModel(progressionModel); - } else { - progressionModel.adaptTotal(total); - } - } - - public ApplicationActionFactory getActionFactory() { - return getContext().getActionFactory(); - } - - public ApplicationActionEngine getActionEngine() { - return getContext().getActionEngine(); - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionEngine.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionEngine.java deleted file mode 100644 index 4ee4e82..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionEngine.java +++ /dev/null @@ -1,126 +0,0 @@ -package org.nuiton.jaxx.application.swing.action; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.jaxx.application.swing.AbstractApplicationUIHandler; - -import javax.swing.AbstractButton; - -/** - * To create and consume {@link AbstractApplicationAction}. - * Created on 11/24/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class ApplicationActionEngine { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(ApplicationActionEngine.class); - - private final ApplicationActionFactory actionFactory; - - public ApplicationActionEngine(ApplicationActionFactory actionFactory) { - this.actionFactory = actionFactory; - } - - public <A extends AbstractApplicationAction> void runInternalAction(A action) { - Throwable error = null; - - try { - action.doAction(); - action.postSuccessAction(); - } catch (Throwable e) { - error = e; - if (log.isErrorEnabled()) { - log.error("Error in action:", e); - } - throw ApplicationActionException.propagateError(action, e); - } finally { - try { - if (error != null) { - action.postFailedAction(error); - } - } finally { - - action.releaseAction(); - } - } - } - - public <A extends AbstractApplicationAction> void runFullInternalAction(A action) { - Throwable error = null; - - try { - boolean doAction = action.prepareAction(); - if (doAction) { - action.doAction(); - action.postSuccessAction(); - } - } catch (Throwable e) { - error = e; - if (log.isErrorEnabled()) { - log.error("Error in action:", e); - } - throw ApplicationActionException.propagateError(action, e); - } finally { - try { - if (error != null) { - action.postFailedAction(error); - } - } finally { - - action.releaseAction(); - } - } - } - - public <A extends AbstractApplicationAction> void runInternalAction(AbstractApplicationUIHandler handler, - Class<A> actionName) { - A action = actionFactory.createLogicAction(handler, actionName); - runInternalAction(action); - } - - public <A extends AbstractApplicationAction> void runAction(A action) { - ApplicationUIAction<A> uiAction = actionFactory.createUIAction(null, action); - uiAction.actionPerformed(null); - } - - public void runAction(AbstractButton button) { - button.getAction().actionPerformed(null); - } - - public <A extends AbstractApplicationAction> void runActionAndWait(A action) { - ApplicationUIAction<A> uiAction = actionFactory.createUIAction(null, action); - uiAction.launchActionAndWait(); - } - - public <A extends AbstractApplicationAction> void runActionAndWait(AbstractApplicationUIHandler handler, - Class<A> actionName) { - A logicAction = actionFactory.createLogicAction(handler, actionName); - runActionAndWait(logicAction); - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionException.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionException.java deleted file mode 100644 index 2cc33a3..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionException.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.nuiton.jaxx.application.swing.action; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -/** - * To box any error of a {@link AbstractApplicationAction}. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class ApplicationActionException extends RuntimeException { - - private static final long serialVersionUID = 1L; - - private final AbstractApplicationAction action; - - public ApplicationActionException(AbstractApplicationAction action, Throwable cause) { - super(cause); - this.action = action; - } - - public static ApplicationActionException propagateError(AbstractApplicationAction action, - Throwable cause) { - ApplicationActionException result; - if (cause instanceof ApplicationActionException) { - result = ((ApplicationActionException) cause); - } else { - result = new ApplicationActionException(action, cause); - } - return result; - } - - public AbstractApplicationAction getAction() { - return action; - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionFactory.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionFactory.java deleted file mode 100644 index 7a53221..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionFactory.java +++ /dev/null @@ -1,94 +0,0 @@ -package org.nuiton.jaxx.application.swing.action; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import com.google.common.base.Preconditions; -import org.apache.commons.lang3.reflect.ConstructorUtils; -import org.nuiton.jaxx.application.ApplicationTechnicalException; -import org.nuiton.jaxx.application.swing.AbstractApplicationUIHandler; - -import javax.swing.AbstractButton; -import javax.swing.Action; - -import static org.nuiton.i18n.I18n.t; - -/** - * Factory of actions. - * - * Created on 11/24/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class ApplicationActionFactory { - - public <A extends AbstractApplicationAction> ApplicationUIAction<A> createUIAction(AbstractApplicationUIHandler handler, - Class<A> actionName) { - return createUIAction(handler, null, actionName); - } - - - public <A extends AbstractApplicationAction> ApplicationUIAction<A> createUIAction(AbstractApplicationUIHandler handler, - AbstractButton abstractButton, - Class<A> actionName) { - try { - - // create logic action - A logicAction = createLogicAction(handler, actionName); - - // create ui action - return createUIAction(abstractButton, logicAction); - } catch (Exception e) { - throw new ApplicationTechnicalException(t("jaxx.application.action.create.error", actionName), e); - } - - } - - public <A extends AbstractApplicationAction> ApplicationUIAction<A> createUIAction(AbstractButton abstractButton, - A logicAction) { - - // create ui action - return new ApplicationUIAction<>(abstractButton, - logicAction); - - - } - - public <A extends AbstractApplicationAction> A createLogicAction(AbstractApplicationUIHandler handler, - Class<A> actionName) { - try { - - // create action - return ConstructorUtils.invokeConstructor(actionName, handler); - } catch (Exception e) { - throw new ApplicationTechnicalException(t("jaxx.application.action.create.error", actionName), e); - } - } - - public <A extends AbstractApplicationAction> A getLogicAction(AbstractButton b) { - Action action = b.getAction(); - Preconditions.checkNotNull(action); - Preconditions.checkState(action instanceof ApplicationUIAction); - return ((ApplicationUIAction<A>) action).getLogicAction(); - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionSwingWorker.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionSwingWorker.java deleted file mode 100644 index 2f556b2..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionSwingWorker.java +++ /dev/null @@ -1,201 +0,0 @@ -package org.nuiton.jaxx.application.swing.action; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.SwingUtilities; -import javax.swing.SwingWorker; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.util.Timer; -import java.util.TimerTask; - -/** - * Worker to execute logic action. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class ApplicationActionSwingWorker<A extends AbstractApplicationAction> extends SwingWorker<Void, String> { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(ApplicationActionSwingWorker.class); - - /** - * Timer used to launch timerTask (to open load dialog). - * - * @since 2.8.2 - */ - private static final Timer t = new Timer(); - - protected final ApplicationActionUI actionUI; - - protected final A action; - - protected Throwable error; - - protected TimerTask timer; - - protected ApplicationActionSwingWorker(A action) { - - this.action = action; - this.actionUI = action.getContext().getActionUI(); - } - - public Throwable getError() { - return error; - } - - public boolean isFailed() { - return error != null; - } - - @Override - protected Void doInBackground() throws Exception { - - if (!isCancelled()) { - - timer = new TuttiActionTimerTask(); - - t.schedule(timer, 1000); - - try { - - action.doAction(); - - } catch (Throwable e) { - if (log.isErrorEnabled()) { - log.error("Task [" + this + "] Error while doAction: ", e); - } - error = e; - } finally { - if (log.isDebugEnabled()) { - log.debug("Task [" + this + "] done"); - } - } - } - return null; - } - - @Override - protected void done() { - super.done(); - - if (log.isDebugEnabled()) { - log.debug("Task [" + this + "] execute done method after all"); - } - - if (error == null) { - - // success hook - action.postSuccessAction(); - } else { - - // fail hook - action.postFailedAction(error); - } - - action.releaseAction(); - - if (timer != null) { - - timer.cancel(); - } - - actionUI.close(); - - updateBusyState(false); - } - - protected void updateBusyState(boolean busy) { - - boolean hideBody = action.isHideBody(); - - action.getContext().setBusy(busy); - - if (hideBody) { - action.getContext().setHideBody(!busy); - } - - } - - protected class TuttiActionTimerTask extends TimerTask { - - public TuttiActionTimerTask() { - action.addPropertyChangeListener(AbstractApplicationAction.PROPERTY_DONE, new PropertyChangeListener() { - - @Override - public void propertyChange(PropertyChangeEvent evt) { - - // prevent memory leak, TuttiActionTimerTask is created each time see https://forge.nuiton.org/issues/3990 - action.removePropertyChangeListener(AbstractApplicationAction.PROPERTY_DONE, this); - - // we do NOT want the timer to wake up then the actionUI dialog - cancel(); - - //if (actionUI.isVisible()) { -//} - SwingUtilities.invokeLater(actionUI::close); - } - }); - } - - @Override - public void run() { - if (isCancelled() || isDone()) { - - if (log.isDebugEnabled()) { - log.debug("Task [" + action + "] was already canceled or done, do nothing"); - } - } else { - - if (log.isDebugEnabled()) { - log.debug("Task [" + action + "] is started, show waiting dialog"); - } - - SwingUtilities.invokeLater(() -> { - - synchronized (actionUI) { - - try { - actionUI.open(action); - } catch (Exception e) { - - // swallow any exception due to ui bad initialisation - // this should not happen, but it does :( - // See https://forge.codelutin.com/issues/7489 - // See http://stackoverflow.com/questions/15545055/nimbus-java-lang-classcastexcept... - // See http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6785663 - if (log.isErrorEnabled()) { - log.error("Something was wrong while opening the action ui, but we do not care", e); - } - } - } - }); - } - } - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionUI.jaxx b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionUI.jaxx deleted file mode 100644 index cf7eee1..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionUI.jaxx +++ /dev/null @@ -1,72 +0,0 @@ -<!-- - #%L - JAXX :: Application Swing - %% - Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - %% - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser 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 Lesser Public License for more details. - - You should have received a copy of the GNU General Lesser Public - License along with this program. If not, see - <http://www.gnu.org/licenses/lgpl-3.0.html>. - #L% - --> -<JDialog width='300' height='200' modal='true' - undecorated='true' - implements='org.nuiton.jaxx.application.swing.ApplicationUI<ApplicationActionUIModel, ApplicationActionUIHandler>'> - <import> - - org.nuiton.jaxx.application.swing.ApplicationUI - org.nuiton.jaxx.application.swing.ApplicationUIContext - org.nuiton.jaxx.application.swing.util.ApplicationUIUtil - - org.nuiton.jaxx.runtime.swing.BlockingLayerUI - - javax.swing.border.EmptyBorder - </import> - - <script><![CDATA[ - - public ApplicationActionUI(JFrame frame, ApplicationUIContext context) { - super(frame, true); - ApplicationUIUtil.setApplicationContext(this, context); - } - - public void open(AbstractApplicationAction action) { - getModel().setAction(action); - } - - public void close() { - getModel().clear(); - } - ]]></script> - - - <BlockingLayerUI id='busyBlockLayerUI'/> - - <ApplicationActionUIModel id='model' - initializer='getContextValue(ApplicationActionUIModel.class)'/> - - <JPanel id='rootPanel' layout='{new BorderLayout()}' - constraints='BorderLayout.CENTER' decorator='boxed'> - <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> - -</JDialog> diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionUI.jcss b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionUI.jcss deleted file mode 100644 index 9601cda..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionUI.jcss +++ /dev/null @@ -1,66 +0,0 @@ -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -#busyBlockLayerUI { - useIcon:false; - blockingColor: {handler.getContext().getColorBlockingLayer()}; - block:{true}; -} - -#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"; -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionUIHandler.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionUIHandler.java deleted file mode 100644 index 3f92f4d..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionUIHandler.java +++ /dev/null @@ -1,274 +0,0 @@ -package org.nuiton.jaxx.application.swing.action; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.nuiton.jaxx.runtime.SwingUtil; -import org.nuiton.jaxx.validator.swing.SwingValidator; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.decorator.Decorator; -import org.nuiton.jaxx.application.swing.AbstractApplicationUIHandler; -import org.nuiton.jaxx.application.type.ApplicationProgressionModel; - -import javax.swing.JComponent; -import java.awt.Component; -import java.awt.Cursor; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; -import java.awt.event.ComponentListener; -import java.beans.PropertyChangeListener; - -import static org.nuiton.i18n.I18n.t; - -/** - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class ApplicationActionUIHandler extends AbstractApplicationUIHandler<ApplicationActionUIModel, ApplicationActionUI> { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(ApplicationActionUIHandler.class); - - protected final PropertyChangeListener progressionListener; - - protected final ComponentListener listener; - - public ApplicationActionUIHandler() { - progressionListener = evt -> { - - String propertyName = evt.getPropertyName(); - if (ApplicationProgressionModel.PROPERTY_MESSAGE.equals(propertyName)) { - - // change message - String newMessage = (String) evt.getNewValue(); - ui.getTaskActionLabel().setText("<html><body>" + newMessage + "</body></html>"); - ui.pack(); - } else if (ApplicationProgressionModel.PROPERTY_TOTAL.equals(propertyName)) { - - // change total progressbar max - ui.getTaskProgressBar().setMaximum((Integer) evt.getNewValue()); - - } else if (ApplicationProgressionModel.PROPERTY_CURRENT.equals(propertyName)) { - - // change value of progress bar - ui.getTaskProgressBar().setValue((Integer) evt.getNewValue()); - } - }; - listener = new ComponentAdapter() { - boolean moving; - - boolean resizing; - - @Override - public void componentMoved(ComponentEvent e) { - - Component mainUI = (Component) e.getSource(); - - if (!moving && mainUI.isShowing()) { - - moving = true; - try { - setLocation(mainUI); - } finally { - moving = false; - } - } - } - - @Override - public void componentResized(ComponentEvent e) { - - Component mainUI = (Component) e.getSource(); - - if (!resizing && mainUI.isShowing()) { - - resizing = true; - try { - setSize(mainUI); - } finally { - resizing = false; - } - } - } - }; - } - - //------------------------------------------------------------------------// - //-- AbstractTuttiUIHandler methods --// - //------------------------------------------------------------------------// - - @Override - public void beforeInit(ApplicationActionUI ui) { - this.ui = ui; - ApplicationActionUIModel model = new ApplicationActionUIModel(); - ui.setContextValue(model); - - model.addPropertyChangeListener(ApplicationActionUIModel.PROPERTY_ACTION, evt -> { - - // udpate global label - AbstractApplicationAction action = (AbstractApplicationAction) evt.getNewValue(); - - if (log.isDebugEnabled()) { - log.debug("Action to use: " + action); - } - if (action == null) { - - // stoping action - hideAction(); - } else { - - // starting action - showAction(action); - } - }); - - model.addPropertyChangeListener(ApplicationActionUIModel.PROPERTY_PROGRESSION_MODEL, evt -> { - - // change progression model - - ApplicationProgressionModel oldValue = (ApplicationProgressionModel) evt.getOldValue(); - ApplicationProgressionModel newValue = (ApplicationProgressionModel) evt.getNewValue(); - - if (log.isDebugEnabled()) { - log.debug("progression model: " + newValue); - } - if (oldValue != null) { - oldValue.removePropertyChangeListener(progressionListener); - } - - if (newValue == null) { - - // remove progression model - ApplicationActionUIHandler.this.ui.getTaskPanel().setVisible(false); - } else { - - // use progression model - ApplicationActionUIHandler.this.ui.getTaskPanel().setVisible(true); - - newValue.addPropertyChangeListener(progressionListener); - } - }); - } - - @Override - public void afterInit(ApplicationActionUI ui) { - - initUI(this.ui); - - // installation layer de blocage en mode busy - SwingUtil.setLayerUI(this.ui.getRootPanel(), this.ui.getBusyBlockLayerUI()); - - this.ui.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - } - - @Override - protected JComponent getComponentToFocus() { - return null; - } - - @Override - public void onCloseUI() { - - } - - @Override - public SwingValidator<ApplicationActionUIModel> getValidator() { - return null; - } - - @Override - public Component getTopestUI() { - return null; - } - - @Override - public <E> Decorator<E> getDecorator(Class<E> beanType, String decoratorContext) { - return null; - } - - //------------------------------------------------------------------------// - //-- Internal methods --// - //------------------------------------------------------------------------// - - protected void hideAction() { - ui.setVisible(false); - } - - protected void showAction(AbstractApplicationAction action) { - ui.setTitle(t("jaxx.application.title.actionUI", - getContext().getConfiguration().getApplicationName(), - getContext().getConfiguration().getVersion(), - action.getActionDescription())); - ui.getGlobalActionLabel().setText( - t("jaxx.application.message.action.running", - action.getActionDescription())); - ui.pack(); - - Component mainUI = getContext().getMainUI(); - if (mainUI != null) { - mainUI.addComponentListener(listener); - - setLocation(mainUI); - setSize(mainUI); - } - try { - ui.setVisible(true); - } finally { - if (mainUI != null) { - mainUI.removeComponentListener(listener); - } - } - } - - protected void setLocation(Component mainUI) { - Component component = getContext().getBodyUI(); - Component status = getContext().getStatusUI(); - int width = component == null ? 0 : component.getWidth(); - int height = component == null ? 0 : component.getHeight() + status.getHeight(); - - int x; - int y; - if (height == 0) { - x = mainUI.getX() + 5; - y = mainUI.getY() + 15; - } else { - x = mainUI.getX() + (mainUI.getWidth() - width); - y = mainUI.getY() + (mainUI.getHeight() - height); - } - ui.setLocation(x, y); - } - - protected void setSize(Component mainUI) { - // Better to let his own size to the action progress bar - // see http://forge.codelutin.com/issues/3263 -// Container component = mainUI.getBody(); -// int width = component == null ? 0 : component.getWidth(); - - ui.pack(); - -// if (width != 0 && ui.getWidth() < width) { -// ui.setSize(width, ui.getHeight()); -// } - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionUIModel.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionUIModel.java deleted file mode 100644 index 833e37e..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationActionUIModel.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.nuiton.jaxx.application.swing.action; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import com.google.common.base.Preconditions; -import org.jdesktop.beans.AbstractSerializableBean; -import org.nuiton.jaxx.application.type.ApplicationProgressionModel; - -/** - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class ApplicationActionUIModel extends AbstractSerializableBean { - - private static final long serialVersionUID = 1L; - - public static final String PROPERTY_ACTION = "action"; - - public static final String PROPERTY_PROGRESSION_MODEL = "progressionModel"; - - protected AbstractApplicationAction action; - - protected ApplicationProgressionModel progressionModel; - - public ApplicationProgressionModel getProgressionModel() { - return progressionModel; - } - - public void setProgressionModel(ApplicationProgressionModel progressionModel) { - Object oldValue = getProgressionModel(); - this.progressionModel = progressionModel; - firePropertyChange(PROPERTY_PROGRESSION_MODEL, oldValue, progressionModel); - } - - public AbstractApplicationAction getAction() { - return action; - } - - public void setAction(AbstractApplicationAction action) { - Preconditions.checkNotNull(action, "action can not be null"); - Object oldValue = getAction(); - this.action = action; - firePropertyChange(PROPERTY_ACTION, oldValue, action); - } - - public void clear() { - setProgressionModel(null); - - Object oldValue = getAction(); - action = null; - firePropertyChange(PROPERTY_ACTION, oldValue, null); - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationUIAction.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationUIAction.java deleted file mode 100644 index 50fd56c..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/action/ApplicationUIAction.java +++ /dev/null @@ -1,235 +0,0 @@ -package org.nuiton.jaxx.application.swing.action; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.jaxx.application.swing.ApplicationUIContext; -import org.nuiton.util.TimeLog; - -import javax.swing.AbstractAction; -import javax.swing.AbstractButton; -import javax.swing.Icon; -import javax.swing.SwingUtilities; -import java.awt.event.ActionEvent; -import java.util.concurrent.CancellationException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -/** - * Abstract tutti ui action which launch a {@link AbstractApplicationAction}. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8.2 - */ -public class ApplicationUIAction<A extends AbstractApplicationAction> extends AbstractAction { - - private static final long serialVersionUID = 1L; - - /** Logger. */ - private static final Log log = LogFactory.getLog(ApplicationUIAction.class); - - private static final TimeLog TIME_LOG = new TimeLog(ApplicationUIAction.class); - - public static final ExecutorService waitingThread = - Executors.newSingleThreadExecutor(); - - private static final String LOGIC_ACTION = "logicAction"; - - private final Object lock = new Object(); - - private boolean wait; - - private long t0; - - public ApplicationUIAction(final AbstractButton button, A action) { - - putValue(LOGIC_ACTION, action); - - // fill the ui action from the button - setActionKey(action.getClass().getName()); - if (button != null) { - - setActionIcon(button.getIcon()); - setActionName(button.getText()); - setActionDescription(button.getToolTipText()); - setActionMnemonic(button.getMnemonic()); - setEnabled(button.isEnabled()); - - // see https://forge.nuiton.org/issues/3525 - button.addPropertyChangeListener(evt -> setEnabled(button.isEnabled())); - - } - } - - public void launchActionAndWait() { - wait = true; - actionPerformed(null); - lock(); - } - - - @Override - public final void actionPerformed(final ActionEvent event) { - - t0 = TimeLog.getTime(); - - if (log.isInfoEnabled()) { - log.info("Task [" + getLogicAction().getClass().getSimpleName() + "] starting"); - } - - // prepare action - boolean doAction; - - A action = getLogicAction(); - - ApplicationUIContext actionContext = action.getContext(); - if (actionContext.isActionInProgress(this)) { - if (log.isInfoEnabled()) { - log.info("Task [" + getLogicAction().getClass().getSimpleName() + "] stopped: action already in progress"); - } - return; - } - - actionContext.setActionInProgress(this, true); - - // reset status message - action.sendMessage(""); - - try { - doAction = action.prepareAction(); - } catch (Exception e) { - action.releaseAction(); - actionContext.setActionInProgress(this, false); - throw ApplicationActionException.propagateError(action, e); - } - - if (doAction) { - - final ApplicationActionSwingWorker<A> worker = - new ApplicationActionSwingWorker<>(action); - - SwingUtilities.invokeLater(() -> { - - // make ui busy - worker.updateBusyState(true); - - }); - - if (log.isDebugEnabled()) { - log.debug("Before execute of action " + action); - } - - // perform and release action - worker.execute(); - - // wait until action is done - waitingThread.execute( - () -> { - - A action1 = getLogicAction(); - try { - try { - worker.get(); - } catch (ExecutionException | InterruptedException | CancellationException e) { - // don't care . - } - if (log.isDebugEnabled()) { - log.debug("After execute of action " + action1 + " (worker done? " + worker.isDone() + ")"); - } - - if (worker.isFailed()) { - - throw ApplicationActionException.propagateError(action1, worker.getError()); - } - } finally { - unlock(); - } - } - ); - - } else { - - try { - // release action - action.releaseAction(); - - } finally { - unlock(); - } - } - } - - public void setActionIcon(Icon actionIcon) { - putValue(SMALL_ICON, actionIcon); - putValue(LARGE_ICON_KEY, actionIcon); - } - - public void setActionKey(String actionKey) { - putValue(ACTION_COMMAND_KEY, actionKey); - } - - public void setActionName(String actionName) { - putValue(NAME, actionName); - } - - public void setActionDescription(String actionDescription) { - putValue(SHORT_DESCRIPTION, actionDescription); - getLogicAction().setActionDescription(actionDescription); - } - - public void setActionMnemonic(int key) { - putValue(MNEMONIC_KEY, key); - } - - public A getLogicAction() { - return (A) getValue(LOGIC_ACTION); - } - - protected void lock() { - if (wait) { - synchronized (lock) { - try { - - lock.wait(); - - } catch (InterruptedException e) { - throw ApplicationActionException.propagateError(getLogicAction(), e); - } finally { - wait = false; - } - } - } - } - - protected void unlock() { - TIME_LOG.log(t0, "Task [" + getLogicAction().getClass().getSimpleName() + "] End"); - if (wait) { - synchronized (lock) { - lock.notifyAll(); - } - } - getLogicAction().getContext().setActionInProgress(this, false); - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/actionng/ApplicationAction.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/actionng/ApplicationAction.java deleted file mode 100644 index 5f17aab..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/actionng/ApplicationAction.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.nuiton.jaxx.application.swing.actionng; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -/** - * Contract of an application action. - * - * Created on 11/23/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public interface ApplicationAction { - - /** - * Before executing the action. - * - * <strong>This code is executed in the Swing thread</strong> - * - * @return {@code true} if action can be execute, {@code false} otherwise. - */ - boolean prepare(); - - /** - * Real action code. - * - * <strong>This code is not executed, you can't then touch to any models or components of UI.</strong> - */ - void action(); - - /** - * Executed when action ended with success. - * - * <strong>This code is executed in the Swing thread, you can here update</strong> - * - */ - void done(); - - /** - * Executed when action failed. - * - * @param error failure exception - */ - void fail(Exception error); -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/actionng/ApplicationActionEngine.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/actionng/ApplicationActionEngine.java deleted file mode 100644 index 7e73cf0..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/actionng/ApplicationActionEngine.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.nuiton.jaxx.application.swing.actionng; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import javax.swing.event.EventListenerList; - -/** - * Engine what consumes incoming actions. - * - * Created on 11/23/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class ApplicationActionEngine { - - private final EventListenerList eventList; - - public ApplicationActionEngine() { - eventList = new EventListenerList(); - } - - public void addAction(ApplicationAction action) { - - } - - //------------------------------------------------------------------------// - //--- ApplicationActionListener API ---// - //------------------------------------------------------------------------// - - public void addApplicationEventListener(ApplicationActionListener listener) { - eventList.add(ApplicationActionListener.class, listener); - } - - public void removeApplicationEventListener(ApplicationActionListener listener) { - eventList.remove(ApplicationActionListener.class, listener); - } - - protected void fireInit(ApplicationAction action) { - ApplicationActionEvent event = new ApplicationActionEvent(action, ApplicationActionEvent.EventType.INIT); - - ApplicationActionListener[] listeners = eventList.getListeners(ApplicationActionListener.class); - for (ApplicationActionListener listener : listeners) { - listener.actionStarted(event); - } - } - - protected void fireStart(ApplicationAction action) { - ApplicationActionEvent event = new ApplicationActionEvent(action, ApplicationActionEvent.EventType.START); - - ApplicationActionListener[] listeners = eventList.getListeners(ApplicationActionListener.class); - for (ApplicationActionListener listener : listeners) { - listener.actionStarted(event); - } - } - - protected void fireDone(ApplicationAction action) { - ApplicationActionEvent event = new ApplicationActionEvent(action, ApplicationActionEvent.EventType.DONE); - ApplicationActionListener[] listeners = eventList.getListeners(ApplicationActionListener.class); - for (ApplicationActionListener listener : listeners) { - listener.actionDone(event); - } - } - - protected void fireFail(ApplicationAction action, Exception error) { - ApplicationActionEvent event = new ApplicationActionEvent(action, ApplicationActionEvent.EventType.FAIL); - event.setError(error); - ApplicationActionListener[] listeners = eventList.getListeners(ApplicationActionListener.class); - for (ApplicationActionListener listener : listeners) { - listener.actionFailed(event); - } - } - - protected void fireProgressionChange(ApplicationAction action) { - ApplicationActionEvent event = new ApplicationActionEvent(action, ApplicationActionEvent.EventType.PROGRESSION_CHANGE); - ApplicationActionListener[] listeners = eventList.getListeners(ApplicationActionListener.class); - for (ApplicationActionListener listener : listeners) { - listener.actionProgressionChanged(event); - } - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/actionng/ApplicationActionEvent.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/actionng/ApplicationActionEvent.java deleted file mode 100644 index d481d75..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/actionng/ApplicationActionEvent.java +++ /dev/null @@ -1,95 +0,0 @@ -package org.nuiton.jaxx.application.swing.actionng; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import java.util.EventObject; - -/** - * Events... - * - * Created on 11/23/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class ApplicationActionEvent extends EventObject { - - private static final long serialVersionUID = 1L; - - public enum EventType { - /** - * Before starting action. - */ - INIT, - /** - * When action is started. - */ - START, - /** - * When action end with succes. - */ - DONE, - /** - * When action failed. - */ - FAIL, - /** - * When progression changed. - */ - PROGRESSION_CHANGE - } - - private Exception error; - - private final EventType eventType; - - /** - * Constructs a prototypical Event. - * - * @param source The object on which the Event initially occurred. - * @param eventType The type of event - * @throws IllegalArgumentException if source is null. - */ - public ApplicationActionEvent(ApplicationAction source, - EventType eventType) { - super(source); - this.eventType = eventType; - } - - @Override - public ApplicationAction getSource() { - return (ApplicationAction) super.getSource(); - } - - public Exception getError() { - return error; - } - - public void setError(Exception error) { - this.error = error; - } - - public EventType getEventType() { - return eventType; - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/actionng/ApplicationActionListener.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/actionng/ApplicationActionListener.java deleted file mode 100644 index f461d29..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/actionng/ApplicationActionListener.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.nuiton.jaxx.application.swing.actionng; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import java.util.EventListener; - -/** - * To listen {@link ApplicationActionEngine} events. - * - * Created on 11/23/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public interface ApplicationActionListener extends EventListener { - - void actionInit(ApplicationActionEvent event); - - void actionStarted(ApplicationActionEvent event); - - void actionProgressionChanged(ApplicationActionEvent event); - - void actionDone(ApplicationActionEvent event); - - void actionFailed(ApplicationActionEvent event); - -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/tab/CustomTab.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/tab/CustomTab.java deleted file mode 100644 index ccb27c7..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/tab/CustomTab.java +++ /dev/null @@ -1,220 +0,0 @@ -package org.nuiton.jaxx.application.swing.tab; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.nuiton.jaxx.runtime.SwingUtil; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.util.beans.BeanUtil; - -import javax.swing.AbstractButton; -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTabbedPane; -import javax.swing.UIManager; -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.Font; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; - -import static org.nuiton.i18n.I18n.t; - -/** - * Custom tab component which adds a * in the end of the title - * when the content is modified. - * - * @author Kevin Morin - morin@codelutin.com - * @since 2.8 - */ -public class CustomTab extends JPanel { - - private static final long serialVersionUID = 1L; - - private static final Log log = LogFactory.getLog(CustomTab.class); - - protected final TabContentModel model; - - protected final TabContainerHandler handler; - - protected final JLabel title = new JLabel(); - - public TabContentModel getModel() { - return model; - } - - public CustomTab(TabContentModel model, TabContainerHandler handler) { - super(new FlowLayout(FlowLayout.LEFT, 0, 0)); - - this.model = model; - this.handler = handler; - - try { - BeanUtil.addPropertyChangeListener( - evt -> updateTitle(), this.model); - - } catch (Exception ex) { - log.error("Error while adding the listener to the model modifications", ex); - } - - setBackground(null); - - updateTitle(); - String actionIcon = model.getIcon(); - if (actionIcon != null) { - title.setIcon(SwingUtil.createActionIcon(actionIcon)); - } - title.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); - add(title); - - if (model.isCloseable()) { - JButton button = new TabButton(); - add(button); - } - - setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0)); - } - - @Override - public void setBackground(Color bg) { - if (bg == null) { - bg = new Color(0, 0, 0, 0); - } - super.setBackground(bg); - revalidate(); - } - - @Override - public void setForeground(Color fg) { - super.setForeground(fg); - if (title != null) { - title.setForeground(fg); - } - } - - protected void updateTitle() { - Font f = UIManager.getDefaults().getFont("Label.font"); - String titleValue = t(model.getTitle()); - - int style; - if (model.isModify()) { - style = Font.BOLD; - titleValue += "*"; - - } else if (model.isEmpty()) { - style = Font.ITALIC; - - } else { - style = Font.PLAIN; - } - - title.setText(titleValue); - title.setFont(f.deriveFont(style)); - } - - protected class TabButton extends JButton implements ActionListener { - - public TabButton() { - int size = 17; - setPreferredSize(new Dimension(size, size)); - setToolTipText(t("jaxx.application.tab.customtab.close.label")); - //Make it transparent - setContentAreaFilled(false); - //No need to be focusable - setFocusable(false); - setBorder(BorderFactory.createEtchedBorder()); - setBorderPainted(false); - //Making nice rollover effect - //we use the same listener for all buttons - addMouseListener(buttonMouseListener); - setRolloverEnabled(true); - //Close the proper tab by clicking the button - addActionListener(this); - } - - @Override - public void actionPerformed(ActionEvent e) { -// if (tabbedPane != null) { -// if (i != -1) { -// tabbedPane.remove(i); -// } -// } - if (handler != null) { - JTabbedPane tabPanel = handler.getTabPanel(); - int i = tabPanel.indexOfTabComponent(CustomTab.this); - handler.removeTab(i); - } - } - - //paint the cross - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - - Graphics2D g2 = (Graphics2D) g.create(); - //shift the image for pressed buttons - if (getModel().isPressed()) { - g2.translate(1, 1); - } - g2.setStroke(new BasicStroke(2)); - if (getModel().isRollover()) { -// g2.setBackground(Color.MAGENTA); - g2.setColor(Color.MAGENTA); - } else { - g2.setColor(Color.BLACK); - } - int delta = 5; - g2.drawLine(delta, delta, getWidth() - delta - 1, getHeight() - delta - 1); - g2.drawLine(getWidth() - delta - 1, delta, delta, getHeight() - delta - 1); - g2.dispose(); - } - } - - private final MouseListener buttonMouseListener = new MouseAdapter() { - public void mouseEntered(MouseEvent e) { - Component component = e.getComponent(); - if (component instanceof AbstractButton) { - AbstractButton button = (AbstractButton) component; - button.setBorderPainted(true); - } - } - - public void mouseExited(MouseEvent e) { - Component component = e.getComponent(); - if (component instanceof AbstractButton) { - AbstractButton button = (AbstractButton) component; - button.setBorderPainted(false); - } - } - }; -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/tab/DelegateTabContainerHandler.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/tab/DelegateTabContainerHandler.java deleted file mode 100644 index 72e6ac5..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/tab/DelegateTabContainerHandler.java +++ /dev/null @@ -1,120 +0,0 @@ -package org.nuiton.jaxx.application.swing.tab; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.nuiton.jaxx.application.swing.AbstractApplicationUIHandler; -import org.nuiton.jaxx.application.swing.ApplicationUI; - -import javax.swing.DefaultSingleSelectionModel; -import javax.swing.JTabbedPane; -import java.awt.Component; - -/** - * Created on 11/25/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class DelegateTabContainerHandler implements TabContainerHandler { - - final JTabbedPane tabbedPane; - - public DelegateTabContainerHandler(JTabbedPane tabbedPane) { - this.tabbedPane = tabbedPane; - } - - @Override - public JTabbedPane getTabPanel() { - return tabbedPane; - } - - @Override - public void init() { - - getTabPanel().setModel(new DefaultSingleSelectionModel() { - - private static final long serialVersionUID = 1L; - - @Override - public void setSelectedIndex(int index) { - int currentIndex = getTabPanel().getSelectedIndex(); - boolean mustChangeTab = onTabChanged(currentIndex, index); - - if (mustChangeTab) { - super.setSelectedIndex(index); - } - } - - }); - } - - @Override - public boolean onTabChanged(int currentIndex, int newIndex) { - boolean result = true; - if (currentIndex != newIndex) { - TabHandler handler = getTabHandler(currentIndex); - if (handler != null) { - result = handler.onHideTab(currentIndex, newIndex); - } - - handler = getTabHandler(newIndex); - if (handler != null) { - handler.onShowTab(currentIndex, newIndex); - } - } - return result; - } - - @Override - public TabHandler getTabHandler(int index) { - TabHandler tabHandler = null; - JTabbedPane tabPanel = getTabPanel(); - if (index >= 0 && index < tabPanel.getTabCount()) { - Component tab = tabPanel.getComponentAt(index); - if (ApplicationUI.class.isInstance(tab)) { - ApplicationUI tuttiTab = (ApplicationUI) tabPanel.getComponentAt(index); - AbstractApplicationUIHandler handler = tuttiTab.getHandler(); - if (TabHandler.class.isInstance(handler)) { - tabHandler = (TabHandler) handler; - } - } - } - return tabHandler; - } - - @Override - public void setCustomTab(int index, TabContentModel model) { - JTabbedPane tabPanel = getTabPanel(); - tabPanel.setTabComponentAt(index, new CustomTab(model, this)); - } - - @Override - public boolean removeTab(int i) { - TabHandler tabHandler = getTabHandler(i); - boolean remove = tabHandler.onRemoveTab(); - if (remove) { - getTabPanel().removeTabAt(i); - } - return remove; - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/tab/TabContainerHandler.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/tab/TabContainerHandler.java deleted file mode 100644 index 9e817a0..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/tab/TabContainerHandler.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.nuiton.jaxx.application.swing.tab; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import javax.swing.JTabbedPane; - -/** - * Created on 11/25/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public interface TabContainerHandler { - - JTabbedPane getTabPanel(); - - void init(); - - /** - * Method called when the user selects a tab. - * - * @param currentIndex - * @param newIndex - * @return <code>false</code> if you want to prevent the tab change, - * <code>true</code> otherwise - */ - boolean onTabChanged(int currentIndex, int newIndex); - - /** - * Returns the tab handler of the tab i. - * - * @param index the index of the tab - * @return the tab handler of the index i if the handler implements - * the {@link TabHandler} interface, - * <code>null</code> otherwise - */ - TabHandler getTabHandler(int index); - - /** - * Sets a {@link CustomTab} as tab component. - * - * @param index - * @param model - */ - void setCustomTab(int index, TabContentModel model); - - /** - * Removes the tab i - * - * @param i the index of the tab to remove - * @return <code>false</code> if you want to prevent the tab close, - * <code>true</code> otherwise - */ - boolean removeTab(int i); - -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/tab/TabContentModel.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/tab/TabContentModel.java deleted file mode 100644 index 7a06746..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/tab/TabContentModel.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.nuiton.jaxx.application.swing.tab; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -/** - * Interface defining the models of the tab content UIs. - * - * @author Kevin Morin - morin@codelutin.com - * @since 2.8 - */ -public interface TabContentModel { - - boolean isEmpty(); - - boolean isValid(); - - boolean isModify(); - - String getTitle(); - - String getIcon(); - - boolean isCloseable(); -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/tab/TabHandler.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/tab/TabHandler.java deleted file mode 100644 index df35072..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/tab/TabHandler.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.nuiton.jaxx.application.swing.tab; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -/** - * Interface describing UI contained in a tab. - * - * @author Kevin Morin - morin@codelutin.com - * @since 2.8 - */ -public interface TabHandler { - - /** - * Method called when the tab is hidden - * - * @param currentIndex - * @param newIndex - * @return <code>false</code> to prevent the tab to be hidden, - * <code>true</code> otherwise. - */ - boolean onHideTab(int currentIndex, int newIndex); - - /** - * Method called when the tab is shown - * - * @param currentIndex - * @param newIndex - */ - void onShowTab(int currentIndex, int newIndex); - - /** - * Method called when the tab is removed - * - * @return <code>false</code> to prevent the tab to be closed, - * <code>true</code> otherwise. - */ - boolean onRemoveTab(); -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/AbstractApplicationTableModel.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/AbstractApplicationTableModel.java deleted file mode 100644 index 0f9449f..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/AbstractApplicationTableModel.java +++ /dev/null @@ -1,371 +0,0 @@ -package org.nuiton.jaxx.application.swing.table; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import com.google.common.base.Preconditions; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import org.nuiton.jaxx.runtime.SwingUtil; -import org.apache.commons.lang3.ObjectUtils; -import org.apache.commons.lang3.tuple.Pair; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jdesktop.swingx.table.TableColumnModelExt; - -import javax.swing.table.AbstractTableModel; -import javax.swing.table.TableColumn; -import java.io.Serializable; -import java.util.List; -import java.util.Set; - -/** - * Abstract model of a table. - * - * @param <R> type of a row. - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public abstract class AbstractApplicationTableModel<R extends Serializable> extends AbstractTableModel { - - private static final long serialVersionUID = 1L; - - /** Logger. */ - private static final Log log = - LogFactory.getLog(AbstractApplicationTableModel.class); - - /** - * Data in the model. - * - * @since 0.2 - */ - protected List<R> rows; - - /** - * Set of non editable columns. - * - * @since 0.2 - */ - protected Set<ColumnIdentifier<?>> noneEditableCols; - - /** - * Creates a new row when moving to next editable cell / row ? - * - * @since 0.3 - */ - protected final boolean createNewRow; - - /** - * Creates a first empty row when setting a null or empty list of rows ? - * - * @since 0.3 - */ - protected final boolean createEmptyRowIsEmpty; - - /** - * Identifiers of columns (in initial order). - * - * @since 1.1 - */ - protected final List<ColumnIdentifier<R>> identifiers; - - public abstract R createNewRow(); - - protected AbstractApplicationTableModel(TableColumnModelExt columnModel, - boolean createNewRow, - boolean createEmptyRowIsEmpty) { - this.identifiers = Lists.newArrayListWithCapacity(columnModel.getColumnCount()); - for (TableColumn tc : columnModel.getColumns(true)) { - this.identifiers.add((ColumnIdentifier<R>) tc.getIdentifier()); - } - this.createNewRow = createNewRow; - this.createEmptyRowIsEmpty = createEmptyRowIsEmpty; - } - - public final List<R> getRows() { - return rows; - } - - public final void setRows(List<R> data) { - - // can't accept a empty data list - Preconditions.checkNotNull(data, "Data list can not be null."); - - onBeforeRowsChanged(rows); - - this.rows = null; - if (createEmptyRowIsEmpty && data.isEmpty()) { - - if (log.isDebugEnabled()) { - log.debug("Creates a first empty row on tableModel " + this); - } - // add a first edit line - data.add(createNewRow()); - } - if (log.isDebugEnabled()) { - log.debug("Set " + data.size() + " row(s) in table model " + this); - } - this.rows = data; - onRowsChanged(data); - fireTableDataChanged(); - } - - public boolean isCreateNewRow() { - return createNewRow; - } - - public boolean isCreateEmptyRowIsEmpty() { - return createEmptyRowIsEmpty; - } - - public final void addNewRow() { - R newValue = createNewRow(); - addNewRow(newValue); - } - - public final void addNewRow(R newValue) { - - addNewRow(getRowCount(), newValue); - } - - public final void addNewRow(int rowIndex, R newValue) { - - Preconditions.checkNotNull(newValue, "Row can not be null."); - - List<R> data = getRows(); - Preconditions.checkNotNull(data, "Data list can not be null."); - - data.add(rowIndex, newValue); - - onRowAdded(rowIndex, newValue); - fireTableRowsInserted(rowIndex, rowIndex); - } - - public final void fireTableRowsInserted(R newValue) { - - Preconditions.checkNotNull(newValue, "Row can not be null."); - - int rowIndex = getRowIndex(newValue); - fireTableRowsInserted(rowIndex, rowIndex); - } - - public final int updateRow(R row) { - Preconditions.checkNotNull(row, "Row can not be null."); - - List<R> data = getRows(); - Preconditions.checkNotNull(data, "Data list can not be null."); - - int rowIndex = data.indexOf(row); - - onRowUpdated(rowIndex, row); - fireTableRowsUpdated(rowIndex, rowIndex); - return rowIndex; - } - - public final R removeRow(int rowIndex) { - SwingUtil.ensureRowIndex(this, rowIndex); - - List<R> data = getRows(); - - R row = data.remove(rowIndex); - - onRowRemoved(rowIndex, row); - fireTableRowsDeleted(rowIndex, rowIndex); - return row; - } - - protected void onRowsChanged(List<R> newRows) { - // by default do nothing - } - - protected void onBeforeRowsChanged(List<R> oldRows) { - // by default do nothing - } - - protected void onRowAdded(int rowIndex, R row) { - // by default do nothing - } - - protected void onRowUpdated(int rowIndex, R row) { - // by default do nothing - } - - protected void onRowRemoved(int rowIndex, R row) { - // by default do nothing - } - - public final int getRowIndex(R row) { - return rows == null ? -1 : rows.indexOf(row); - } - - public final R getEntry(int rowIndex) { - SwingUtil.ensureRowIndex(this, rowIndex); - List<R> data = getRows(); - return data == null ? null : data.get(rowIndex); - } - - public final void setNoneEditableCols(ColumnIdentifier<?>... noneEditableCols) { - this.noneEditableCols = Sets.newHashSet(noneEditableCols); - } - - @Override - public final int getRowCount() { - return rows == null ? 0 : rows.size(); - } - - @Override - public final int getColumnCount() { - return identifiers.size(); - } - - @Override - public final Object getValueAt(int rowIndex, int columnIndex) { - R entry = getEntry(rowIndex); - ColumnIdentifier<R> identifier = getIdentifier(columnIndex); - if (log.isDebugEnabled()) { - log.debug("columnIndex: " + columnIndex + " :: " + identifier.getPropertyName()); - } - return identifier.getValue(entry); - } - - @Override - public final void setValueAt(Object aValue, int rowIndex, int columnIndex) { - if (log.isDebugEnabled()) { - log.debug("setValueAt " + aValue); - } - R entry = getEntry(rowIndex); - ColumnIdentifier<R> identifier = getIdentifier(columnIndex); - setValueAt(aValue, rowIndex, columnIndex, identifier, entry); - } - - @Override - public final boolean isCellEditable(int rowIndex, int columnIndex) { - ColumnIdentifier<R> identifier = getIdentifier(columnIndex); - return isCellEditable(rowIndex, columnIndex, identifier); - } - - protected void setValueAt(Object aValue, - int rowIndex, - int columnIndex, - ColumnIdentifier<R> propertyName, - R entry) { - if (log.isDebugEnabled()) { - log.debug("setValueAt " + aValue); - } - propertyName.setValue(entry, aValue); - } - - protected boolean isCellEditable(int rowIndex, - int columnIndex, - ColumnIdentifier<R> propertyName) { - return !noneEditableCols.contains(propertyName); - } - - public final void fireTableCellUpdated(int rowIndex, - ColumnIdentifier<R>... identifiers) { - for (ColumnIdentifier<R> identifier : identifiers) { - int columnIndex = this.identifiers.indexOf(identifier); - fireTableCellUpdated(rowIndex, columnIndex); - } - } - - public final void fireTableRowUpdatedShell(Set<R> shell) { - - int minRowIndex1 = getColumnCount(); - int maxRowIndex1 = 0; - - for (R r : shell) { - int rowIndex1 = getRowIndex(r); - minRowIndex1 = Math.min(minRowIndex1, rowIndex1); - maxRowIndex1 = Math.max(maxRowIndex1, rowIndex1); - } - fireTableRowsUpdated(minRowIndex1, maxRowIndex1); - } - - protected void collectShell(R row, Set<R> collectedRows) { - - // by default just add the incoming row - collectedRows.add(row); - } - - @Override - public String getColumnName(int columnIndex) { - return getIdentifier(columnIndex).getPropertyName(); - } - - protected ColumnIdentifier<R> getIdentifier(int columnIndex) { - return identifiers.get(columnIndex); - } - - public int getColumnIndex(final String propertyName) { - return Iterables.indexOf(identifiers, input -> ObjectUtils.equals(propertyName, input.getPropertyName())); - } - - public Pair<Integer, Integer> getCell(R row, final String propertyName) { - - int rowIndex = getRowIndex(row); - int columnIndex = getColumnIndex(propertyName); - - return Pair.of(rowIndex, columnIndex); - } - - public void moveUp(R row) { - - int rowIndex = getRowIndex(row); - - if (log.isInfoEnabled()) { - log.info("Will move up row of index: " + rowIndex); - } - rows.remove(rowIndex); - rows.add(rowIndex - 1, row); - fireTableRowsUpdated(rowIndex - 1, rowIndex); - - } - - public void moveDown(R row) { - - int rowIndex = getRowIndex(row); - - if (log.isInfoEnabled()) { - log.info("Will move down row of index: " + rowIndex); - } - rows.remove(rowIndex); - rows.add(rowIndex + 1, row); - fireTableRowsUpdated(rowIndex, rowIndex + 1); - - } - - public boolean isFirstRow(R row) { - - int rowIndex = getRowIndex(row); - return rowIndex == 0; - - } - - public boolean isLastRow(R row) { - - int rowIndex = getRowIndex(row); - return rowIndex == getRowCount() - 1; - - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/AbstractSelectTableAction.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/AbstractSelectTableAction.java deleted file mode 100644 index c5ef9e7..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/AbstractSelectTableAction.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.nuiton.jaxx.application.swing.table; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.jaxx.application.swing.util.ApplicationUIUtil; - -import javax.swing.AbstractAction; -import javax.swing.JTable; - -/** - * Abstract action to select a cell in a table. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public abstract class AbstractSelectTableAction<M extends AbstractApplicationTableModel> extends AbstractAction { - - private static final long serialVersionUID = 1L; - - /** Logger. */ - private static final Log log = - LogFactory.getLog(AbstractSelectTableAction.class); - - private final M model; - - private final JTable table; - - public AbstractSelectTableAction(M model, JTable table) { - this.model = model; - this.table = table; - } - - protected void doSelectCell(int rowIndex, int columnIndex) { - - if (log.isDebugEnabled()) { - log.debug("Will select cell at " + - getCellCoordinate(rowIndex, columnIndex)); - } - ApplicationUIUtil.doSelectCell(table, rowIndex, columnIndex); - } - - protected int getSelectedRow() { - return table.getSelectedRow(); - } - - protected int getSelectedColumn() { - return table.getSelectedColumn(); - } - - protected int getRowCount() { - return table.getRowCount(); - } - - protected int getColumnCount() { - return table.getColumnCount(); - } - - protected boolean isCellEditable(int rowIndex, int columnIndex) { - boolean result; - result = rowIndex > -1 && columnIndex > -1 && - table.isCellEditable(rowIndex, columnIndex); - return result; - } - - protected boolean isCreateNewRow() { - return model.isCreateNewRow(); - } - - protected String getCellCoordinate(int rowIndex, int columnIndex) { - return " [" + rowIndex + ", " + columnIndex + "]"; - } - - protected void addNewRow() { - model.addNewRow(); - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/ApplicationTableModelValidatorDataLocator.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/ApplicationTableModelValidatorDataLocator.java deleted file mode 100644 index 9a4ba5f..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/ApplicationTableModelValidatorDataLocator.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.nuiton.jaxx.application.swing.table; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.nuiton.jaxx.validator.swing.SwingListValidatorDataLocator; -import org.apache.commons.lang3.tuple.Pair; - -import javax.swing.table.TableModel; -import java.io.Serializable; - -/** - * To locate data in a {@link AbstractApplicationTableModel}. - * - * Created on 8/14/14. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.10 - */ -public class ApplicationTableModelValidatorDataLocator<R extends Serializable, T extends AbstractApplicationTableModel<R>> implements SwingListValidatorDataLocator<R> { - - public static <R extends Serializable, T extends AbstractApplicationTableModel<R>> ApplicationTableModelValidatorDataLocator<R, T> newLocator(Class<R> rowType) { - return new ApplicationTableModelValidatorDataLocator<>(rowType); - } - - private final Class<R> rowType; - - public ApplicationTableModelValidatorDataLocator(Class<R> rowType) { - this.rowType = rowType; - } - - @Override - public boolean acceptType(Class<?> beanType) { - return rowType.isAssignableFrom(beanType); - } - - @Override - public Pair<Integer, Integer> locateDataCell(TableModel tableModel, - R bean, - String fieldName) { - T model = (T) tableModel; - - return model.getCell(bean, fieldName); - } - - @Override - public int locateBeanRowIndex(TableModel tableModel, R bean) { - T model = (T) tableModel; - return model.getRowIndex(bean); - } - - @Override - public R locateBean(TableModel tableModel, int rowIndex) { - T model = (T) tableModel; - return model.getEntry(rowIndex); - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/ColumnIdentifier.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/ColumnIdentifier.java deleted file mode 100644 index 2205ea9..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/ColumnIdentifier.java +++ /dev/null @@ -1,103 +0,0 @@ -package org.nuiton.jaxx.application.swing.table; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.nuiton.jaxx.application.bean.JavaBeanObjectUtil; - -import java.io.Serializable; - -/** - * To represent a column of a table. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class ColumnIdentifier<R> implements Serializable { - - private static final long serialVersionUID = 1L; - - private final String propertyName; - - private final String headerI18nKey; - - private final String headerTipI18nKey; - - public static <R> ColumnIdentifier<R> newId(String propertyName, - String headerI18nKey, - String headerTipI18nKey) { - return new ColumnIdentifier<>(propertyName, - headerI18nKey, - headerTipI18nKey); - } - - public static <R> ColumnIdentifier<R> newReadOnlyId(String propertyName, - String headerI18nKey, - String headerTipI18nKey) { - return new ColumnIdentifier<R>(propertyName, - headerI18nKey, - headerTipI18nKey) { - - private static final long serialVersionUID = 1L; - - @Override - public void setValue(R entry, Object value) { - // no set - } - }; - } - - protected ColumnIdentifier(String propertyName, - String headerI18nKey, - String headerTipI18nKey) { - this.propertyName = propertyName; - this.headerI18nKey = headerI18nKey; - this.headerTipI18nKey = headerTipI18nKey; - } - - public String getPropertyName() { - return propertyName; - } - - public String getHeaderI18nKey() { - return headerI18nKey; - } - - public String getHeaderTipI18nKey() { - return headerTipI18nKey; - } - - public Object getValue(R entry) { - Object result = null; - if (propertyName != null && entry != null) { - result = JavaBeanObjectUtil.getProperty(entry, propertyName); - } - return result; - } - - public void setValue(R entry, Object value) { - if (propertyName != null) { - JavaBeanObjectUtil.setProperty(entry, propertyName, value); - } - } - -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/MoveToNextEditableCellAction.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/MoveToNextEditableCellAction.java deleted file mode 100644 index 674ca97..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/MoveToNextEditableCellAction.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.nuiton.jaxx.application.swing.table; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.JTable; -import java.awt.event.ActionEvent; - -/** - * Action to select next editable cell in a table. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class MoveToNextEditableCellAction<M extends AbstractApplicationTableModel> extends AbstractSelectTableAction<M> { - - private static final long serialVersionUID = 1L; - - /** Logger. */ - private static final Log log = - LogFactory.getLog(MoveToNextEditableCellAction.class); - - public static <M extends AbstractApplicationTableModel> MoveToNextEditableCellAction<M> newAction(M model, JTable table) { - return new MoveToNextEditableCellAction<>(model, table); - } - - protected MoveToNextEditableCellAction(M model, JTable table) { - super(model, table); - } - - @Override - public void actionPerformed(ActionEvent e) { - - int currentRow = getSelectedRow(); - int currentColumn = getSelectedColumn(); - - if (log.isDebugEnabled()) { - log.debug("Move to previous editable cell " + - getCellCoordinate(currentRow, currentColumn)); - } - - int columnCount = getColumnCount(); - - int rowCount = getRowCount(); - - if (currentRow <= rowCount || currentColumn <= columnCount) { - - // go to next cell - currentColumn++; - boolean canSelect = true; - - // select next cell - if (currentColumn >= columnCount) { - - // no more cell, so will move to next editable column on next row - currentColumn = 0; - currentRow++; - - if (currentRow == rowCount) { - - if (isCreateNewRow()) { - - // create a new row in model - addNewRow(); - } else { - - // can not create new row, so do nothing - canSelect = false; - } - } - } - - if (canSelect) { - doSelectCell(currentRow, currentColumn); - } - } - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/MoveToNextEditableRowAction.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/MoveToNextEditableRowAction.java deleted file mode 100644 index a86fe65..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/MoveToNextEditableRowAction.java +++ /dev/null @@ -1,91 +0,0 @@ -package org.nuiton.jaxx.application.swing.table; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.JTable; -import java.awt.event.ActionEvent; - -/** - * Action to select next editable row in a table. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class MoveToNextEditableRowAction<M extends AbstractApplicationTableModel> extends AbstractSelectTableAction<M> { - - private static final long serialVersionUID = 1L; - - /** Logger. */ - private static final Log log = - LogFactory.getLog(MoveToNextEditableRowAction.class); - - public static <M extends AbstractApplicationTableModel> MoveToNextEditableRowAction<M> newAction(M model, JTable table) { - return new MoveToNextEditableRowAction<>(model, table); - } - - protected MoveToNextEditableRowAction(M model, JTable table) { - super(model, table); - } - - @Override - public void actionPerformed(ActionEvent e) { - int currentRow = getSelectedRow(); - int currentColumn = getSelectedColumn(); - - if (log.isDebugEnabled()) { - log.debug("Move to next row editable cell " + - getCellCoordinate(currentRow, currentColumn)); - } - - int rowCount = getRowCount(); - - if (currentRow < rowCount) { - // go to next cell - currentRow++; - boolean canSelect = true; - - // select next cell - if (currentRow >= rowCount) { - - if (log.isDebugEnabled()) { - log.debug("No next row"); - } - if (isCreateNewRow()) { - - // create a new row in model - addNewRow(); - - } else { - canSelect = false; - } - } - - if (canSelect) { - doSelectCell(currentRow, currentColumn); - } - } - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/MoveToPreviousEditableCellAction.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/MoveToPreviousEditableCellAction.java deleted file mode 100644 index b951522..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/MoveToPreviousEditableCellAction.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.nuiton.jaxx.application.swing.table; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.JTable; -import java.awt.event.ActionEvent; - -/** - * Action to select previous editable cell in a table. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class MoveToPreviousEditableCellAction<M extends AbstractApplicationTableModel> extends AbstractSelectTableAction<M> { - - private static final long serialVersionUID = 1L; - - /** Logger. */ - private static final Log log = - LogFactory.getLog(MoveToPreviousEditableCellAction.class); - - public static <M extends AbstractApplicationTableModel> MoveToPreviousEditableCellAction<M> newAction(M model, JTable table) { - return new MoveToPreviousEditableCellAction<>(model, table); - } - - protected MoveToPreviousEditableCellAction(M model, JTable table) { - super(model, table); - } - - @Override - public void actionPerformed(ActionEvent e) { - int currentRow = getSelectedRow(); - int currentColumn = getSelectedColumn(); - - if (log.isDebugEnabled()) { - log.debug("Move to previous editable cell, " + - getCellCoordinate(currentRow, currentColumn)); - } - - int columnCount = getColumnCount(); - - if (currentRow > 0 || currentColumn > 0) { - - // go to next cell - currentColumn--; - - // select next cell - if (currentColumn < 0) { - - currentColumn = columnCount - 1; - currentRow--; - } - - doSelectCell(currentRow, currentColumn); - } - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/MoveToPreviousEditableRowAction.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/MoveToPreviousEditableRowAction.java deleted file mode 100644 index 05117c9..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/table/MoveToPreviousEditableRowAction.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.nuiton.jaxx.application.swing.table; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.JTable; -import java.awt.event.ActionEvent; - -/** - * Action to select previous editable row in a table. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class MoveToPreviousEditableRowAction<M extends AbstractApplicationTableModel> extends AbstractSelectTableAction<M> { - - private static final long serialVersionUID = 1L; - - /** Logger. */ - private static final Log log = - LogFactory.getLog(MoveToPreviousEditableRowAction.class); - - public static <M extends AbstractApplicationTableModel> MoveToPreviousEditableRowAction<M> newAction(M model, JTable table) { - return new MoveToPreviousEditableRowAction<>(model, table); - } - - protected MoveToPreviousEditableRowAction(M model, JTable table) { - super(model, table); - } - - @Override - public void actionPerformed(ActionEvent e) { - - int currentRow = getSelectedRow(); - int currentColumn = getSelectedColumn(); - - if (log.isDebugEnabled()) { - log.debug("Move to previous row editable cell " + - getCellCoordinate(currentRow, currentColumn)); - } - - if (currentRow > 0) { - - // go to next cell - currentRow--; - doSelectCell(currentRow, currentColumn); - } - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/ActionListCellRenderer.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/ActionListCellRenderer.java deleted file mode 100644 index 6099d16..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/ActionListCellRenderer.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.nuiton.jaxx.application.swing.util; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import javax.swing.Action; -import javax.swing.DefaultListCellRenderer; -import javax.swing.Icon; -import javax.swing.JButton; -import javax.swing.JList; -import javax.swing.border.EmptyBorder; -import java.awt.Component; - -/** - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class ActionListCellRenderer extends DefaultListCellRenderer { - - private static final long serialVersionUID = 1L; - - protected final EmptyBorder border = new EmptyBorder(4, 8, 4, 8); - - @Override - public Component getListCellRendererComponent(JList list, - Object value, - int index, - boolean isSelected, - boolean cellHasFocus) { - - Component result = super.getListCellRendererComponent( - list, value, index, isSelected, cellHasFocus); - Action action = ((JButton) value).getAction(); - setIcon((Icon) action.getValue(Action.LARGE_ICON_KEY)); - setText((String) action.getValue(Action.NAME)); - setToolTipText((String) action.getValue(Action.SHORT_DESCRIPTION)); - setEnabled(action.isEnabled()); - setBorder(border); - return result; - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/ApplicationColorHighlighter.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/ApplicationColorHighlighter.java deleted file mode 100644 index a68c3e2..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/ApplicationColorHighlighter.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.nuiton.jaxx.application.swing.util; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.jdesktop.swingx.decorator.AbstractHighlighter; -import org.jdesktop.swingx.decorator.ComponentAdapter; -import org.jdesktop.swingx.decorator.HighlightPredicate; -import org.jdesktop.swingx.util.PaintUtils; - -import java.awt.Color; -import java.awt.Component; - -/** - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class ApplicationColorHighlighter extends AbstractHighlighter { - - protected final Color color; - - protected final boolean foreground; - - public ApplicationColorHighlighter(HighlightPredicate predicate, Color color, boolean foreground) { - super(predicate); - this.color = color; - this.foreground = foreground; - } - - @Override - protected Component doHighlight(Component component, ComponentAdapter adapter) { - - if (foreground) { - component.setForeground(color); - - } else { - component.setBackground(color); - if (adapter.isSelected()) { - component.setForeground(PaintUtils.computeForeground(color)); - } - } - - return component; - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/ApplicationErrorHelper.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/ApplicationErrorHelper.java deleted file mode 100644 index 85fe4c9..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/ApplicationErrorHelper.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.nuiton.jaxx.application.swing.util; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.jdesktop.swingx.JXErrorPane; -import org.jdesktop.swingx.error.ErrorInfo; -import org.jdesktop.swingx.error.ErrorReporter; -import org.nuiton.csv.ImportRuntimeException; -import org.nuiton.jaxx.application.ApplicationBusinessException; -import org.nuiton.jaxx.application.swing.ApplicationUIContext; -import org.nuiton.jaxx.application.swing.action.ApplicationActionUI; - -import javax.swing.JOptionPane; - -import static org.nuiton.i18n.I18n.t; - -/** - * Helper to display errors. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class ApplicationErrorHelper implements ErrorReporter { - - protected final ApplicationUIContext context; - - public ApplicationErrorHelper(ApplicationUIContext context) { - this.context = context; - } - - /** - * Display a user friendly error frame. - * - * @param message message for user - * @param cause exception cause - */ - public void showErrorDialog(String message, Throwable cause) { - - if (cause == null) { - JOptionPane.showMessageDialog(context.getMainUI(), "<html><body>" + message + "</body></html>", - t("jaxx.application.error.ui.business.error"), - JOptionPane.ERROR_MESSAGE); - } else if (cause instanceof ApplicationBusinessException) { - JOptionPane.showMessageDialog(context.getMainUI(), "<html><body>" + cause.getMessage() + "</body></html>", - t("jaxx.application.error.ui.business.error"), - JOptionPane.ERROR_MESSAGE); - } else if (cause instanceof ImportRuntimeException) { - JOptionPane.showMessageDialog(context.getMainUI(), cause.getMessage(), - t("jaxx.application.error.ui.business.error"), - JOptionPane.ERROR_MESSAGE); - } else { - - JXErrorPane pane = new JXErrorPane(); - ErrorInfo info = new ErrorInfo(t("jaxx.application.error.ui.other.error"), - t("jaxx.application.error.errorpane.htmlmessage", message), null, null, - cause, null, null); - pane.setErrorInfo(info); - pane.setErrorReporter(this); - ApplicationActionUI actionUI = context.getActionUI(); - if (actionUI != null) { - actionUI.close(); - } - JXErrorPane.showDialog(context.getMainUI(), pane); - } - - } - - /** - * Display a user friendly error frame. - * - * @param message message for user - */ - public void showErrorDialog(String message) { - showErrorDialog(message, null); - } - - @Override - public void reportError(ErrorInfo errorInfo) throws NullPointerException { - - showErrorDialog(errorInfo.getBasicErrorMessage(), errorInfo.getErrorException()); - } - - /** - * Display a user friendly warning frame. - * - * @param message message for user - */ - public void showWarningDialog(String message) { - - JOptionPane.showMessageDialog(context.getMainUI(), "<html><body>" + message + "</body></html>", - t("jaxx.application.error.ui.business.warning"), - JOptionPane.WARNING_MESSAGE); - - } - -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/ApplicationExceptionHandler.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/ApplicationExceptionHandler.java deleted file mode 100644 index c848962..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/ApplicationExceptionHandler.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.nuiton.jaxx.application.swing.util; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.nuiton.jaxx.runtime.swing.JAXXRuntimeException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.jaxx.application.ApplicationTechnicalException; - -/** - * Global exception handler. - * - * Catch all application uncaught and display it in a custom JoptionPane - * or JXErrorPane. - * - * See http://stackoverflow.com/a/4448569/1165234 for details. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class ApplicationExceptionHandler implements Thread.UncaughtExceptionHandler { - - private static final Log log = - LogFactory.getLog(ApplicationExceptionHandler.class); - - final ApplicationErrorHelper errorHelper; - - public ApplicationExceptionHandler(ApplicationErrorHelper errorHelper) { - this.errorHelper = errorHelper; - } - - @Override - public void uncaughtException(Thread t, Throwable ex) { - handleException(t.getName(), ex); - } - - public void handle(Throwable thrown) { - // for EDT exceptions - handleException(Thread.currentThread().getName(), thrown); - } - - protected void handleException(String tname, Throwable ex) { - if (log.isErrorEnabled()) { - log.error("Global application exception [" + tname + "]", ex); - } - - Throwable cause = getCause(ex); - - showErrorDialog(cause.getMessage(), cause); - } - - protected Throwable getCause(Throwable ex) { - - Throwable cause = ex; - - if (cause instanceof ApplicationTechnicalException) { - cause = cause.getCause(); - } - - if (cause instanceof JAXXRuntimeException) { - cause = cause.getCause(); - } - return cause; - } - - public void showErrorDialog(String message, Throwable cause) { - errorHelper.showErrorDialog(message, cause); - } -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/ApplicationUIUtil.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/ApplicationUIUtil.java deleted file mode 100644 index 57cdac1..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/ApplicationUIUtil.java +++ /dev/null @@ -1,208 +0,0 @@ -package org.nuiton.jaxx.application.swing.util; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.nuiton.jaxx.runtime.JAXXObject; -import org.nuiton.jaxx.runtime.swing.JTables; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jdesktop.swingx.JXTable; -import org.jdesktop.swingx.decorator.HighlightPredicate; -import org.jdesktop.swingx.decorator.Highlighter; -import org.nuiton.jaxx.application.ApplicationTechnicalException; -import org.nuiton.jaxx.application.swing.ApplicationUIContext; - -import javax.swing.JTable; -import java.awt.Color; -import java.awt.Desktop; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; - -import static org.nuiton.i18n.I18n.t; - -/** - * Useful ui methods. - * - * Created on 11/23/13. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public class ApplicationUIUtil { - - /** Logger. */ - private static final Log log = LogFactory.getLog(ApplicationUIUtil.class); - - protected ApplicationUIUtil() { - // avoid instanciate util class - } - - public static void setApplicationContext(JAXXObject ui, ApplicationUIContext context) { - ui.setContextValue(context, "applicationContext"); - } - - public static ApplicationUIContext getApplicationContext(JAXXObject ui) { - return ui.getContextValue(ApplicationUIContext.class, "applicationContext"); - } - - public static Highlighter newBackgroundColorHighlighter(HighlightPredicate predicate, Color color) { - return new ApplicationColorHighlighter(predicate, color, false); - } - - public static Highlighter newForegroundColorHighlighter(HighlightPredicate predicate, Color color) { - return new ApplicationColorHighlighter(predicate, color, true); - } - - public static void openLink(URL url) { - try { - openLink(url.toURI()); - } catch (URISyntaxException e) { - throw new ApplicationTechnicalException(t("jaxx.application.error.cannot.open.link", url), e); - } - } - - public static Desktop getDesktopForBrowse() { - - if (!Desktop.isDesktopSupported()) { - throw new ApplicationTechnicalException( - t("jaxx.application.error.desktop.not.supported")); - } - - Desktop desktop = Desktop.getDesktop(); - - if (!desktop.isSupported(Desktop.Action.BROWSE)) { - - throw new ApplicationTechnicalException( - t("jaxx.application.error.desktop.browse.not.supported")); - } - - return desktop; - } - - public static Desktop getDesktopForOpen() { - - if (!Desktop.isDesktopSupported()) { - throw new ApplicationTechnicalException( - t("jaxx.application.error.desktop.not.supported")); - } - - Desktop desktop = Desktop.getDesktop(); - - if (!desktop.isSupported(Desktop.Action.OPEN)) { - - throw new ApplicationTechnicalException( - t("jaxx.application.error.desktop.open.not.supported")); - } - - return desktop; - } - - public static void openLink(URI uri) { - - Desktop desktop = getDesktopForBrowse(); - - try { - - desktop.browse(uri); - } catch (Exception e) { - - throw new ApplicationTechnicalException( - t("jaxx.application.error.cannot.open.link", uri), e); - } - } - - public static Desktop getDesktopForMail() { - - if (!Desktop.isDesktopSupported()) { - throw new ApplicationTechnicalException( - t("jaxx.application.error.desktop.not.supported")); - } - - Desktop desktop = Desktop.getDesktop(); - - if (!desktop.isSupported(Desktop.Action.MAIL)) { - - throw new ApplicationTechnicalException( - t("jaxx.application.error.desktop.mail.not.supported")); - } - - return desktop; - } - - public static void mail(String subject, String body) { - - Desktop desktop = getDesktopForMail(); - - try { - URI mailtoURI = new URI("mailto", null, null, "subject=" + subject + "&body=" + body, null); - desktop.mail(mailtoURI); - - } catch (Exception e) { - - throw new ApplicationTechnicalException( - t("jaxx.application.error.cannot.mail"), e); - } - } - - /** - * @deprecated since 2.18, use instead {@link JTables#selectFirstCellOnFirstRowAndStopEditing(JTable)} - */ - @Deprecated - public static void selectFirstCellOnFirstRowAndStopEditing(JXTable table) { - - JTables.selectFirstCellOnFirstRowAndStopEditing(table); - - } - - /** - * @deprecated since 2.18, use instead {@link JTables#selectFirstCellOnLastRow(JTable)} - */ - @Deprecated - public static void selectFirstCellOnLastRow(JXTable table) { - - JTables.selectFirstCellOnLastRow(table); - - } - - /** - * @deprecated since 2.18, use instead {@link JTables#selectFirstCellOnRow(JTable, int, boolean)} - */ - @Deprecated - public static void selectFirstCellOnRow(JXTable table, int row, boolean stopEdit) { - - JTables.selectFirstCellOnRow(table, row, stopEdit); - - } - - /** - * @deprecated since 2.18, use instead {@link JTables#doSelectCell(JTable, int, int)} - */ - @Deprecated - public static void doSelectCell(JTable table, int rowIndex, int columnIndex) { - - JTables.doSelectCell(table, rowIndex, columnIndex); - - } - -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/Cancelable.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/Cancelable.java deleted file mode 100644 index 78719b8..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/Cancelable.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.nuiton.jaxx.application.swing.util; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -/** - * To cancel contract. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public interface Cancelable { - - void cancel(); -} diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/CloseableUI.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/CloseableUI.java deleted file mode 100644 index fec6ee7..0000000 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/CloseableUI.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.nuiton.jaxx.application.swing.util; - -/* - * #%L - * JAXX :: Application Swing - * %% - * Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -/** - * Place this contract on any handler of ui that need some check before closing. - * - * Contract to close an ui. - * - * @author Tony Chemit - dev@tchemit.fr - * @since 2.8 - */ -public interface CloseableUI { - - /** - * Try to quit UI. - * - * @return {@code true} if ui is safe to quit, {@code false} otherwise - * (means must stay on it). - */ - boolean quitUI(); -} diff --git a/jaxx-application-swing/src/main/resources/i18n/jaxx-application-swing_en_GB.properties b/jaxx-application-swing/src/main/resources/i18n/jaxx-application-swing_en_GB.properties deleted file mode 100644 index 9643ccf..0000000 --- a/jaxx-application-swing/src/main/resources/i18n/jaxx-application-swing_en_GB.properties +++ /dev/null @@ -1,23 +0,0 @@ -jaxx.application.action.create.error= -jaxx.application.common.askBeforeDelete.help= -jaxx.application.common.askCancelEditBeforeLeaving.help= -jaxx.application.common.askCancelEditBeforeLeaving.title= -jaxx.application.common.askOverwriteFile.help= -jaxx.application.common.askOverwriteFile.message= -jaxx.application.common.askOverwriteFile.title= -jaxx.application.common.askSaveBeforeLeaving.help= -jaxx.application.common.askSaveBeforeLeaving.title= -jaxx.application.common.datefield.tip= -jaxx.application.error.cannot.mail= -jaxx.application.error.cannot.open.link= -jaxx.application.error.desktop.browse.not.supported= -jaxx.application.error.desktop.mail.not.supported= -jaxx.application.error.desktop.not.supported= -jaxx.application.error.desktop.open.not.supported= -jaxx.application.error.errorpane.htmlmessage= -jaxx.application.error.ui.business.error= -jaxx.application.error.ui.business.warning= -jaxx.application.error.ui.other.error= -jaxx.application.message.action.running= -jaxx.application.tab.customtab.close.label= -jaxx.application.title.actionUI= diff --git a/jaxx-application-swing/src/main/resources/i18n/jaxx-application-swing_es_ES.properties b/jaxx-application-swing/src/main/resources/i18n/jaxx-application-swing_es_ES.properties deleted file mode 100644 index 9643ccf..0000000 --- a/jaxx-application-swing/src/main/resources/i18n/jaxx-application-swing_es_ES.properties +++ /dev/null @@ -1,23 +0,0 @@ -jaxx.application.action.create.error= -jaxx.application.common.askBeforeDelete.help= -jaxx.application.common.askCancelEditBeforeLeaving.help= -jaxx.application.common.askCancelEditBeforeLeaving.title= -jaxx.application.common.askOverwriteFile.help= -jaxx.application.common.askOverwriteFile.message= -jaxx.application.common.askOverwriteFile.title= -jaxx.application.common.askSaveBeforeLeaving.help= -jaxx.application.common.askSaveBeforeLeaving.title= -jaxx.application.common.datefield.tip= -jaxx.application.error.cannot.mail= -jaxx.application.error.cannot.open.link= -jaxx.application.error.desktop.browse.not.supported= -jaxx.application.error.desktop.mail.not.supported= -jaxx.application.error.desktop.not.supported= -jaxx.application.error.desktop.open.not.supported= -jaxx.application.error.errorpane.htmlmessage= -jaxx.application.error.ui.business.error= -jaxx.application.error.ui.business.warning= -jaxx.application.error.ui.other.error= -jaxx.application.message.action.running= -jaxx.application.tab.customtab.close.label= -jaxx.application.title.actionUI= diff --git a/jaxx-application-swing/src/main/resources/i18n/jaxx-application-swing_fr_FR.properties b/jaxx-application-swing/src/main/resources/i18n/jaxx-application-swing_fr_FR.properties deleted file mode 100644 index 5af83ef..0000000 --- a/jaxx-application-swing/src/main/resources/i18n/jaxx-application-swing_fr_FR.properties +++ /dev/null @@ -1,23 +0,0 @@ -jaxx.application.action.create.error=Erreur à l'instanciation de l'action %s -jaxx.application.common.askBeforeDelete.help=Que voulez-vous faire ?<ul><li><strong>Annuler</strong> pour ne pas supprimer</li><li><strong>OK</strong> pour supprimer l'objet en question</li></ul> -jaxx.application.common.askCancelEditBeforeLeaving.help=Que voulez-vous faire ?<ul><li><strong>Annuler</strong> pour rester sur cet écran</li><li><strong>OK</strong> pour quitter l'écran en abandonnant les modifications</li></ul> -jaxx.application.common.askCancelEditBeforeLeaving.title=Modifications non enregistrées mais invalides -jaxx.application.common.askOverwriteFile.help=Que voulez-vous faire ?<ul><li><strong>Annuler</strong> pour ne pas écraser le fichier et annuler l'opération</li><li><strong>Oui</strong> pour écraser le fichier et continuer l'opération</li></ul> -jaxx.application.common.askOverwriteFile.message=Le fichier %s existe déjà, confirmer pour l'écraser -jaxx.application.common.askOverwriteFile.title=Confirmer l'écrasement d'un fichier... -jaxx.application.common.askSaveBeforeLeaving.help=Que voulez-vous faire?<ul><li><strong>Annuler</strong> pour rester sur cet écran</li><li><strong>Non</strong> pour quitter l'écran en abandonnant les modifications en cours</li><li><strong>Oui</strong> pour quitter l'écran après enregistrement des modifications</li></ul> -jaxx.application.common.askSaveBeforeLeaving.title=Modifications non enregistrées -jaxx.application.common.datefield.tip=Format attendu \: %s -jaxx.application.error.cannot.mail=Erreur lors de l'ouverture du client mail -jaxx.application.error.cannot.open.link=Impossible d'ouvrir le fichier %s -jaxx.application.error.desktop.browse.not.supported=Le navigateur n'a pas pu être ouvert. Vérifiez que vous avez défini un navigateur par défaut dans votre système -jaxx.application.error.desktop.mail.not.supported=Le client mail n'a pas pu être ouvert. Vérifiez que vous avez défini un client mail par défaut dans votre système -jaxx.application.error.desktop.not.supported=Votre système ne permet pas d'ouvrir des liens ou fichiers en dehors de l'application -jaxx.application.error.desktop.open.not.supported=Le fichier n'a pas pu être ouvert. Vérifiez que vous avez défini un logiciel par défaut dans votre système pour ce type de fichier -jaxx.application.error.errorpane.htmlmessage=<html><body><b>Une erreur s'est produite</b>\:<br/>%s</body></html> -jaxx.application.error.ui.business.error=Erreur -jaxx.application.error.ui.business.warning=Avertissement -jaxx.application.error.ui.other.error=Erreur -jaxx.application.message.action.running=<html>Action <strong>%s</strong> en cours d'exécution...</html> -jaxx.application.tab.customtab.close.label=Fermer l'onglet -jaxx.application.title.actionUI=%s - v %s [%s] diff --git a/jaxx-application-swing/src/site/site.xml b/jaxx-application-swing/src/site/site.xml deleted file mode 100644 index 2975066..0000000 --- a/jaxx-application-swing/src/site/site.xml +++ /dev/null @@ -1,44 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - #%L - JAXX :: Application Swing - %% - Copyright (C) 2008 - 2014 Code Lutin, Tony Chemit - %% - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser 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 Lesser Public License for more details. - You should have received a copy of the GNU General Lesser Public - License along with this program. If not, see - <http://www.gnu.org/licenses/lgpl-3.0.html>. - #L% - --> - -<project name="${project.name}" - xmlns="http://maven.apache.org/DECORATION/1.4.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/DECORATION/1.4.0 http://maven.apache.org/xsd/decoration-1.4.0.xsd"> - - <bannerLeft> - <name>${project.name}</name> - <src>${siteCommonResourcesUrl}/images/logos/jaxx-logo.png</src> - <href>index.html</href> - </bannerLeft> - - <body> - - <breadcrumbs> - <item name="${project.name}" href="index.html"/> - </breadcrumbs> - - <menu ref="parent"/> - - <menu ref="reports"/> - - </body> -</project> diff --git a/pom.xml b/pom.xml index e13d74d..bdd0ef9 100644 --- a/pom.xml +++ b/pom.xml @@ -47,8 +47,6 @@ <module>jaxx-widgets-datetime</module> <module>jaxx-widgets-gis</module> <module>jaxx-config</module> - <module>jaxx-application-api</module> - <module>jaxx-application-swing</module> </modules> <developers> -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.