1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir package complex.loadAllDocuments;
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir // __________ Imports __________
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir // structs, const, ...
32*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir // exceptions
35*cdf0e10cSrcweir import com.sun.star.uno.Exception;
36*cdf0e10cSrcweir import com.sun.star.uno.RuntimeException;
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir // interfaces
39*cdf0e10cSrcweir import com.sun.star.task.XStatusIndicator;
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir // helper
42*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir // others
45*cdf0e10cSrcweir //import java.lang.*;
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir // __________ Implementation __________
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir /**
50*cdf0e10cSrcweir  * Implemets a simple status indicator, which
51*cdf0e10cSrcweir  * provide informations about state of a load request.
52*cdf0e10cSrcweir  * It can be used as an argument e.g. for loadComponentFromURL().
53*cdf0e10cSrcweir  */
54*cdf0e10cSrcweir public class StatusIndicator implements com.sun.star.task.XStatusIndicator
55*cdf0e10cSrcweir {
56*cdf0e10cSrcweir     // ____________________
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir     /**
59*cdf0e10cSrcweir      * @const SHOWSTATUS_NO         don't show the status - but save information about using of this indicator object
60*cdf0e10cSrcweir      * @const SHOWSTATUS_LOG        the possible set protocol object will be used (it covers STDOUT, STDERR automaticly too)
61*cdf0e10cSrcweir      * @const SHOWSTATUS_DIALOG     the status will be shown inside a java dialog
62*cdf0e10cSrcweir      * @const SHOWSTATUS_LINK       the status will be notified to interested listener (one listener only!)
63*cdf0e10cSrcweir      */
64*cdf0e10cSrcweir     public static final int SHOWSTATUS_NO       =   0;
65*cdf0e10cSrcweir     public static final int SHOWSTATUS_LOG      =   1;
66*cdf0e10cSrcweir     public static final int SHOWSTATUS_DIALOG   =   4;
67*cdf0e10cSrcweir     public static final int SHOWSTATUS_LINK     =   8;
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir     // ____________________
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir     /**
72*cdf0e10cSrcweir      * @member m_sText      text, which describe the current status
73*cdf0e10cSrcweir      * @member m_nRange     max value for any progress
74*cdf0e10cSrcweir      * @member m_nValue     the progress value
75*cdf0e10cSrcweir      * @member m_nOut       regulate, how the status will be shown
76*cdf0e10cSrcweir      * @member m_aProtocol  used for logging and transport information about used interface of this object
77*cdf0e10cSrcweir      */
78*cdf0e10cSrcweir     private String          m_sText     ;
79*cdf0e10cSrcweir     private int             m_nRange    ;
80*cdf0e10cSrcweir     private int             m_nValue    ;
81*cdf0e10cSrcweir     private int             m_nOut      ;
82*cdf0e10cSrcweir //    private Protocol        m_aProtocol ;
83*cdf0e10cSrcweir     private boolean         m_bWasUsed  ;
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir     // ____________________
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir     /**
88*cdf0e10cSrcweir      * ctor
89*cdf0e10cSrcweir      * It's initialize an object of this class with default values.
90*cdf0e10cSrcweir      */
91*cdf0e10cSrcweir     public StatusIndicator( int nOut)
92*cdf0e10cSrcweir     {
93*cdf0e10cSrcweir         m_sText     = new String()  ;
94*cdf0e10cSrcweir         m_nRange    = 100           ;
95*cdf0e10cSrcweir         m_nValue    = 0             ;
96*cdf0e10cSrcweir         m_nOut      = nOut          ;
97*cdf0e10cSrcweir         //m_aProtocol = aProtocol     ;
98*cdf0e10cSrcweir         m_bWasUsed  = false;
99*cdf0e10cSrcweir //        aProtocol.resetUsingState();
100*cdf0e10cSrcweir     }
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir     // ____________________
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir     /**
105*cdf0e10cSrcweir      * It starts the progress and set the initial text and range.
106*cdf0e10cSrcweir      *
107*cdf0e10cSrcweir      * @param sText
108*cdf0e10cSrcweir      *          the initial text for showing
109*cdf0e10cSrcweir      *
110*cdf0e10cSrcweir      * @param nRange
111*cdf0e10cSrcweir      *          the new range for following progress
112*cdf0e10cSrcweir      */
113*cdf0e10cSrcweir     public void start( /*IN*/String sText, /*IN*/int nRange )
114*cdf0e10cSrcweir     {
115*cdf0e10cSrcweir         synchronized(this)
116*cdf0e10cSrcweir         {
117*cdf0e10cSrcweir             //m_aProtocol.log("start("+sText+","+nRange+")\n");
118*cdf0e10cSrcweir             m_bWasUsed = true;
119*cdf0e10cSrcweir //            m_aProtocol.itWasUsed();
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir             m_sText  = sText ;
122*cdf0e10cSrcweir             m_nRange = nRange;
123*cdf0e10cSrcweir             m_nValue = 0     ;
124*cdf0e10cSrcweir         }
125*cdf0e10cSrcweir         impl_show();
126*cdf0e10cSrcweir     }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir     // ____________________
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir     /**
131*cdf0e10cSrcweir      * Finish the progress and reset internal members.
132*cdf0e10cSrcweir      */
133*cdf0e10cSrcweir     public void end()
134*cdf0e10cSrcweir     {
135*cdf0e10cSrcweir         synchronized(this)
136*cdf0e10cSrcweir         {
137*cdf0e10cSrcweir             //m_aProtocol.log("end()\n");
138*cdf0e10cSrcweir             m_bWasUsed = true;
139*cdf0e10cSrcweir //            m_aProtocol.itWasUsed();
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir             m_sText  = new String();
142*cdf0e10cSrcweir             m_nRange = 100;
143*cdf0e10cSrcweir             m_nValue = 0;
144*cdf0e10cSrcweir         }
145*cdf0e10cSrcweir         impl_show();
146*cdf0e10cSrcweir     }
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir     // ____________________
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir     /**
151*cdf0e10cSrcweir      * Set the new description text.
152*cdf0e10cSrcweir      *
153*cdf0e10cSrcweir      * @param sText
154*cdf0e10cSrcweir      *          the new text for showing
155*cdf0e10cSrcweir      */
156*cdf0e10cSrcweir     public void setText( /*IN*/String sText )
157*cdf0e10cSrcweir     {
158*cdf0e10cSrcweir         synchronized(this)
159*cdf0e10cSrcweir         {
160*cdf0e10cSrcweir             //m_aProtocol.log("setText("+sText+")\n");
161*cdf0e10cSrcweir             m_bWasUsed = true;
162*cdf0e10cSrcweir //            m_aProtocol.itWasUsed();
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir             m_sText = sText;
165*cdf0e10cSrcweir         }
166*cdf0e10cSrcweir         impl_show();
167*cdf0e10cSrcweir     }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir     // ____________________
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir     /**
172*cdf0e10cSrcweir      * Set the new progress value.
173*cdf0e10cSrcweir      *
174*cdf0e10cSrcweir      * @param nValue
175*cdf0e10cSrcweir      *          the new progress value
176*cdf0e10cSrcweir      *          Must fit the range!
177*cdf0e10cSrcweir      */
178*cdf0e10cSrcweir     public void setValue( /*IN*/int nValue )
179*cdf0e10cSrcweir     {
180*cdf0e10cSrcweir         synchronized(this)
181*cdf0e10cSrcweir         {
182*cdf0e10cSrcweir             //m_aProtocol.log("setValue("+nValue+")\n");
183*cdf0e10cSrcweir             m_bWasUsed = true;
184*cdf0e10cSrcweir //            m_aProtocol.itWasUsed();
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir             if (nValue<=m_nRange)
187*cdf0e10cSrcweir                 m_nValue = nValue;
188*cdf0e10cSrcweir         }
189*cdf0e10cSrcweir         impl_show();
190*cdf0e10cSrcweir     }
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir     // ____________________
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir     /**
195*cdf0e10cSrcweir      * Reset text and progress value to her defaults.
196*cdf0e10cSrcweir      */
197*cdf0e10cSrcweir     public void reset()
198*cdf0e10cSrcweir     {
199*cdf0e10cSrcweir         synchronized(this)
200*cdf0e10cSrcweir         {
201*cdf0e10cSrcweir             //m_aProtocol.log("reset()\n");
202*cdf0e10cSrcweir             m_bWasUsed = true;
203*cdf0e10cSrcweir //            m_aProtocol.itWasUsed();
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir             m_sText  = new String();
206*cdf0e10cSrcweir             m_nValue = 0;
207*cdf0e10cSrcweir         }
208*cdf0e10cSrcweir         impl_show();
209*cdf0e10cSrcweir     }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir     // ____________________
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir     /**
214*cdf0e10cSrcweir      * Internal helper to show the status.
215*cdf0e10cSrcweir      * Currently it's implement as normal text out on stdout.
216*cdf0e10cSrcweir      * But of course other thimngs are possible here too.
217*cdf0e10cSrcweir      * e.g. a dialog
218*cdf0e10cSrcweir      */
219*cdf0e10cSrcweir     private void impl_show()
220*cdf0e10cSrcweir     {
221*cdf0e10cSrcweir /*        synchronized(this)
222*cdf0e10cSrcweir         {
223*cdf0e10cSrcweir             if ((m_nOut & SHOWSTATUS_LOG) == SHOWSTATUS_LOG)
224*cdf0e10cSrcweir                 //m_aProtocol.log("\t["+m_nValue+"/"+m_nRange+"] "+m_sText+"\n");
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir             //if ((m_nOut & SHOWSTATUS_DIALOG) == SHOWSTATUS_DIALOG)
227*cdf0e10cSrcweir                 // not supported yet!
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir             //if ((m_nOut & SHOWSTATUS_LINK) == SHOWSTATUS_LINK)
230*cdf0e10cSrcweir                 // not supported yet!
231*cdf0e10cSrcweir         } */
232*cdf0e10cSrcweir     }
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir     public boolean wasUsed() {
235*cdf0e10cSrcweir         return m_bWasUsed;
236*cdf0e10cSrcweir     }
237*cdf0e10cSrcweir }
238