176b6b121SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 376b6b121SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 476b6b121SAndrew Rist * or more contributor license agreements. See the NOTICE file 576b6b121SAndrew Rist * distributed with this work for additional information 676b6b121SAndrew Rist * regarding copyright ownership. The ASF licenses this file 776b6b121SAndrew Rist * to you under the Apache License, Version 2.0 (the 876b6b121SAndrew Rist * "License"); you may not use this file except in compliance 976b6b121SAndrew Rist * with the License. You may obtain a copy of the License at 1076b6b121SAndrew Rist * 1176b6b121SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 1276b6b121SAndrew Rist * 1376b6b121SAndrew Rist * Unless required by applicable law or agreed to in writing, 1476b6b121SAndrew Rist * software distributed under the License is distributed on an 1576b6b121SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1676b6b121SAndrew Rist * KIND, either express or implied. See the License for the 1776b6b121SAndrew Rist * specific language governing permissions and limitations 1876b6b121SAndrew Rist * under the License. 1976b6b121SAndrew Rist * 2076b6b121SAndrew Rist *************************************************************/ 2176b6b121SAndrew Rist 2276b6b121SAndrew Rist 23cdf0e10cSrcweir package complex.loadAllDocuments; 24cdf0e10cSrcweir 25cdf0e10cSrcweir // __________ Imports __________ 26cdf0e10cSrcweir 27cdf0e10cSrcweir // structs, const, ... 28cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 29cdf0e10cSrcweir 30cdf0e10cSrcweir // exceptions 31cdf0e10cSrcweir import com.sun.star.uno.Exception; 32cdf0e10cSrcweir import com.sun.star.uno.RuntimeException; 33cdf0e10cSrcweir 34cdf0e10cSrcweir // interfaces 35cdf0e10cSrcweir import com.sun.star.task.XStatusIndicator; 36cdf0e10cSrcweir 37cdf0e10cSrcweir // helper 38cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 39cdf0e10cSrcweir 40cdf0e10cSrcweir // others 41cdf0e10cSrcweir //import java.lang.*; 42cdf0e10cSrcweir 43cdf0e10cSrcweir // __________ Implementation __________ 44cdf0e10cSrcweir 45cdf0e10cSrcweir /** 46cdf0e10cSrcweir * Implemets a simple status indicator, which 47cdf0e10cSrcweir * provide informations about state of a load request. 48cdf0e10cSrcweir * It can be used as an argument e.g. for loadComponentFromURL(). 49cdf0e10cSrcweir */ 50cdf0e10cSrcweir public class StatusIndicator implements com.sun.star.task.XStatusIndicator 51cdf0e10cSrcweir { 52cdf0e10cSrcweir // ____________________ 53cdf0e10cSrcweir 54cdf0e10cSrcweir /** 55cdf0e10cSrcweir * @const SHOWSTATUS_NO don't show the status - but save information about using of this indicator object 56*07a3d7f1SPedro Giffuni * @const SHOWSTATUS_LOG the possible set protocol object will be used (it covers STDOUT, STDERR automatically too) 57cdf0e10cSrcweir * @const SHOWSTATUS_DIALOG the status will be shown inside a java dialog 58cdf0e10cSrcweir * @const SHOWSTATUS_LINK the status will be notified to interested listener (one listener only!) 59cdf0e10cSrcweir */ 60cdf0e10cSrcweir public static final int SHOWSTATUS_NO = 0; 61cdf0e10cSrcweir public static final int SHOWSTATUS_LOG = 1; 62cdf0e10cSrcweir public static final int SHOWSTATUS_DIALOG = 4; 63cdf0e10cSrcweir public static final int SHOWSTATUS_LINK = 8; 64cdf0e10cSrcweir 65cdf0e10cSrcweir // ____________________ 66cdf0e10cSrcweir 67cdf0e10cSrcweir /** 68cdf0e10cSrcweir * @member m_sText text, which describe the current status 69cdf0e10cSrcweir * @member m_nRange max value for any progress 70cdf0e10cSrcweir * @member m_nValue the progress value 71cdf0e10cSrcweir * @member m_nOut regulate, how the status will be shown 72cdf0e10cSrcweir * @member m_aProtocol used for logging and transport information about used interface of this object 73cdf0e10cSrcweir */ 74cdf0e10cSrcweir private String m_sText ; 75cdf0e10cSrcweir private int m_nRange ; 76cdf0e10cSrcweir private int m_nValue ; 77cdf0e10cSrcweir private int m_nOut ; 78cdf0e10cSrcweir // private Protocol m_aProtocol ; 79cdf0e10cSrcweir private boolean m_bWasUsed ; 80cdf0e10cSrcweir 81cdf0e10cSrcweir // ____________________ 82cdf0e10cSrcweir 83cdf0e10cSrcweir /** 84cdf0e10cSrcweir * ctor 85cdf0e10cSrcweir * It's initialize an object of this class with default values. 86cdf0e10cSrcweir */ StatusIndicator( int nOut)87cdf0e10cSrcweir public StatusIndicator( int nOut) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir m_sText = new String() ; 90cdf0e10cSrcweir m_nRange = 100 ; 91cdf0e10cSrcweir m_nValue = 0 ; 92cdf0e10cSrcweir m_nOut = nOut ; 93cdf0e10cSrcweir //m_aProtocol = aProtocol ; 94cdf0e10cSrcweir m_bWasUsed = false; 95cdf0e10cSrcweir // aProtocol.resetUsingState(); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir // ____________________ 99cdf0e10cSrcweir 100cdf0e10cSrcweir /** 101cdf0e10cSrcweir * It starts the progress and set the initial text and range. 102cdf0e10cSrcweir * 103cdf0e10cSrcweir * @param sText 104cdf0e10cSrcweir * the initial text for showing 105cdf0e10cSrcweir * 106cdf0e10cSrcweir * @param nRange 107cdf0e10cSrcweir * the new range for following progress 108cdf0e10cSrcweir */ start( String sText, int nRange )109cdf0e10cSrcweir public void start( /*IN*/String sText, /*IN*/int nRange ) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir synchronized(this) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir //m_aProtocol.log("start("+sText+","+nRange+")\n"); 114cdf0e10cSrcweir m_bWasUsed = true; 115cdf0e10cSrcweir // m_aProtocol.itWasUsed(); 116cdf0e10cSrcweir 117cdf0e10cSrcweir m_sText = sText ; 118cdf0e10cSrcweir m_nRange = nRange; 119cdf0e10cSrcweir m_nValue = 0 ; 120cdf0e10cSrcweir } 121cdf0e10cSrcweir impl_show(); 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir // ____________________ 125cdf0e10cSrcweir 126cdf0e10cSrcweir /** 127cdf0e10cSrcweir * Finish the progress and reset internal members. 128cdf0e10cSrcweir */ end()129cdf0e10cSrcweir public void end() 130cdf0e10cSrcweir { 131cdf0e10cSrcweir synchronized(this) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir //m_aProtocol.log("end()\n"); 134cdf0e10cSrcweir m_bWasUsed = true; 135cdf0e10cSrcweir // m_aProtocol.itWasUsed(); 136cdf0e10cSrcweir 137cdf0e10cSrcweir m_sText = new String(); 138cdf0e10cSrcweir m_nRange = 100; 139cdf0e10cSrcweir m_nValue = 0; 140cdf0e10cSrcweir } 141cdf0e10cSrcweir impl_show(); 142cdf0e10cSrcweir } 143cdf0e10cSrcweir 144cdf0e10cSrcweir // ____________________ 145cdf0e10cSrcweir 146cdf0e10cSrcweir /** 147cdf0e10cSrcweir * Set the new description text. 148cdf0e10cSrcweir * 149cdf0e10cSrcweir * @param sText 150cdf0e10cSrcweir * the new text for showing 151cdf0e10cSrcweir */ setText( String sText )152cdf0e10cSrcweir public void setText( /*IN*/String sText ) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir synchronized(this) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir //m_aProtocol.log("setText("+sText+")\n"); 157cdf0e10cSrcweir m_bWasUsed = true; 158cdf0e10cSrcweir // m_aProtocol.itWasUsed(); 159cdf0e10cSrcweir 160cdf0e10cSrcweir m_sText = sText; 161cdf0e10cSrcweir } 162cdf0e10cSrcweir impl_show(); 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir // ____________________ 166cdf0e10cSrcweir 167cdf0e10cSrcweir /** 168cdf0e10cSrcweir * Set the new progress value. 169cdf0e10cSrcweir * 170cdf0e10cSrcweir * @param nValue 171cdf0e10cSrcweir * the new progress value 172cdf0e10cSrcweir * Must fit the range! 173cdf0e10cSrcweir */ setValue( int nValue )174cdf0e10cSrcweir public void setValue( /*IN*/int nValue ) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir synchronized(this) 177cdf0e10cSrcweir { 178cdf0e10cSrcweir //m_aProtocol.log("setValue("+nValue+")\n"); 179cdf0e10cSrcweir m_bWasUsed = true; 180cdf0e10cSrcweir // m_aProtocol.itWasUsed(); 181cdf0e10cSrcweir 182cdf0e10cSrcweir if (nValue<=m_nRange) 183cdf0e10cSrcweir m_nValue = nValue; 184cdf0e10cSrcweir } 185cdf0e10cSrcweir impl_show(); 186cdf0e10cSrcweir } 187cdf0e10cSrcweir 188cdf0e10cSrcweir // ____________________ 189cdf0e10cSrcweir 190cdf0e10cSrcweir /** 191cdf0e10cSrcweir * Reset text and progress value to her defaults. 192cdf0e10cSrcweir */ reset()193cdf0e10cSrcweir public void reset() 194cdf0e10cSrcweir { 195cdf0e10cSrcweir synchronized(this) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir //m_aProtocol.log("reset()\n"); 198cdf0e10cSrcweir m_bWasUsed = true; 199cdf0e10cSrcweir // m_aProtocol.itWasUsed(); 200cdf0e10cSrcweir 201cdf0e10cSrcweir m_sText = new String(); 202cdf0e10cSrcweir m_nValue = 0; 203cdf0e10cSrcweir } 204cdf0e10cSrcweir impl_show(); 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir // ____________________ 208cdf0e10cSrcweir 209cdf0e10cSrcweir /** 210cdf0e10cSrcweir * Internal helper to show the status. 211cdf0e10cSrcweir * Currently it's implement as normal text out on stdout. 212cdf0e10cSrcweir * But of course other thimngs are possible here too. 213cdf0e10cSrcweir * e.g. a dialog 214cdf0e10cSrcweir */ impl_show()215cdf0e10cSrcweir private void impl_show() 216cdf0e10cSrcweir { 217cdf0e10cSrcweir /* synchronized(this) 218cdf0e10cSrcweir { 219cdf0e10cSrcweir if ((m_nOut & SHOWSTATUS_LOG) == SHOWSTATUS_LOG) 220cdf0e10cSrcweir //m_aProtocol.log("\t["+m_nValue+"/"+m_nRange+"] "+m_sText+"\n"); 221cdf0e10cSrcweir 222cdf0e10cSrcweir //if ((m_nOut & SHOWSTATUS_DIALOG) == SHOWSTATUS_DIALOG) 223cdf0e10cSrcweir // not supported yet! 224cdf0e10cSrcweir 225cdf0e10cSrcweir //if ((m_nOut & SHOWSTATUS_LINK) == SHOWSTATUS_LINK) 226cdf0e10cSrcweir // not supported yet! 227cdf0e10cSrcweir } */ 228cdf0e10cSrcweir } 229cdf0e10cSrcweir wasUsed()230cdf0e10cSrcweir public boolean wasUsed() { 231cdf0e10cSrcweir return m_bWasUsed; 232cdf0e10cSrcweir } 233cdf0e10cSrcweir } 234