[izpack-changes] r1706 - in izpack-src/trunk/src: . lib/com/izforge/izpack/event lib/com/izforge/izpack/panels

noreply at berlios.de noreply at berlios.de
Sat Jan 13 19:03:06 CET 2007


Author: jponge
Date: 2007-01-13 19:02:49 +0100 (Sat, 13 Jan 2007)
New Revision: 1706

Added:
   izpack-src/trunk/src/lib/com/izforge/izpack/event/LateShortcutInstallListener.java
Modified:
   izpack-src/trunk/src/build.xml
   izpack-src/trunk/src/lib/com/izforge/izpack/panels/ShortcutPanel.java
Log:
UserInputPanel (Markus Schlegel via Julien Ponge):
  - support for the new "installGroup"-attribute for the "programGroup" element of the shortcutSpec.xml
  - late creation of shortcuts, for example in case ShortcutPanel is displayed before InstallPanel
  - fixed a bug where each Shortcut-Subgroup influenced the remaining Shortcut creation



Modified: izpack-src/trunk/src/build.xml
===================================================================
--- izpack-src/trunk/src/build.xml	2007-01-13 17:39:52 UTC (rev 1705)
+++ izpack-src/trunk/src/build.xml	2007-01-13 18:02:49 UTC (rev 1706)
@@ -696,6 +696,7 @@
     <!-- Macro to compile a listener's classes and create its jar file -->
     <macrodef name="build-listener">
         <attribute name="name" description="The listener jar will get this name" />
+        <attribute name="classpath-ext" description="An extension of the classpath required to build the listener" default=""/>
         <attribute name="srcdir"
                    default="${src.dir}"
                    description="Source directory. Defaults to izpack src dir" />
@@ -710,7 +711,7 @@
             <!-- sourcepath is cleared so there's no mistaking what goes into the Listener -->
             <javac srcdir="@{srcdir}"
                    destdir="${bin.dir}/customActions/@{name}"
-                   classpath="${installer.jar};${compiler.jar};${izevent.jar}"
+                   classpath="${installer.jar};${compiler.jar};${izevent.jar};@{classpath-ext}"
                    sourcepath=""
                    optimize="on"
                    deprecation="on"
@@ -747,12 +748,13 @@
     <!-- Convenience macro to call build-listener for installer listeners -->
     <macrodef name="build-installer-listener">
         <attribute name="name" />
+        <attribute name="classpath-ext" description="An extension of the classpath required to build the listener" default=""/>
         <attribute name="srcdir" default="${src.dir}" />
         <element name="installer-fileset"
                  implicit="yes"
                  description="include and exclude elements indicating listener sources" />
         <sequential>
-            <build-listener name="@{name}" srcdir="@{srcdir}" izeventExcludes="**/*Uninstaller*">
+            <build-listener name="@{name}" srcdir="@{srcdir}" izeventExcludes="**/*Uninstaller*" classpath-ext="@{classpath-ext}">
                 <installer-fileset />
             </build-listener>
         </sequential>
@@ -779,7 +781,12 @@
          This also acts as a check to help limit dependancies.
     -->
     <target name="build.listeners" depends="build.compiler,build.installer,build.listener-base">
-        <build-installer-listener name="AntActionInstallerListener">
+    	<!-- This dependency is mandatory -->
+    	<build-installer-listener name="LateShortcutInstallListener" classpath-ext="${bin.dir}/panels/ShortcutPanel.jar">
+            <include name="com/izforge/izpack/event/LateShortcutInstallListener.java" />
+        </build-installer-listener>
+
+    	<build-installer-listener name="AntActionInstallerListener">
             <include name="com/izforge/izpack/event/AntActionInstallerListener.java" />
             <include name="com/izforge/izpack/event/AntAction.java" />
         </build-installer-listener>

Added: izpack-src/trunk/src/lib/com/izforge/izpack/event/LateShortcutInstallListener.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/event/LateShortcutInstallListener.java	2007-01-13 17:39:52 UTC (rev 1705)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/event/LateShortcutInstallListener.java	2007-01-13 18:02:49 UTC (rev 1706)
@@ -0,0 +1,48 @@
+/*
+ * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
+ * 
+ * http://www.izforge.com/izpack/
+ * http://developer.berlios.de/projects/izpack/
+ * 
+ * Copyright 2007 Markus Schlegel
+ * Copyright 2007 Julien Ponge
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *     
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.izforge.izpack.event;
+
+import com.izforge.izpack.installer.*;
+import com.izforge.izpack.panels.ShortcutPanel;
+import com.izforge.izpack.util.AbstractUIProgressHandler;
+
+/**
+ * Creates the Shortcuts after files have been installed.
+ * Use this listener, if you place the ShortcutPanel before the Installation of the files.
+ * 
+ * @author Marcus Schlegel, Pulinco
+ */
+public class LateShortcutInstallListener extends SimpleInstallerListener {
+
+  public LateShortcutInstallListener()
+  {
+      ShortcutPanel.getInstance().createImmediately = false;
+  }
+  
+  public void afterPacks(AutomatedInstallData idata, AbstractUIProgressHandler handler)
+  throws Exception
+  {
+      //now it's time to write down the shortcuts...
+      ShortcutPanel.getInstance().createAndRegisterShortcuts();
+  }
+}

