1a1b4a26bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3a1b4a26bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4a1b4a26bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5a1b4a26bSAndrew Rist  * distributed with this work for additional information
6a1b4a26bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7a1b4a26bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8a1b4a26bSAndrew Rist  * "License"); you may not use this file except in compliance
9a1b4a26bSAndrew Rist  * with the License.  You may obtain a copy of the License at
10a1b4a26bSAndrew Rist  *
11a1b4a26bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12a1b4a26bSAndrew Rist  *
13a1b4a26bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14a1b4a26bSAndrew Rist  * software distributed under the License is distributed on an
15a1b4a26bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16a1b4a26bSAndrew Rist  * KIND, either express or implied.  See the License for the
17a1b4a26bSAndrew Rist  * specific language governing permissions and limitations
18a1b4a26bSAndrew Rist  * under the License.
19a1b4a26bSAndrew Rist  *
20a1b4a26bSAndrew Rist  *************************************************************/
21a1b4a26bSAndrew Rist 
22a1b4a26bSAndrew Rist 
23cdf0e10cSrcweir package com.sun.star.wizards.web;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir //import com.sun.star.awt.ItemEvent;
26cdf0e10cSrcweir //import com.sun.star.awt.XItemListener;
27cdf0e10cSrcweir import java.io.FileNotFoundException;
28cdf0e10cSrcweir import java.util.Comparator;
29cdf0e10cSrcweir import java.util.List;
30cdf0e10cSrcweir import java.util.Vector;
31cdf0e10cSrcweir 
32cdf0e10cSrcweir import com.sun.star.awt.VclWindowPeerAttribute;
33cdf0e10cSrcweir import com.sun.star.awt.XControl;
34cdf0e10cSrcweir import com.sun.star.awt.XItemListener;
35cdf0e10cSrcweir import com.sun.star.awt.XWindow;
36cdf0e10cSrcweir import com.sun.star.awt.XWindowPeer;
37cdf0e10cSrcweir import com.sun.star.frame.XDesktop;
38cdf0e10cSrcweir import com.sun.star.frame.XFrame;
39cdf0e10cSrcweir import com.sun.star.frame.XModel;
40cdf0e10cSrcweir import com.sun.star.lang.EventObject;
41cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
42cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
43cdf0e10cSrcweir import com.sun.star.wizards.common.ConfigSet;
44cdf0e10cSrcweir import com.sun.star.wizards.common.Configuration;
45cdf0e10cSrcweir import com.sun.star.wizards.common.Desktop;
46cdf0e10cSrcweir import com.sun.star.wizards.common.FileAccess;
47cdf0e10cSrcweir import com.sun.star.wizards.common.Helper;
48cdf0e10cSrcweir import com.sun.star.wizards.common.JavaTools;
49cdf0e10cSrcweir import com.sun.star.wizards.common.PropertyNames;
50cdf0e10cSrcweir import com.sun.star.wizards.common.SystemDialog;
51cdf0e10cSrcweir import com.sun.star.wizards.document.OfficeDocument;
52cdf0e10cSrcweir import com.sun.star.wizards.ui.DocumentPreview;
53cdf0e10cSrcweir import com.sun.star.wizards.ui.event.DataAware;
54cdf0e10cSrcweir import com.sun.star.wizards.ui.event.ListModelBinder;
55cdf0e10cSrcweir import com.sun.star.wizards.ui.event.RadioDataAware;
56cdf0e10cSrcweir import com.sun.star.wizards.ui.event.SimpleDataAware;
57cdf0e10cSrcweir import com.sun.star.wizards.ui.event.Task;
58cdf0e10cSrcweir import com.sun.star.wizards.ui.event.UnoDataAware;
59cdf0e10cSrcweir import com.sun.star.wizards.web.data.CGContent;
60cdf0e10cSrcweir import com.sun.star.wizards.web.data.CGDocument;
61cdf0e10cSrcweir import com.sun.star.wizards.web.data.CGIconSet;
62cdf0e10cSrcweir import com.sun.star.wizards.web.data.CGPublish;
63cdf0e10cSrcweir import com.sun.star.wizards.web.data.CGSession;
64cdf0e10cSrcweir import com.sun.star.wizards.web.data.CGSessionName;
65cdf0e10cSrcweir import com.sun.star.wizards.web.data.CGSettings;
66cdf0e10cSrcweir import com.sun.star.wizards.web.data.CGStyle;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir /**
69cdf0e10cSrcweir  * Web Wizard Dialog implementation : Startup.
70cdf0e10cSrcweir  * This class contains the startup implementation and session mounting methods.<p/>
71cdf0e10cSrcweir  * <h2> Data Aware Concept </h2>
72cdf0e10cSrcweir  * <p> I use DataAware objects, which synchronize
73cdf0e10cSrcweir  * UI and Data. A DataAware object a kind of interface
74cdf0e10cSrcweir  * between a Value and a UI element.
75cdf0e10cSrcweir  * </P>
76cdf0e10cSrcweir  * <p>
77cdf0e10cSrcweir  * A Value is either a JavaBean property with
78*86e1cf34SPedro Giffuni  * a Getter and a Setter or a public class Member.
79cdf0e10cSrcweir  * </P>
80cdf0e10cSrcweir  * When the UI Control changes, the Value changes correspondingly.
81cdf0e10cSrcweir  * This depends on settings a Listener which calls the updateData()
82cdf0e10cSrcweir  * method od the DataAware object.
83cdf0e10cSrcweir  * When the Value changes, the UI Control changes respopndingly.
84cdf0e10cSrcweir  * This also depends on settings a Listener which calls the updateUI()
85cdf0e10cSrcweir  * method of the DataAware object.
86cdf0e10cSrcweir  * </P>
87cdf0e10cSrcweir  * <P>
88cdf0e10cSrcweir  * here I use only UI Listeners, and keep calling
89cdf0e10cSrcweir  * the updateUI() method whenever I change the Value.
90cdf0e10cSrcweir  * </P>
91cdf0e10cSrcweir  * To contain the Data, I use the Configuration Data Objects
92*86e1cf34SPedro Giffuni  * which read themselves out of the Configuration. they are all located under
93cdf0e10cSrcweir  * the data package.
94cdf0e10cSrcweir  * <p/>
95cdf0e10cSrcweir  * Different groups of DataAware objects are grouped into vectors.
96cdf0e10cSrcweir  * Each group (all elements of a vector) uses the same DataObject,
97cdf0e10cSrcweir  * so when I change the underlying dataObject, I change the whole vector's DataObject,
98cdf0e10cSrcweir  * thus actualizing UI.<br/>
99cdf0e10cSrcweir  * This is what happends when a session loads: I Load the session into
100cdf0e10cSrcweir  * a tree of DataObjects, and change the DataAware's DataObject. <br/>
101cdf0e10cSrcweir  * One could also look at this as a kind of "View-Model" relationship.
102cdf0e10cSrcweir  * The controls are the View, The DataObjects are the Model, containing the
103cdf0e10cSrcweir  * Data rad directly from the configuration, and the DataAware objects
104cdf0e10cSrcweir  * are the controller inbetween.
105cdf0e10cSrcweir  *
106cdf0e10cSrcweir  * @author rpiterman
107cdf0e10cSrcweir  *
108cdf0e10cSrcweir  */
109cdf0e10cSrcweir public abstract class WWD_Startup extends WWD_General
110cdf0e10cSrcweir {
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     SimpleDataAware sda = null;
113cdf0e10cSrcweir     /**
114cdf0e10cSrcweir      * This is currently not used.
115cdf0e10cSrcweir      * It should have been a Listener which invoces
116cdf0e10cSrcweir      * an Update to the Preview-Document, only
117cdf0e10cSrcweir      * We did not implement the live-preview document,
118cdf0e10cSrcweir      * so this became obsolete.
119cdf0e10cSrcweir      */
120cdf0e10cSrcweir     protected DataAware.Listener refresh;
121cdf0e10cSrcweir     /**
122cdf0e10cSrcweir      * Is called whenever a field is changed which
123cdf0e10cSrcweir      * could affect the "create" button enable state,
124cdf0e10cSrcweir      * like publishing-checkboxes, save-session check- and textbox.
125cdf0e10cSrcweir      */
126cdf0e10cSrcweir     protected DataAware.Listener checkPublish = new CheckPublish();
127cdf0e10cSrcweir     /**
128cdf0e10cSrcweir      * The Vector containing DataAware objects
129cdf0e10cSrcweir      * which relay on the selected document
130cdf0e10cSrcweir      * as DataObject (or Model).
131cdf0e10cSrcweir      */
132cdf0e10cSrcweir     protected List docAware = new Vector();
133cdf0e10cSrcweir     /**
134cdf0e10cSrcweir      * The Vector containing DataAware objects
135cdf0e10cSrcweir      * which relay on the session's generalInfo
136cdf0e10cSrcweir      * Object (CGSession.cp_GeneralInfo) as
137cdf0e10cSrcweir      * DataObject (or model).
138cdf0e10cSrcweir      */
139cdf0e10cSrcweir     protected List genAware = new Vector();
140cdf0e10cSrcweir     /**
141cdf0e10cSrcweir      * The vector containing DataAware objectscm25npd ..
142cdf0e10cSrcweir      * which relay on the session's Design Object
143cdf0e10cSrcweir      * (CGSession.cp_Design) as DataObject
144cdf0e10cSrcweir      * (or model).
145cdf0e10cSrcweir      *
146cdf0e10cSrcweir      */
147cdf0e10cSrcweir     protected List designAware = new Vector();
148cdf0e10cSrcweir     /**
149cdf0e10cSrcweir      * A Vector containig the DataAware objects
150cdf0e10cSrcweir      * which relay on Publishing Objects.
151cdf0e10cSrcweir      * Differently from other Vectors, each
152cdf0e10cSrcweir      * DataAware object in this Vector relays
153cdf0e10cSrcweir      * on a <b>different</b> CGPublish object,
154cdf0e10cSrcweir      * So they are handled with more care.
155cdf0e10cSrcweir      */
156cdf0e10cSrcweir     protected List pubAware = new Vector(3);
157cdf0e10cSrcweir     /**
158cdf0e10cSrcweir      * The DataAware object which handles
159cdf0e10cSrcweir      * the documents-list events.
160cdf0e10cSrcweir      * This will call the set/getDocument() method
161cdf0e10cSrcweir      * implemented in WWD_General.
162cdf0e10cSrcweir      */
163cdf0e10cSrcweir     protected UnoDataAware docListDA;
164cdf0e10cSrcweir     /**
165cdf0e10cSrcweir      * DataAware object which synchronizes the session
166cdf0e10cSrcweir      * name in step 7 with the CGSession.cp_Name
167cdf0e10cSrcweir      */
168cdf0e10cSrcweir     protected UnoDataAware sessionNameDA;
169cdf0e10cSrcweir     /**
170cdf0e10cSrcweir      * Binds a ListModel to the UnoControlListBox.
171cdf0e10cSrcweir      */
172cdf0e10cSrcweir     protected ListModelBinder docsBinder;
173cdf0e10cSrcweir     /**
174cdf0e10cSrcweir      *  a DocumentPreview object is
175cdf0e10cSrcweir      * the UI OO Document preview
176cdf0e10cSrcweir      * in the Dialog
177cdf0e10cSrcweir      */
178cdf0e10cSrcweir     protected DocumentPreview dpStylePreview;
179cdf0e10cSrcweir     /**
180cdf0e10cSrcweir      * An Object that implements the
181cdf0e10cSrcweir      * File-copy and refresh of the
182cdf0e10cSrcweir      * style preview
183cdf0e10cSrcweir      */
184cdf0e10cSrcweir     protected StylePreview stylePreview;
185cdf0e10cSrcweir     /**
186cdf0e10cSrcweir      * the currently selected document.
187cdf0e10cSrcweir      */
188cdf0e10cSrcweir     protected short[] selectedDoc = new short[0];
189cdf0e10cSrcweir     /**
190cdf0e10cSrcweir      * If ftp proxies are on, ftp is disabled, and
191cdf0e10cSrcweir      * the true/false of the FTP publisher is set to false.
192cdf0e10cSrcweir      * In order to save it correctly when saving the session
193cdf0e10cSrcweir      * at the end, the original loaded value is saved to this variable;
194cdf0e10cSrcweir      */
195cdf0e10cSrcweir     boolean __ftp;
196cdf0e10cSrcweir     /**
197cdf0e10cSrcweir      * When the wizard starts, a new document opens.
198*86e1cf34SPedro Giffuni      * The backgroundDoc member contains the TextDocument
199cdf0e10cSrcweir      * instance used for that purpose.
200cdf0e10cSrcweir      */
201cdf0e10cSrcweir     protected XFrame myFrame;
202cdf0e10cSrcweir 
203cdf0e10cSrcweir 
204cdf0e10cSrcweir     /* ******************************************
205cdf0e10cSrcweir      *  ****************************************
206cdf0e10cSrcweir      *             General Methods
207cdf0e10cSrcweir      *  ****************************************
208cdf0e10cSrcweir      * ******************************************  */
209cdf0e10cSrcweir 
210cdf0e10cSrcweir     /*
211cdf0e10cSrcweir      * GENERAL Initialization  methods
212cdf0e10cSrcweir      */
213cdf0e10cSrcweir     /**
214cdf0e10cSrcweir      * He - my constructor !
215cdf0e10cSrcweir      * I call/do here in this order: <br/>
216cdf0e10cSrcweir      * Check if ftp http proxy is set, and warn user he can not use
217cdf0e10cSrcweir      * ftp if  it is.<br/>
218cdf0e10cSrcweir      * draw NaviBar and steps 1 to 7, incl. Step X,
219cdf0e10cSrcweir      * which is the Layouts ImageList on step 3.<br/>
220cdf0e10cSrcweir      * load the settings from the configuration. <br/>
221cdf0e10cSrcweir      * set the default save session name to the first
222cdf0e10cSrcweir      * available one (sessionX or something like that). <br/>
223cdf0e10cSrcweir      * set the Layouts ImageList ListModel, and call
224cdf0e10cSrcweir      * its "create()" method. <br/>
225cdf0e10cSrcweir      * check the content (documents) specified in the default session.<br/>
226cdf0e10cSrcweir      * fill the list boxes (saved sessions, styles, combobox save session). <br/>
227cdf0e10cSrcweir      * make data aware. <br/>
228cdf0e10cSrcweir      * updateUI (refreshes the display to crrespond to the data in
229cdf0e10cSrcweir      * the default session.)<br/>
230cdf0e10cSrcweir      * fill the documents listbox. <br/>
231cdf0e10cSrcweir      * if proxies are set, disable the ftp controls in step 7.
232cdf0e10cSrcweir      */
WWD_Startup(XMultiServiceFactory xmsf)233cdf0e10cSrcweir     public WWD_Startup(XMultiServiceFactory xmsf) throws Exception
234cdf0e10cSrcweir     {
235cdf0e10cSrcweir         super(xmsf);
236cdf0e10cSrcweir 
237cdf0e10cSrcweir         proxies = getOOProxies();
238cdf0e10cSrcweir 
239cdf0e10cSrcweir         String soTemplateDir = FileAccess.getOfficePath(xmsf, "Template", "share", "/wizard");
240cdf0e10cSrcweir 
241cdf0e10cSrcweir         String exclamationURL = FileAccess.connectURLs(soTemplateDir, "../wizard/bitmap/caution_16.png");
242cdf0e10cSrcweir         this.drawNaviBar();
243cdf0e10cSrcweir         this.buildStep1();
244cdf0e10cSrcweir         this.buildStep2();
245cdf0e10cSrcweir         this.buildStep3();
246cdf0e10cSrcweir 
247cdf0e10cSrcweir         this.buildStep4();
248cdf0e10cSrcweir         this.buildStep5();
249cdf0e10cSrcweir         this.buildStep6();
250cdf0e10cSrcweir         this.buildStep7(proxies, exclamationURL);
251cdf0e10cSrcweir         buildStepX();
252cdf0e10cSrcweir 
253cdf0e10cSrcweir         this.xMSF = xmsf;
254cdf0e10cSrcweir         XDesktop xDesktop = Desktop.getDesktop(xMSF);
255cdf0e10cSrcweir         myFrame = OfficeDocument.createNewFrame(xMSF, this);
256cdf0e10cSrcweir         Object doc = OfficeDocument.createNewDocument(myFrame, "swriter", false, true);
257cdf0e10cSrcweir 
258cdf0e10cSrcweir         loadSettings(doc);
259cdf0e10cSrcweir         setSaveSessionName(settings.cp_DefaultSession);
260cdf0e10cSrcweir 
261cdf0e10cSrcweir         ilLayouts.setListModel(settings.cp_Layouts);
262cdf0e10cSrcweir         ilLayouts.create(this);
263cdf0e10cSrcweir 
264cdf0e10cSrcweir         checkContent(settings.cp_DefaultSession.cp_Content, new Task(PropertyNames.EMPTY_STRING, PropertyNames.EMPTY_STRING, 99999), this.xControl);
265cdf0e10cSrcweir 
266cdf0e10cSrcweir         //saved sessions, styles, combobox save session.
267cdf0e10cSrcweir         // also set the chosen saved session...
268cdf0e10cSrcweir         fillLists();
269cdf0e10cSrcweir         makeDataAware();
270cdf0e10cSrcweir         // change the display to correspond to the current session.
271cdf0e10cSrcweir         updateUI();
272cdf0e10cSrcweir         // fill the documents listbox.
273cdf0e10cSrcweir         mount(settings.cp_DefaultSession.cp_Content);
274cdf0e10cSrcweir 
275cdf0e10cSrcweir 
276cdf0e10cSrcweir         if (proxies)
277cdf0e10cSrcweir         {
278cdf0e10cSrcweir             setEnabled(btnFTP, false);
279cdf0e10cSrcweir             setEnabled(chkFTP, false);
280cdf0e10cSrcweir         }
281cdf0e10cSrcweir     }
282cdf0e10cSrcweir 
283cdf0e10cSrcweir     /**
284cdf0e10cSrcweir      * return true if http proxies or other proxies
285cdf0e10cSrcweir      * which do not enable ftp to function correctly are set.
286cdf0e10cSrcweir      * @return true if (http) proxies are on.
287cdf0e10cSrcweir      * @throws Exception
288cdf0e10cSrcweir      */
getOOProxies()289cdf0e10cSrcweir     private boolean getOOProxies() throws Exception
290cdf0e10cSrcweir     {
291cdf0e10cSrcweir         Object node = Configuration.getConfigurationRoot(xMSF, "org.openoffice.Inet/Settings", false);
292cdf0e10cSrcweir         int i = Configuration.getInt("ooInetProxyType", node);
293cdf0e10cSrcweir         //System.out.println("WWD:Startup:getOOProxies:" + i);
294cdf0e10cSrcweir         switch (i)
295cdf0e10cSrcweir         {
296cdf0e10cSrcweir             case 0: //no proxies
297cdf0e10cSrcweir                 return false;
298cdf0e10cSrcweir             case 2: //http proxies
299cdf0e10cSrcweir                 return true;
300cdf0e10cSrcweir             default:
301cdf0e10cSrcweir                 return true;
302cdf0e10cSrcweir         }
303cdf0e10cSrcweir     }
304cdf0e10cSrcweir 
305cdf0e10cSrcweir     /**
306cdf0e10cSrcweir      * calculates the first available session name,
307cdf0e10cSrcweir      * and sets the current session name to it.
308cdf0e10cSrcweir      * The combobox text in step 7 will be updated
309cdf0e10cSrcweir      * automatically when updateUI() is called.
310cdf0e10cSrcweir      */
setSaveSessionName(CGSession session)311cdf0e10cSrcweir     protected void setSaveSessionName(CGSession session)
312cdf0e10cSrcweir     {
313cdf0e10cSrcweir         int max = 0;
314cdf0e10cSrcweir         int len = resources.resSessionName.length();
315cdf0e10cSrcweir         // traverse between the sessions and find the one that
316cdf0e10cSrcweir         // has the biggest number.
317cdf0e10cSrcweir         for (int i = 0; i < settings.cp_SavedSessions.getSize(); i++)
318cdf0e10cSrcweir         {
319cdf0e10cSrcweir             String sessionName = ((CGSessionName) settings.cp_SavedSessions.getElementAt(i)).cp_Name;
320cdf0e10cSrcweir             if (sessionName.startsWith(resources.resSessionName))
321cdf0e10cSrcweir             {
322cdf0e10cSrcweir                 max = max(max, Integer.valueOf(sessionName.substring(len)).intValue());
323cdf0e10cSrcweir             }
324cdf0e10cSrcweir         }
325cdf0e10cSrcweir 
326cdf0e10cSrcweir         session.cp_Name = resources.resSessionName + ++max;
327cdf0e10cSrcweir 
328cdf0e10cSrcweir     }
329cdf0e10cSrcweir 
max(int i1, int i2)330cdf0e10cSrcweir     private int max(int i1, int i2)
331cdf0e10cSrcweir     {
332cdf0e10cSrcweir         if (i1 > i2)
333cdf0e10cSrcweir         {
334cdf0e10cSrcweir             return i1;
335cdf0e10cSrcweir         }
336cdf0e10cSrcweir         else
337cdf0e10cSrcweir         {
338cdf0e10cSrcweir             return i2;
339cdf0e10cSrcweir         }
340cdf0e10cSrcweir     }
341cdf0e10cSrcweir 
342cdf0e10cSrcweir     /**
343cdf0e10cSrcweir      * fills the road map, and sets the necessary properties,
344cdf0e10cSrcweir      * like MaxStep, Complete, Interactive-
345cdf0e10cSrcweir      * Disables the finbihButton.
346cdf0e10cSrcweir      */
addRoadMapItems()347cdf0e10cSrcweir     private void addRoadMapItems()
348cdf0e10cSrcweir     {
349cdf0e10cSrcweir         insertRoadMapItems(new String[]
350cdf0e10cSrcweir                 {
351cdf0e10cSrcweir                     resources.resStep1, resources.resStep2, resources.resStep3, resources.resStep4, resources.resStep5, resources.resStep6, resources.resStep7
352cdf0e10cSrcweir                 }, new int[]
353cdf0e10cSrcweir                 {
354cdf0e10cSrcweir                     1, 2, 3, 4, 5, 6, 7
355cdf0e10cSrcweir                 }, new boolean[]
356cdf0e10cSrcweir                 {
357cdf0e10cSrcweir                     true, true, false, false, false, false, false
358cdf0e10cSrcweir                 });
359cdf0e10cSrcweir 
360cdf0e10cSrcweir         setRoadmapInteractive(true);
361cdf0e10cSrcweir         setRoadmapComplete(true);
362cdf0e10cSrcweir         setCurrentRoadmapItemID((short) 1);
363cdf0e10cSrcweir         setMaxStep(7);
364cdf0e10cSrcweir         enableFinishButton(false);
365cdf0e10cSrcweir 
366cdf0e10cSrcweir     }
367cdf0e10cSrcweir 
368cdf0e10cSrcweir     /**
369cdf0e10cSrcweir      * This method goes through all
370cdf0e10cSrcweir      * the DataAware vectors and objects and
371cdf0e10cSrcweir      * calls their updateUI() method.
372cdf0e10cSrcweir      * In response, the UI is synchronized to
373cdf0e10cSrcweir      * the state of the corresponding data objects.
374cdf0e10cSrcweir      *
375cdf0e10cSrcweir      */
updateUI()376cdf0e10cSrcweir     private void updateUI()
377cdf0e10cSrcweir     {
378cdf0e10cSrcweir         DataAware.updateUI(designAware);
379cdf0e10cSrcweir         DataAware.updateUI(genAware);
380cdf0e10cSrcweir         DataAware.updateUI(pubAware);
381cdf0e10cSrcweir         sessionNameDA.updateUI();
382cdf0e10cSrcweir         checkPublish();
383cdf0e10cSrcweir     }
384cdf0e10cSrcweir 
getFrame(Object model)385cdf0e10cSrcweir     private XFrame getFrame(Object model)
386cdf0e10cSrcweir     {
387cdf0e10cSrcweir         XModel xmodel = UnoRuntime.queryInterface(XModel.class, model);
388cdf0e10cSrcweir         return xmodel.getCurrentController().getFrame();
389cdf0e10cSrcweir     }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir     /**
392cdf0e10cSrcweir      * create the peer, add roadmap,
393cdf0e10cSrcweir      * add roadmap items, add style-preview,
394cdf0e10cSrcweir      * disable the steps 3 to 7 if no documents are
395cdf0e10cSrcweir      * on the list, and... show the dialog!
396cdf0e10cSrcweir      */
show()397cdf0e10cSrcweir     public void show()
398cdf0e10cSrcweir     {
399cdf0e10cSrcweir         try
400cdf0e10cSrcweir         {
401cdf0e10cSrcweir 
402cdf0e10cSrcweir 
403cdf0e10cSrcweir             /* myFrame.initialize(docWindow);
404cdf0e10cSrcweir              * */
405cdf0e10cSrcweir 
406cdf0e10cSrcweir             //desktopFrame = Desktop.findAFrame(xMSF, myFrame, desktopFrame);
407cdf0e10cSrcweir 
408cdf0e10cSrcweir             //XWindow xContainerWindow = myFrame.getContainerWindow();
409cdf0e10cSrcweir 
410cdf0e10cSrcweir             XWindow xContainerWindow = myFrame.getComponentWindow();
411cdf0e10cSrcweir             XWindowPeer xWindowPeer = UnoRuntime.queryInterface(XWindowPeer.class, xContainerWindow);
412cdf0e10cSrcweir 
413cdf0e10cSrcweir             createWindowPeer(xWindowPeer);
414cdf0e10cSrcweir 
415cdf0e10cSrcweir             addRoadmap();
416cdf0e10cSrcweir             addRoadMapItems();
417cdf0e10cSrcweir             addStylePreview();
418cdf0e10cSrcweir             checkSteps();
419cdf0e10cSrcweir 
420cdf0e10cSrcweir             executeDialog(myFrame);
421cdf0e10cSrcweir             removeTerminateListener();
422cdf0e10cSrcweir 
423cdf0e10cSrcweir         }
424cdf0e10cSrcweir         catch (java.lang.Exception jexception)
425cdf0e10cSrcweir         {
426cdf0e10cSrcweir             jexception.printStackTrace(System.out);
427cdf0e10cSrcweir         }
428cdf0e10cSrcweir     }
429cdf0e10cSrcweir 
430cdf0e10cSrcweir     /**
431cdf0e10cSrcweir      * initializes the style preview.
432cdf0e10cSrcweir      */
addStylePreview()433cdf0e10cSrcweir     private void addStylePreview()
434cdf0e10cSrcweir     {
435cdf0e10cSrcweir         try
436cdf0e10cSrcweir         {
437cdf0e10cSrcweir             dpStylePreview = new DocumentPreview(xMSF, imgPreview);
438cdf0e10cSrcweir             stylePreview = new StylePreview(xMSF, settings.workPath);
439cdf0e10cSrcweir             stylePreview.refresh(settings.cp_DefaultSession.getStyle(), settings.cp_DefaultSession.cp_Design.cp_BackgroundImage);
440cdf0e10cSrcweir             dpStylePreview.setDocument(stylePreview.htmlFilename, DocumentPreview.PREVIEW_MODE);
441cdf0e10cSrcweir 
442cdf0e10cSrcweir         }
443cdf0e10cSrcweir         catch (Exception ex)
444cdf0e10cSrcweir         {
445cdf0e10cSrcweir             ex.printStackTrace();
446cdf0e10cSrcweir         }
447cdf0e10cSrcweir     }
448cdf0e10cSrcweir 
449cdf0e10cSrcweir     /**
450cdf0e10cSrcweir      * Loads the web wizard settings from the registry.
451cdf0e10cSrcweir      */
loadSettings(Object document)452cdf0e10cSrcweir     private void loadSettings(Object document)
453cdf0e10cSrcweir     {
454cdf0e10cSrcweir         try
455cdf0e10cSrcweir         {
456cdf0e10cSrcweir             // instanciate
457cdf0e10cSrcweir             String[] settingsResources = new String[]
458cdf0e10cSrcweir             {
459cdf0e10cSrcweir                 resources.resPages,
460cdf0e10cSrcweir                 resources.resSlides,
461cdf0e10cSrcweir                 resources.resCreatedTemplate,
462cdf0e10cSrcweir                 resources.resUpdatedTemplate,
463cdf0e10cSrcweir                 resources.resSizeTemplate
464cdf0e10cSrcweir             };
465cdf0e10cSrcweir 
466cdf0e10cSrcweir             settings = new CGSettings(xMSF, settingsResources, document);
467cdf0e10cSrcweir 
468cdf0e10cSrcweir             // get configuration view
469cdf0e10cSrcweir             Object confRoot = Configuration.getConfigurationRoot(xMSF, CONFIG_PATH, false);
470cdf0e10cSrcweir             // read
471cdf0e10cSrcweir             settings.readConfiguration(confRoot, CONFIG_READ_PARAM);
472cdf0e10cSrcweir 
473cdf0e10cSrcweir             ConfigSet set = settings.cp_DefaultSession.cp_Publishing;
474cdf0e10cSrcweir 
475*86e1cf34SPedro Giffuni             // now if path variables are used in publisher paths, they
476cdf0e10cSrcweir             // are getting replaced here...
477cdf0e10cSrcweir             for (int i = 0; i < set.getSize(); i++)
478cdf0e10cSrcweir             {
479cdf0e10cSrcweir                 CGPublish p = (CGPublish) set.getElementAt(i);
480cdf0e10cSrcweir                 p.cp_URL = substitute(p.cp_URL);
481cdf0e10cSrcweir             }
482cdf0e10cSrcweir 
483cdf0e10cSrcweir             // initialize the settings.
484cdf0e10cSrcweir             settings.configure(xMSF);
485cdf0e10cSrcweir 
486cdf0e10cSrcweir             // set resource needed for web page.
487cdf0e10cSrcweir 
488cdf0e10cSrcweir             // sort the styles alphabetically
489cdf0e10cSrcweir             settings.cp_Styles.sort(new StylesComparator());
490cdf0e10cSrcweir 
491cdf0e10cSrcweir             prepareSessionLists();
492cdf0e10cSrcweir 
493cdf0e10cSrcweir             if (proxies)
494cdf0e10cSrcweir             {
495cdf0e10cSrcweir                 __ftp = getPublisher(FTP_PUBLISHER).cp_Publish;
496cdf0e10cSrcweir                 getPublisher(FTP_PUBLISHER).cp_Publish = false;
497cdf0e10cSrcweir 
498cdf0e10cSrcweir             }
499cdf0e10cSrcweir 
500cdf0e10cSrcweir         }
501cdf0e10cSrcweir         catch (Exception ex)
502cdf0e10cSrcweir         {
503cdf0e10cSrcweir             ex.printStackTrace();
504cdf0e10cSrcweir         }
505cdf0e10cSrcweir     }
506cdf0e10cSrcweir 
prepareSessionLists()507cdf0e10cSrcweir     protected void prepareSessionLists()
508cdf0e10cSrcweir     {
509cdf0e10cSrcweir         // now copy the sessions list...
510cdf0e10cSrcweir         Object[] sessions = settings.cp_SavedSessions.items();
511cdf0e10cSrcweir         settings.savedSessions.clear();
512cdf0e10cSrcweir         for (int i = 0; i < sessions.length; i++)
513cdf0e10cSrcweir         {
514cdf0e10cSrcweir             settings.savedSessions.add(i, sessions[i]);        // add an empty session to the saved session list which apears in step 1
515cdf0e10cSrcweir         }
516cdf0e10cSrcweir         CGSessionName sn = new CGSessionName();
517cdf0e10cSrcweir         sn.cp_Name = resources.resSessionNameNone;
518cdf0e10cSrcweir         settings.cp_SavedSessions.add(0, sn);
519cdf0e10cSrcweir     }
520cdf0e10cSrcweir 
521cdf0e10cSrcweir     /**
522cdf0e10cSrcweir      * fills the saved session list, the styles list,
523cdf0e10cSrcweir      * and save session combo box.
524cdf0e10cSrcweir      * Also set the selected "load" session to the last session
525cdf0e10cSrcweir      * which was saved.
526cdf0e10cSrcweir      */
fillLists()527cdf0e10cSrcweir     private void fillLists()
528cdf0e10cSrcweir     {
529cdf0e10cSrcweir         // fill the saved session list.
530cdf0e10cSrcweir         ListModelBinder.fillList(lstLoadSettings, settings.cp_SavedSessions.items(), null);
531cdf0e10cSrcweir 
532cdf0e10cSrcweir         // set the selected session to load. (step 1)
533cdf0e10cSrcweir         selectSession();
534cdf0e10cSrcweir 
535cdf0e10cSrcweir         // fill the styles list.
536cdf0e10cSrcweir         ListModelBinder.fillList(lstStyles, settings.cp_Styles.items(), null);
537cdf0e10cSrcweir 
538cdf0e10cSrcweir         // fill the save session combobox (step 7)
539cdf0e10cSrcweir         ListModelBinder.fillComboBox(cbSaveSettings, settings.savedSessions.items(), null);
540cdf0e10cSrcweir 
541cdf0e10cSrcweir 
542cdf0e10cSrcweir     }
543cdf0e10cSrcweir 
selectSession()544cdf0e10cSrcweir     protected void selectSession()
545cdf0e10cSrcweir     {
546cdf0e10cSrcweir         int selectedSession = 0;
547cdf0e10cSrcweir         if (settings.cp_LastSavedSession != null && !settings.cp_LastSavedSession.equals(PropertyNames.EMPTY_STRING))
548cdf0e10cSrcweir         {
549cdf0e10cSrcweir 
550cdf0e10cSrcweir             Object ses = settings.cp_SavedSessions.getElement(settings.cp_LastSavedSession);
551cdf0e10cSrcweir             if (ses != null)
552cdf0e10cSrcweir             {
553cdf0e10cSrcweir                 selectedSession = settings.cp_SavedSessions.getIndexOf(ses);
554cdf0e10cSrcweir             }
555cdf0e10cSrcweir         }
556cdf0e10cSrcweir         Helper.setUnoPropertyValue(getModel(lstLoadSettings), PropertyNames.SELECTED_ITEMS, new short[]
557cdf0e10cSrcweir                 {
558cdf0e10cSrcweir                     (short) selectedSession
559cdf0e10cSrcweir                 });
560cdf0e10cSrcweir 
561cdf0e10cSrcweir     }
562cdf0e10cSrcweir 
563cdf0e10cSrcweir     public class SimpleDataawareUpdater implements XItemListener
564cdf0e10cSrcweir     {
565cdf0e10cSrcweir         /* (non-Javadoc)
566cdf0e10cSrcweir          * @see com.sun.star.lang.XEventListener#disposing(com.sun.star.lang.EventObject)
567cdf0e10cSrcweir          */
568cdf0e10cSrcweir 
disposing(EventObject arg0)569cdf0e10cSrcweir         public void disposing(EventObject arg0)
570cdf0e10cSrcweir         {
571cdf0e10cSrcweir             // TODO Auto-generated method stub
572cdf0e10cSrcweir         }
573cdf0e10cSrcweir 
itemStateChanged(com.sun.star.awt.ItemEvent itemEvent)574cdf0e10cSrcweir         public void itemStateChanged(com.sun.star.awt.ItemEvent itemEvent)
575cdf0e10cSrcweir         {
576cdf0e10cSrcweir             sda.updateData();
577cdf0e10cSrcweir         //TODO xf uncomment
578cdf0e10cSrcweir         //refresh.eventPerformed(ie);
579cdf0e10cSrcweir         }
580cdf0e10cSrcweir     }
581cdf0e10cSrcweir 
582cdf0e10cSrcweir     /**
583cdf0e10cSrcweir      * attaches to each ui-data-control (like checkbox, groupbox or
584cdf0e10cSrcweir      * textbox, no buttons though), a DataObject's JavaBean Property,
585cdf0e10cSrcweir      * or class member.
586cdf0e10cSrcweir      */
makeDataAware()587cdf0e10cSrcweir     private void makeDataAware()
588cdf0e10cSrcweir     {
589cdf0e10cSrcweir         //page 1
590cdf0e10cSrcweir         new ListModelBinder(lstLoadSettings, settings.cp_SavedSessions);
591cdf0e10cSrcweir 
592cdf0e10cSrcweir         //page 2 : document properties
593cdf0e10cSrcweir 
594cdf0e10cSrcweir         docListDA = UnoDataAware.attachListBox(this, "SelectedDoc", lstDocuments, null, false);
595cdf0e10cSrcweir         docListDA.disableControls(new Object[]
596cdf0e10cSrcweir                 {
597cdf0e10cSrcweir                     /*btnDocDown, btnDocUp, */
598cdf0e10cSrcweir                     lnDocsInfo, btnRemoveDoc, lblDocTitle, txtDocTitle, lblDocInfo, txtDocInfo, lblDocAuthor, txtDocAuthor, lblDocExportFormat, lstDocTargetType
599cdf0e10cSrcweir                 });
600cdf0e10cSrcweir         docListDA.updateUI();
601cdf0e10cSrcweir 
602cdf0e10cSrcweir         CGDocument doc = new CGDocument(); //dummy
603cdf0e10cSrcweir 
604cdf0e10cSrcweir         docsBinder = new ListModelBinder(lstDocuments, settings.cp_DefaultSession.cp_Content.cp_Documents);
605cdf0e10cSrcweir 
606cdf0e10cSrcweir         docAware.add(UnoDataAware.attachEditControl(doc, "cp_Title", txtDocTitle, refresh, true));
607cdf0e10cSrcweir         docAware.add(UnoDataAware.attachEditControl(doc, "cp_Description", txtDocInfo, refresh, true));
608cdf0e10cSrcweir         docAware.add(UnoDataAware.attachEditControl(doc, "cp_Author", txtDocAuthor, refresh, true));
609cdf0e10cSrcweir         docAware.add(UnoDataAware.attachListBox(doc, "Exporter", lstDocTargetType, refresh, false));
610cdf0e10cSrcweir 
611cdf0e10cSrcweir         //page 3 : Layout
612cdf0e10cSrcweir         Object design = settings.cp_DefaultSession.cp_Design;
613cdf0e10cSrcweir         sda = new SimpleDataAware(design, new DataAware.PropertyValue("Layout", design), ilLayouts, new DataAware.PropertyValue("Selected", ilLayouts));
614cdf0e10cSrcweir         ilLayouts.addItemListener(new SimpleDataawareUpdater());
615cdf0e10cSrcweir         designAware.add(sda);
616cdf0e10cSrcweir 
617cdf0e10cSrcweir         //page 4 : layout 2
618cdf0e10cSrcweir         designAware.add(UnoDataAware.attachCheckBox(design, "cp_DisplayDescription", chbDocDesc, refresh, true));
619cdf0e10cSrcweir         designAware.add(UnoDataAware.attachCheckBox(design, "cp_DisplayAuthor", chbDocAuthor, refresh, true));
620cdf0e10cSrcweir         designAware.add(UnoDataAware.attachCheckBox(design, "cp_DisplayCreateDate", chkDocCreated, refresh, true));
621cdf0e10cSrcweir         designAware.add(UnoDataAware.attachCheckBox(design, "cp_DisplayUpdateDate", chkDocChanged, refresh, true));
622cdf0e10cSrcweir         designAware.add(UnoDataAware.attachCheckBox(design, "cp_DisplayFilename", chkDocFilename, refresh, true));
623cdf0e10cSrcweir         designAware.add(UnoDataAware.attachCheckBox(design, "cp_DisplayFileFormat", chkDocFormat, refresh, true));
624cdf0e10cSrcweir         designAware.add(UnoDataAware.attachCheckBox(design, "cp_DisplayFormatIcon", chkDocFormatIcon, refresh, true));
625cdf0e10cSrcweir         designAware.add(UnoDataAware.attachCheckBox(design, "cp_DisplayPages", chkDocPages, refresh, true));
626cdf0e10cSrcweir         designAware.add(UnoDataAware.attachCheckBox(design, "cp_DisplaySize", chkDocSize, refresh, true));
627cdf0e10cSrcweir         designAware.add(RadioDataAware.attachRadioButtons(settings.cp_DefaultSession.cp_Design, "cp_OptimizeDisplaySize", new Object[]
628cdf0e10cSrcweir                 {
629cdf0e10cSrcweir                     optOptimize640x480, optOptimize800x600, optOptimize1024x768
630cdf0e10cSrcweir                 }, refresh, true));
631cdf0e10cSrcweir 
632cdf0e10cSrcweir 
633cdf0e10cSrcweir         //page 5 : Style
634cdf0e10cSrcweir         /*
635cdf0e10cSrcweir          * note : on style change, i do not call here refresh ,but rather on
636cdf0e10cSrcweir          * a special method which will perform some display, background and Iconsets changes.
637cdf0e10cSrcweir          */
638cdf0e10cSrcweir         designAware.add(UnoDataAware.attachListBox(settings.cp_DefaultSession.cp_Design, "Style", lstStyles, null, false));
639cdf0e10cSrcweir 
640cdf0e10cSrcweir         //page 6 : site general props
641cdf0e10cSrcweir         genAware.add(UnoDataAware.attachEditControl(settings.cp_DefaultSession.cp_GeneralInfo, "cp_Title", txtSiteTitle, refresh, true));
642cdf0e10cSrcweir         genAware.add(UnoDataAware.attachEditControl(settings.cp_DefaultSession.cp_GeneralInfo, "cp_Description", txtSiteDesc, refresh, true));
643cdf0e10cSrcweir 
644cdf0e10cSrcweir         genAware.add(UnoDataAware.attachDateControl(settings.cp_DefaultSession.cp_GeneralInfo, "CreationDate", dateSiteCreated, refresh, false));
645cdf0e10cSrcweir         genAware.add(UnoDataAware.attachDateControl(settings.cp_DefaultSession.cp_GeneralInfo, "UpdateDate", dateSiteUpdate, refresh, false));
646cdf0e10cSrcweir         genAware.add(UnoDataAware.attachEditControl(settings.cp_DefaultSession.cp_GeneralInfo, "cp_Email", txtEmail, refresh, true));
647cdf0e10cSrcweir         genAware.add(UnoDataAware.attachEditControl(settings.cp_DefaultSession.cp_GeneralInfo, "cp_Copyright", txtCopyright, refresh, true));
648cdf0e10cSrcweir 
649cdf0e10cSrcweir         //page 7 : publishing
650cdf0e10cSrcweir 
651cdf0e10cSrcweir         pubAware(LOCAL_PUBLISHER, chkLocalDir, txtLocalDir, false);
652cdf0e10cSrcweir         pubAware(FTP_PUBLISHER, chkFTP, lblFTP, true);
653cdf0e10cSrcweir         pubAware(ZIP_PUBLISHER, chkZip, txtZip, false);
654cdf0e10cSrcweir 
655cdf0e10cSrcweir         sessionNameDA = UnoDataAware.attachEditControl(settings.cp_DefaultSession, "cp_Name", cbSaveSettings, null, true);
656cdf0e10cSrcweir 
657cdf0e10cSrcweir     //cleanup when exiting wizard.
658cdf0e10cSrcweir     //guiEventListener.add("WebWizardDialog",EventNames.EVENT_WINDOW_HIDDEN, "cleanup", this);
659cdf0e10cSrcweir     //xWindow.addWindowListener((XWindowListener)guiEventListener);
660cdf0e10cSrcweir     }
661cdf0e10cSrcweir 
662cdf0e10cSrcweir     /**
663cdf0e10cSrcweir      * A help method to attach a Checkbox and a TextBox to
664cdf0e10cSrcweir      * a CGPublish object properties/class members,
665cdf0e10cSrcweir      * @param publish
666cdf0e10cSrcweir      * @param checkbox
667cdf0e10cSrcweir      * @param textbox
668cdf0e10cSrcweir      */
pubAware(String publish, Object checkbox, Object textbox, boolean isLabel)669cdf0e10cSrcweir     private void pubAware(String publish, Object checkbox, Object textbox, boolean isLabel)
670cdf0e10cSrcweir     {
671cdf0e10cSrcweir         Object p = settings.cp_DefaultSession.cp_Publishing.getElement(publish);
672cdf0e10cSrcweir         UnoDataAware uda = UnoDataAware.attachCheckBox(p, "cp_Publish", checkbox, checkPublish, true);
673cdf0e10cSrcweir         uda.setInverse(true);
674cdf0e10cSrcweir 
675cdf0e10cSrcweir         uda.disableControls(new Object[]
676cdf0e10cSrcweir                 {
677cdf0e10cSrcweir                     textbox
678cdf0e10cSrcweir                 });
679cdf0e10cSrcweir         pubAware.add(uda);
680cdf0e10cSrcweir         pubAware.add(
681cdf0e10cSrcweir                 isLabel ? UnoDataAware.attachLabel(p, PropertyNames.URL, textbox, checkPublish, false)
682cdf0e10cSrcweir                 : UnoDataAware.attachEditControl(p, PropertyNames.URL, textbox, checkPublish, false));
683cdf0e10cSrcweir 
684cdf0e10cSrcweir     }
685cdf0e10cSrcweir 
686cdf0e10cSrcweir     /*
687cdf0e10cSrcweir      * Session load methods
688cdf0e10cSrcweir      * (are used both on the start of the wizard and
689cdf0e10cSrcweir      * when the user loads a session)
690cdf0e10cSrcweir      */
691cdf0e10cSrcweir     /**
692cdf0e10cSrcweir      * Is called when a new session/settings is
693cdf0e10cSrcweir      * loaded. <br/>
694cdf0e10cSrcweir      * Checks the documents (validate), fills the
695cdf0e10cSrcweir      * documents listbox, and changes the
696cdf0e10cSrcweir      * DataAware data objects to the
697cdf0e10cSrcweir      * new session's objects.<br/>
698cdf0e10cSrcweir      * Task advances 4 times in the mount method,
699cdf0e10cSrcweir      * and ??? times for each document in the session.
700cdf0e10cSrcweir      *
701cdf0e10cSrcweir      */
mount(CGSession session, Task task, boolean refreshStyle, XControl xC)702cdf0e10cSrcweir     protected void mount(CGSession session, Task task, boolean refreshStyle, XControl xC)
703cdf0e10cSrcweir     {
704cdf0e10cSrcweir         /* This checks the documents. If the user
705cdf0e10cSrcweir          * chooses to cancel, the session is not loaded.
706cdf0e10cSrcweir          */
707cdf0e10cSrcweir         checkContent(session.cp_Content, task, xC);
708cdf0e10cSrcweir 
709cdf0e10cSrcweir         settings.cp_DefaultSession = session;
710cdf0e10cSrcweir 
711cdf0e10cSrcweir         mount(session.cp_Content);
712cdf0e10cSrcweir 
713cdf0e10cSrcweir         task.advance(true);
714cdf0e10cSrcweir 
715cdf0e10cSrcweir         mount(session.cp_Design, designAware);
716cdf0e10cSrcweir         mount(session.cp_GeneralInfo, genAware);
717cdf0e10cSrcweir 
718cdf0e10cSrcweir         task.advance(true);
719cdf0e10cSrcweir 
720cdf0e10cSrcweir         mount(session.cp_Publishing.getElement(LOCAL_PUBLISHER), 0);
721cdf0e10cSrcweir         mount(session.cp_Publishing.getElement(FTP_PUBLISHER), 1);
722cdf0e10cSrcweir         mount(session.cp_Publishing.getElement(ZIP_PUBLISHER), 2);
723cdf0e10cSrcweir 
724cdf0e10cSrcweir         task.advance(true);
725cdf0e10cSrcweir 
726cdf0e10cSrcweir         sessionNameDA.setDataObject(session, true);
727cdf0e10cSrcweir         Helper.setUnoPropertyValue(getModel(chkSaveSettings), PropertyNames.PROPERTY_STATE, new Short((short) 1));
728cdf0e10cSrcweir         docListDA.updateUI();
729cdf0e10cSrcweir 
730cdf0e10cSrcweir         task.advance(true);
731cdf0e10cSrcweir 
732cdf0e10cSrcweir         if (refreshStyle)
733cdf0e10cSrcweir         {
734cdf0e10cSrcweir             refreshStylePreview();
735cdf0e10cSrcweir             updateIconsetText();
736cdf0e10cSrcweir         }
737cdf0e10cSrcweir 
738cdf0e10cSrcweir     //updateUI();
739cdf0e10cSrcweir     }
740cdf0e10cSrcweir 
741cdf0e10cSrcweir     /**
742cdf0e10cSrcweir      * used to mount the publishing objects. This is somehow cryptic -
743cdf0e10cSrcweir      * there are 6 DataAware objects, 2 for each Publishing Object (CGPublish).
744cdf0e10cSrcweir      * All 6 reside on one Vector (pubAware).
745cdf0e10cSrcweir      * Since, otherwise than other DataAware objects, different
746cdf0e10cSrcweir      * Objects on the same Vector need different DataObjectBinding,
747cdf0e10cSrcweir      * I use this method...
748cdf0e10cSrcweir      * @param data the CGPublish object
749cdf0e10cSrcweir      * @param i the number of the object (0 = local, 1 = ftp, 2 = zip)
750cdf0e10cSrcweir      */
mount(Object data, int i)751cdf0e10cSrcweir     private void mount(Object data, int i)
752cdf0e10cSrcweir     {
753cdf0e10cSrcweir         ((DataAware) pubAware.get(i * 2)).setDataObject(data, true);
754cdf0e10cSrcweir         ((DataAware) pubAware.get(i * 2 + 1)).setDataObject(data, true);
755cdf0e10cSrcweir     }
756cdf0e10cSrcweir 
757cdf0e10cSrcweir     /**
758cdf0e10cSrcweir      * Fills the documents listbox.
759cdf0e10cSrcweir      * @param root the CGContent object
760cdf0e10cSrcweir      * that contains the documents (a ListModel)
761cdf0e10cSrcweir      */
mount(CGContent root)762cdf0e10cSrcweir     private void mount(CGContent root)
763cdf0e10cSrcweir     {
764cdf0e10cSrcweir         ListModelBinder.fillList(lstDocuments, root.cp_Documents.items(), null);
765cdf0e10cSrcweir         docsBinder.setListModel(root.cp_Documents);
766cdf0e10cSrcweir         disableDocUpDown();
767cdf0e10cSrcweir 
768cdf0e10cSrcweir     }
769cdf0e10cSrcweir 
770cdf0e10cSrcweir     /**
771cdf0e10cSrcweir      * changes the DataAwares Objects' (in
772cdf0e10cSrcweir      * the gioen list) DataObject to the
773cdf0e10cSrcweir      * @param data
774cdf0e10cSrcweir      * @param list
775cdf0e10cSrcweir      */
mount(Object data, List list)776cdf0e10cSrcweir     protected void mount(Object data, List list)
777cdf0e10cSrcweir     {
778cdf0e10cSrcweir         for (int i = 0; i < list.size(); i++)
779cdf0e10cSrcweir         {
780cdf0e10cSrcweir             ((DataAware) list.get(i)).setDataObject(data, true);
781cdf0e10cSrcweir         }
782cdf0e10cSrcweir     }
783cdf0e10cSrcweir 
784cdf0e10cSrcweir     /**
785cdf0e10cSrcweir      * Checks if the document specified by the given CGDocument
786cdf0e10cSrcweir      * object (cp_URL) exists. Calls also the validate(...) method
787cdf0e10cSrcweir      * of this document.
788cdf0e10cSrcweir      * If the document does not exist, it asks the user whether
789cdf0e10cSrcweir      * to specify a new URL, or forget about this document.
790cdf0e10cSrcweir      * @param doc the document to check.
791cdf0e10cSrcweir      * @param task while loading a session, a status is
792cdf0e10cSrcweir      * displayed, using the Task object to monitor progress.
793cdf0e10cSrcweir      * @return true if the document is ok (a file exists in the given url).
794cdf0e10cSrcweir      */
checkDocument(CGDocument doc, Task task, XControl xC)795cdf0e10cSrcweir     protected boolean checkDocument(CGDocument doc, Task task, XControl xC)
796cdf0e10cSrcweir     {
797cdf0e10cSrcweir         try
798cdf0e10cSrcweir         {
799cdf0e10cSrcweir             doc.validate(xMSF, task);
800cdf0e10cSrcweir             return true;
801cdf0e10cSrcweir         }
802cdf0e10cSrcweir         catch (FileNotFoundException ex)
803cdf0e10cSrcweir         {
804cdf0e10cSrcweir 
805cdf0e10cSrcweir             int relocate = SystemDialog.showMessageBox(xMSF, xC.getPeer(), "WarningBox", VclWindowPeerAttribute.YES_NO + VclWindowPeerAttribute.DEF_NO, getFileAccess().getPath(doc.cp_URL, PropertyNames.EMPTY_STRING) + "\n\n" + resources.resSpecifyNewFileLocation);
806cdf0e10cSrcweir 
807cdf0e10cSrcweir             if (relocate == 2)
808cdf0e10cSrcweir             {
809cdf0e10cSrcweir                 String[] file = getDocAddDialog().callOpenDialog(false, FileAccess.getParentDir(doc.cp_URL));
810cdf0e10cSrcweir                 if (file == null)
811cdf0e10cSrcweir                 {
812cdf0e10cSrcweir                     return false;
813cdf0e10cSrcweir                 }
814cdf0e10cSrcweir                 else
815cdf0e10cSrcweir                 {
816cdf0e10cSrcweir                     doc.cp_URL = file[0];
817cdf0e10cSrcweir                     return checkDocument(doc, task, xC);
818cdf0e10cSrcweir                 }
819cdf0e10cSrcweir             }
820cdf0e10cSrcweir             else
821cdf0e10cSrcweir             {
822cdf0e10cSrcweir                 return false;
823cdf0e10cSrcweir             }
824cdf0e10cSrcweir         }
825cdf0e10cSrcweir         catch (IllegalArgumentException iaex)
826cdf0e10cSrcweir         {
827cdf0e10cSrcweir             //file is a directory
828cdf0e10cSrcweir             AbstractErrorHandler.showMessage(xMSF, xControl.getPeer(),
829cdf0e10cSrcweir                     JavaTools.replaceSubString(resources.resErrIsDirectory,
830cdf0e10cSrcweir                     getFileAccess().getPath(doc.cp_URL, PropertyNames.EMPTY_STRING),
831cdf0e10cSrcweir                     "%FILENAME"),
832cdf0e10cSrcweir                     ErrorHandler.ERROR_PROCESS_FATAL);
833cdf0e10cSrcweir             return false;
834cdf0e10cSrcweir         }
835cdf0e10cSrcweir         catch (Exception exp)
836cdf0e10cSrcweir         {
837cdf0e10cSrcweir             //something went wrong.
838cdf0e10cSrcweir             exp.printStackTrace();
839cdf0e10cSrcweir             AbstractErrorHandler.showMessage(xMSF, xControl.getPeer(),
840cdf0e10cSrcweir                     JavaTools.replaceSubString(resources.resErrDocValidate,
841cdf0e10cSrcweir                     getFileAccess().getPath(doc.cp_URL, PropertyNames.EMPTY_STRING),
842cdf0e10cSrcweir                     "%FILENAME"), ErrorHandler.ERROR_PROCESS_FATAL);
843cdf0e10cSrcweir             return false;
844cdf0e10cSrcweir         }
845cdf0e10cSrcweir 
846cdf0e10cSrcweir     }
847cdf0e10cSrcweir 
848cdf0e10cSrcweir     /**
849cdf0e10cSrcweir      * Checks the documents contained in this content.
850cdf0e10cSrcweir      * @param content
851cdf0e10cSrcweir      * @param task
852cdf0e10cSrcweir      */
checkContent(CGContent content, Task task, XControl xC)853cdf0e10cSrcweir     private void checkContent(CGContent content, Task task, XControl xC)
854cdf0e10cSrcweir     {
855cdf0e10cSrcweir         for (int i = 0; i < content.cp_Documents.getSize(); i++)
856cdf0e10cSrcweir         {
857cdf0e10cSrcweir             if (!checkDocument((CGDocument) content.cp_Documents.getElementAt(i), task, xC))
858cdf0e10cSrcweir             // I use here 'i--' since, when the document is removed
859cdf0e10cSrcweir             // an index change accures
860cdf0e10cSrcweir             {
861cdf0e10cSrcweir                 content.cp_Documents.remove(i--);
862cdf0e10cSrcweir             /*for (Iterator i = content.cp_Contents.childrenMap.values().iterator(); i.hasNext();)
863cdf0e10cSrcweir             checkContent((CGContent)i.next(),task);*/
864cdf0e10cSrcweir             }
865cdf0e10cSrcweir         }
866cdf0e10cSrcweir     }
867cdf0e10cSrcweir 
868cdf0e10cSrcweir     /**
869cdf0e10cSrcweir      * A Listener which is called whenever
870cdf0e10cSrcweir      * a Publish checkbox/textbox state changes, and
871cdf0e10cSrcweir      * changes the "create" button enable state accordingly.
872cdf0e10cSrcweir      * @author rpiterman
873cdf0e10cSrcweir      */
874cdf0e10cSrcweir     private class CheckPublish implements DataAware.Listener
875cdf0e10cSrcweir     {
876cdf0e10cSrcweir 
eventPerformed(Object event)877cdf0e10cSrcweir         public void eventPerformed(Object event)
878cdf0e10cSrcweir         {
879cdf0e10cSrcweir             checkPublish();
880cdf0e10cSrcweir         }
881cdf0e10cSrcweir     }
882cdf0e10cSrcweir 
883cdf0e10cSrcweir     /**
884cdf0e10cSrcweir      * Disables/enables the docUpDown buttons (step 2)
885cdf0e10cSrcweir      * according to the currently selected document
886cdf0e10cSrcweir      * (no doc selected - both disbaled, last doc selected,
887cdf0e10cSrcweir      * down disabled and so on...)
888cdf0e10cSrcweir      *
889cdf0e10cSrcweir      */
disableDocUpDown()890cdf0e10cSrcweir     protected void disableDocUpDown()
891cdf0e10cSrcweir     {
892cdf0e10cSrcweir         try
893cdf0e10cSrcweir         {
894cdf0e10cSrcweir             setEnabled(btnDocUp, selectedDoc.length == 0 ? Boolean.FALSE : (selectedDoc[0] == 0 ? Boolean.FALSE : Boolean.TRUE));
895cdf0e10cSrcweir             setEnabled(btnDocDown, selectedDoc.length == 0 ? Boolean.FALSE : (selectedDoc[0] + 1 < settings.cp_DefaultSession.cp_Content.cp_Documents.getSize() ? Boolean.TRUE : Boolean.FALSE));
896cdf0e10cSrcweir         }
897cdf0e10cSrcweir         catch (Exception e)
898cdf0e10cSrcweir         {
899cdf0e10cSrcweir             e.printStackTrace();
900cdf0e10cSrcweir         }
901cdf0e10cSrcweir     }
902cdf0e10cSrcweir 
updateBackgroundText()903cdf0e10cSrcweir     void updateBackgroundText()
904cdf0e10cSrcweir     {
905cdf0e10cSrcweir         String bg = settings.cp_DefaultSession.cp_Design.cp_BackgroundImage;
906cdf0e10cSrcweir         if (bg == null || bg.equals(PropertyNames.EMPTY_STRING))
907cdf0e10cSrcweir         {
908cdf0e10cSrcweir             bg = resources.resBackgroundNone;
909cdf0e10cSrcweir         }
910cdf0e10cSrcweir         else
911cdf0e10cSrcweir         {
912cdf0e10cSrcweir             bg = FileAccess.getPathFilename(getFileAccess().getPath(bg, null));
913cdf0e10cSrcweir         }
914cdf0e10cSrcweir         Helper.setUnoPropertyValue(getModel(txtBackground), PropertyNames.PROPERTY_LABEL, bg);
915cdf0e10cSrcweir     }
916cdf0e10cSrcweir 
updateIconsetText()917cdf0e10cSrcweir     void updateIconsetText()
918cdf0e10cSrcweir     {
919cdf0e10cSrcweir         String iconset = settings.cp_DefaultSession.cp_Design.cp_IconSet;
920cdf0e10cSrcweir         String iconsetName;
921cdf0e10cSrcweir         if (iconset == null || iconset.equals(PropertyNames.EMPTY_STRING))
922cdf0e10cSrcweir         {
923cdf0e10cSrcweir             iconsetName = resources.resIconsetNone;
924cdf0e10cSrcweir         }
925cdf0e10cSrcweir         else
926cdf0e10cSrcweir         {
927cdf0e10cSrcweir             CGIconSet is = (CGIconSet) settings.cp_IconSets.getElement(iconset);
928cdf0e10cSrcweir             if (is == null)
929cdf0e10cSrcweir             {
930cdf0e10cSrcweir                 iconsetName = resources.resIconsetNone;
931cdf0e10cSrcweir             }
932cdf0e10cSrcweir             else
933cdf0e10cSrcweir             {
934cdf0e10cSrcweir                 iconsetName = is.cp_Name;
935cdf0e10cSrcweir             }
936cdf0e10cSrcweir         }
937cdf0e10cSrcweir 
938cdf0e10cSrcweir         Helper.setUnoPropertyValue(getModel(txtIconset), PropertyNames.PROPERTY_LABEL, iconsetName);
939cdf0e10cSrcweir     }
940cdf0e10cSrcweir 
941cdf0e10cSrcweir     /**
942cdf0e10cSrcweir      * refreshes the style preview.
943cdf0e10cSrcweir      * I also call here "updateBackgroundtext", because always
944cdf0e10cSrcweir      * when the background is changed, this method
945cdf0e10cSrcweir      * has to be called, so I am walking on the safe side here...
946cdf0e10cSrcweir      */
refreshStylePreview()947cdf0e10cSrcweir     public void refreshStylePreview()
948cdf0e10cSrcweir     {
949cdf0e10cSrcweir         try
950cdf0e10cSrcweir         {
951cdf0e10cSrcweir             updateBackgroundText();
952cdf0e10cSrcweir             stylePreview.refresh(settings.cp_DefaultSession.getStyle(), settings.cp_DefaultSession.cp_Design.cp_BackgroundImage);
953cdf0e10cSrcweir             dpStylePreview.reload(xMSF);
954cdf0e10cSrcweir         }
955cdf0e10cSrcweir         catch (Exception ex)
956cdf0e10cSrcweir         {
957cdf0e10cSrcweir             ex.printStackTrace();
958cdf0e10cSrcweir         }
959cdf0e10cSrcweir     }
960cdf0e10cSrcweir 
961cdf0e10cSrcweir     private class StylesComparator implements Comparator
962cdf0e10cSrcweir     {
963cdf0e10cSrcweir 
964cdf0e10cSrcweir         /* (non-Javadoc)
965cdf0e10cSrcweir          * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
966cdf0e10cSrcweir          */
compare(Object o1, Object o2)967cdf0e10cSrcweir         public int compare(Object o1, Object o2)
968cdf0e10cSrcweir         {
969cdf0e10cSrcweir             // TODO Auto-generated method stub
970cdf0e10cSrcweir             if (o1 instanceof CGStyle && o2 instanceof CGStyle)
971cdf0e10cSrcweir             {
972cdf0e10cSrcweir                 return ((CGStyle) o1).cp_Name.compareTo(
973cdf0e10cSrcweir                         ((CGStyle) o2).cp_Name);
974cdf0e10cSrcweir             }
975cdf0e10cSrcweir             else
976cdf0e10cSrcweir             {
977cdf0e10cSrcweir                 throw new IllegalArgumentException("Cannot compare objects which are not CGStyle.");
978cdf0e10cSrcweir             }
979cdf0e10cSrcweir         }
980cdf0e10cSrcweir     }
981cdf0e10cSrcweir }
982