Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/flexstor/common/gui/imprt/AbstractSettingsModel.java


1   /*
2    * AbstractSettingsModel.java
3    *
4    * Copyright $Date: 2003/08/11 02:22:30 $ FLEXSTOR.net Inc.
5    *
6    * This work is licensed for use and distribution under license terms found at
7    * http://www.flexstor.org/license.html
8    *
9    */
10  
11  package com.flexstor.common.gui.imprt;
12  
13  import java.util.Hashtable;
14  
15  import com.flexstor.common.exceptions.FileOperationFailedException;
16  import com.flexstor.common.gateway.exceptions.TransactionFailedException;
17  import com.flexstor.common.settings.ImportSettingManagerI;
18  import com.flexstor.common.settings.ImportSettingsI;
19  
20  
21  public abstract class AbstractSettingsModel extends java.util.Observable
22   implements SettingsModelI
23  {
24    protected ImportSettingManagerI manager         = null;
25    protected ImportSettingsI       importSettings  = null;
26    protected Hashtable               iSettings       = new Hashtable();
27    protected String[]                disguiseNames   = null;
28    /**
29     * Flag to indicate if the import is done from the main tool bar or from the search retrieval
30     * frame.
31     *
32     * @since 3.0
33     */
34    protected boolean bIsFromRetrieval        = false;
35  
36  
37  
38    public AbstractSettingsModel()
39    {
40    }
41  
42    public AbstractSettingsModel ( ImportSettingManagerI mgr )
43    {
44       manager = mgr;
45    }
46  
47    public AbstractSettingsModel ( ImportSettingManagerI mgr,
48                                     ImportSettingsI currImportSetting )
49    {
50      manager = mgr;
51      importSettings = currImportSetting;
52      if ( importSettings != null )
53      {
54        iSettings.put ( importSettings.getString ( ImportSettingsI.NAME ), importSettings );
55      }
56    }
57  
58    public ImportSettingManagerI getPersistManager()
59    {
60     return manager;
61    }
62    public void setPersistManager ( ImportSettingManagerI mgr )
63    {
64     manager = mgr;
65    }
66  
67    public String getThumbBaseLocation()
68    {
69        return importSettings.getString ( ImportSettingsI.THUMB_URL );
70    }
71  
72    public void setThumbBaseLocation( String text, boolean notifyObservers )
73    {
74        importSettings.setString( ImportSettingsI.THUMB_URL, text );
75  
76        if ( notifyObservers )
77        {
78         notifyAllObservers ( new Notification ( ImportSettingsI.THUMB_URL, null ) );
79        }
80    }
81    public String getSourceFileBaseLoc()
82    {
83        return importSettings.getString( ImportSettingsI.SOURCE_FILES_BASE );
84    }
85  
86    public void setSourceFileBaseLoc( String text, boolean notifyObservers )
87    {
88        importSettings.setString( ImportSettingsI.SOURCE_FILES_BASE, text );
89  
90        if ( notifyObservers )
91        {
92          notifyAllObservers ( new Notification ( ImportSettingsI.SOURCE_FILES_BASE, null ) );
93        }
94    }
95    public String getHighResBaseLoc()
96    {
97        return importSettings.getString( ImportSettingsI.HIGH_RES_URL );
98    }
99    public void setHighResBaseLoc( String text, boolean notifyObservers )
100   {
101       importSettings.setString( ImportSettingsI.HIGH_RES_URL, text );
102       importSettings.setString( ImportSettingsI.TOP, text );
103 
104       if ( notifyObservers )
105       {
106         notifyAllObservers ( new Notification ( ImportSettingsI.HIGH_RES_URL, null ) );
107       }
108   }
109   public void enableInput ( boolean mode )
110   {
111     if ( mode )
112       notifyAllObservers ( new Notification ( Notification.FREE, null ) );
113     else
114       notifyAllObservers ( new Notification ( Notification.BUSY, null ) );
115   }
116   public String getLowResBaseLoc()
117   {
118       return importSettings.getString( ImportSettingsI.LOW_RES_URL );
119   }
120 
121   public void setLowResBaseLoc( String text, boolean notifyObservers )
122   {
123       importSettings.setString(ImportSettingsI.LOW_RES_URL, text );
124 
125       if ( notifyObservers )
126       {
127        notifyAllObservers ( new Notification ( ImportSettingsI.LOW_RES_URL, null ) );
128       }
129   }
130 
131 
132   public String getLRExtension()
133   {
134       return importSettings.getString( ImportSettingsI.LOW_RES_EXT );
135   }
136 
137   public void setLRExtension( String text, boolean notifyObservers )
138   {
139       importSettings.setString(ImportSettingsI.LOW_RES_EXT, text );
140 
141       if ( notifyObservers )
142       {
143        notifyAllObservers ( new Notification ( ImportSettingsI.LOW_RES_EXT, null ) );
144       }
145 
146   }
147 
148   public String getLRDirectory()
149   {
150       return importSettings.getString( ImportSettingsI.LOW_RES_DIR );
151   }
152 
153   public void setLRDirectory( String text, boolean notifyObservers )
154   {
155       importSettings.setString( ImportSettingsI.LOW_RES_DIR, text );
156 
157       if ( notifyObservers )
158       {
159        notifyAllObservers ( new Notification ( ImportSettingsI.LOW_RES_DIR, null ) );
160       }
161   }
162 
163   public String getLocalPath()
164   {
165       return importSettings.getString( ImportSettingsI.LOCAL_PATH );
166   }
167 
168   public void setLocalPath( String text, boolean notifyObservers )
169   {
170       importSettings.setString( ImportSettingsI.LOCAL_PATH, text );
171 
172       if ( notifyObservers )
173       {
174        notifyAllObservers ( new Notification ( ImportSettingsI.LOCAL_PATH, null ) );
175       }
176   }
177 
178   public String getHRToBaseLocPath()
179   {
180       return importSettings.getString( ImportSettingsI.HIGH_RES_DEST_URL );
181   }
182 
183   public void setHRToBaseLocPath( String text, boolean notifyObservers )
184   {
185       importSettings.setString( ImportSettingsI.HIGH_RES_DEST_URL, text );
186 
187       if ( notifyObservers )
188       {
189        notifyAllObservers ( new Notification ( ImportSettingsI.HIGH_RES_DEST_URL, null ) );
190       }
191   }
192 
193   public String getLRToBaseLocPath()
194   {
195       return importSettings.getString( ImportSettingsI.LOW_RES_DEST_URL );
196   }
197 
198   public void setLRToBaseLocPath( String text, boolean notifyObservers )
199   {
200       importSettings.setString( ImportSettingsI.LOW_RES_DEST_URL, text );
201 
202       if ( notifyObservers )
203       {
204        notifyAllObservers ( new Notification ( ImportSettingsI.LOW_RES_DEST_URL, null ) );
205       }
206 
207   }
208 
209 
210   /// From pref panel - start
211   public String getConversionSetting()
212   {
213       return importSettings.getString( ImportSettingsI.CONFIG_FILE );
214   }
215 
216   public void setConversionSetting( String convSetting, boolean notifyObservers )
217   {
218       importSettings.setString( ImportSettingsI.CONFIG_FILE, convSetting );
219       if ( notifyObservers )
220       {
221         notifyAllObservers ( new Notification ( ImportSettingsI.CONFIG_FILE, null) );
222       }
223   }
224 
225   public String getEmailAddress()
226   {
227       return importSettings.getString( ImportSettingsI.EMAIL );
228   }
229 
230   public String getMailTime()
231   {
232       return importSettings.getString( ImportSettingsI.MAILTIME );
233   }
234 
235   public Object getImportTime()
236   {
237       return importSettings.getObject( ImportSettingsI.IMPORTTIME );
238   }
239 
240 
241   public void setEmailAddress( String emailAddress, boolean notifyObservers )
242   {
243       importSettings.setString( ImportSettingsI.EMAIL, emailAddress );
244 
245       if ( notifyObservers )
246       {
247         notifyAllObservers ( new Notification ( ImportSettingsI.EMAIL, null ) );
248       }
249   }
250 
251   public void setMailTime( String mailTime, boolean notifyObservers )
252   {
253       importSettings.setString( ImportSettingsI.MAILTIME, mailTime );
254 
255       if ( notifyObservers )
256       {
257         notifyAllObservers ( new Notification ( ImportSettingsI.EMAIL, null ) );
258       }
259   }
260 
261   public void setImportTime( Object mailTime, boolean notifyObservers, boolean bOnFly )
262   {
263       importSettings.setObject( ImportSettingsI.IMPORTTIME, mailTime, bOnFly );
264 
265       if ( notifyObservers )
266       {
267         notifyAllObservers ( new Notification ( ImportSettingsI.IMPORTTIME, null ) );
268       }
269   }
270 
271 
272    /// From pref panel - end
273 
274 //  public void saveSetting();
275 
276 //  public void saveSettingAs( String settingName, boolean notifyObservers );
277 
278   public boolean canPerform( String operationID )
279   {
280       return importSettings.getBoolean( operationID );
281   }
282 
283   public boolean canEdit ( String operationID )
284   {
285       return true;
286   }
287 
288   public void setBoxChecked( String operationID, boolean def, boolean notifyObservers )
289   {
290       if ( operationID == null )
291        return;
292 
293       importSettings.setBoolean( operationID, def );
294 
295       if ( notifyObservers )
296       {
297         notifyAllObservers ( new Notification ( operationID, def ? Boolean.TRUE : Boolean.FALSE ) );
298       }
299   }
300   public com.flexstor.common.settings.ImportSettingsI getCurrentImportSetting()
301   {
302      return importSettings;
303   }
304   public void setCurrentImportSetting ( com.flexstor.common.settings.ImportSettingsI settings )
305   {
306     importSettings = ( ImportSettingsI ) settings;
307     if ( importSettings != null )
308     {
309      notifyAllObservers ( new Notification ( ImportSettingsI.SETTING_CHANGED, Boolean.TRUE ) );
310     }
311   }
312   public String getCurrentDisguiseName ()
313   {
314       return importSettings.getString( ImportSettingsI.APPLICATION_NAME );
315   }
316   public void setCurrentDisguiseName ( String name,
317                                        boolean notifyObservers,
318                                        boolean bOnFly )
319   {
320     importSettings.setString( ImportSettingsI.APPLICATION_NAME, name, bOnFly );
321 
322     if ( notifyObservers )
323     {
324        notifyAllObservers ( new Notification ( ImportSettingsI.APPLICATION_NAME, Boolean.TRUE ) );
325     }
326   }
327   public void setCurrentImportSetting ( String settings )
328     throws FileOperationFailedException
329   {
330        if ( iSettings != null )
331        {
332           if ( iSettings.containsKey ( settings ) )
333           {
334              importSettings = ( ImportSettingsI ) iSettings.get ( settings );
335           }
336           else
337           {
338              if ( manager != null )
339              {
340                  importSettings = manager.getImportSetting ( settings );
341                  // to set the value of toClassify property
342                  importSettings.setBoolean ( ImportSettingsI.TO_CLASSIFY, !bIsFromRetrieval, true  );
343                  iSettings.put ( settings, importSettings );
344              }
345           }
346           notifyAllObservers ( new Notification ( ImportSettingsI.SETTING_CHANGED, Boolean.TRUE ) );
347         }
348   }
349 
350   public java.util.Hashtable getAllImportSettings()
351      throws FileOperationFailedException
352   {
353     // caching
354     if  ( ( iSettings == null ) && ( manager != null ) )
355     {
356       iSettings = manager.getAllImportSettings();
357     }
358     return iSettings;
359   }
360   public String[] getAllImportSettingNames()
361      throws FileOperationFailedException, TransactionFailedException
362   {
363     if ( manager != null )
364       return manager.getUserImportSettingNames();
365 
366     return null;
367   }
368   public String[] getAllExistingImportSettingNames()
369      throws FileOperationFailedException
370   {
371     if ( manager != null )
372       return manager.getAllExistingImportSettingNames();
373 
374     return null;
375   }
376 
377   public void notifyAllObservers()
378   {
379      setChanged();
380      notifyObservers();
381      clearChanged();
382   }
383   public void notifyAllObservers( Object object )
384   {
385      setChanged();
386      notifyObservers( object );
387      clearChanged();
388   }
389 }
390