Modified: izpack-src/trunk/src/lib/com/izforge/izpack/panels/ShortcutPanel.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/panels/ShortcutPanel.java	2007-01-13 17:39:52 UTC (rev 1705)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/panels/ShortcutPanel.java	2007-01-13 18:02:49 UTC (rev 1706)
@@ -54,6 +54,8 @@
  * a program group for shortcuts, accept the creation of desktop shortcuts and actually creates the
  * shortcuts.
  * 
+ * Use LateShortcutInstallListener to create the Shortcuts after the Files have been installed.
+ * 
  * @version $Revision$
  */
 public class ShortcutPanel extends IzPanel implements ActionListener, ListSelectionListener // ,//
@@ -146,6 +148,10 @@
     // ------------------------------------------------------
     /** SPEC_ATTRIBUTE_DEFAULT_GROUP = "defaultName" */
     private static final String SPEC_ATTRIBUTE_DEFAULT_GROUP = "defaultName";
+    
+    /** Support the InstallGroups like in Packs.
+     * SPEC_ATTRIBUTE_INSTALLGROUP = "installGroup" */
+    private static final String SPEC_ATTRIBUTE_INSTALLGROUP = "installGroup";
 
     /** SPEC_ATTRIBUTE_LOCATION = "location" */
     private static final String SPEC_ATTRIBUTE_LOCATION = "location";
@@ -218,8 +224,6 @@
     // automatic script section keys
     // ------------------------------------------------------
 
-    /**   */
-
     /** AUTO_KEY_PROGRAM_GROUP = SPEC_KEY_PROGRAM_GROUP = "programGroup" */
     public static final String AUTO_KEY_PROGRAM_GROUP = SPEC_KEY_PROGRAM_GROUP;
 
@@ -269,6 +273,13 @@
 
     /** internal flag: create */
     static boolean create;
+    
+    /** 
+     * May be switched by an installerlistener to false.
+     * Installerlistener may then perform the creation of the shortcuts after the files have been installed...
+     * Default is true.
+     */
+    public static boolean createImmediately = true;
 
     /** internal flag isRootUser */
     private static boolean isRootUser;
@@ -565,11 +576,10 @@
 
         create = createShortcuts.isSelected();
 
-        createShortcuts();
+        if (createImmediately){
+            createAndRegisterShortcuts();
+        }
 
-        // add files and directories to the uninstaller
-        addToUninstaller();
-
         return (true);
     }
 
@@ -829,7 +839,29 @@
         // be placed and where this program group should be
         // located
         // ----------------------------------------------------
-        XMLElement group = spec.getFirstChildNamed(SPEC_KEY_PROGRAM_GROUP);
+        
+        XMLElement group = null;
+        Vector groupSpecs = spec.getChildrenNamed(SPEC_KEY_PROGRAM_GROUP);
+        String selectedInstallGroup = idata.getVariable("INSTALL_GROUP");
+        if (selectedInstallGroup!=null){
+            //The user selected an InstallGroup before.
+            //We may have some restrictions on the Installationgroup
+            //search all defined ProgramGroups for the given InstallGroup
+            for (int i = 0; i < groupSpecs.size(); i++)
+            {
+                XMLElement g = (XMLElement)groupSpecs.get(i);
+                String instGrp = g.getAttribute(SPEC_ATTRIBUTE_INSTALLGROUP);
+                if (instGrp!=null && selectedInstallGroup.equalsIgnoreCase(instGrp)){
+                    group = g;
+                    break;
+                }
+            }
+        }
+        if (group==null){
+            //default (old) behavior
+            group = spec.getFirstChildNamed(SPEC_KEY_PROGRAM_GROUP);
+        }
+        
         String location = null;
         hasDesktopShortcuts = false;
 
@@ -1080,6 +1112,16 @@
     /*--------------------------------------------------------------------------*/
 
     /**
+     * Enables Shortcutcreation from outside, e.g. from an InstallerListener.
+     * The Installerlistener can switch the flag "createImmediately" to false on initialisation, and call this method when afterpacks is performed.
+     * This makes only sense, if the ShorcutPanel is displayed before the files are copied onto the disk.
+     */
+    public void createAndRegisterShortcuts(){
+      createShortcuts();
+      addToUninstaller();
+    }
+    
+    /**
      * Creates all shortcuts based on the information in shortcuts.
      */
 
@@ -1089,6 +1131,9 @@
         if (!create) { Debug.log( this.getClass().getName() + "::createShortcuts():create=" + create ); return; }
 
         ShortcutData data;
+        
+        //fix: don't influence other shortcuts when altering group name...
+        String gn = groupName;
 
         for (int i = 0; i < shortcuts.size(); i++)
         {
@@ -1096,7 +1141,7 @@
 
             try
             {
-                groupName = groupName + data.subgroup;
+                gn = groupName + data.subgroup;
                 shortcut.setUserType(itsUserType);
                 shortcut.setLinkName(data.name);
                 shortcut.setLinkType(data.type);
@@ -1124,7 +1169,7 @@
 
                 if (data.addToGroup)
                 {
-                    shortcut.setProgramGroup(groupName);
+                    shortcut.setProgramGroup(gn);
                 }
                 else
                 {




More information about the izpack-changes mailing list