/[svn]/jsampler/trunk/src/org/jsampler/task/InstrumentsDb.java
ViewVC logotype

Annotation of /jsampler/trunk/src/org/jsampler/task/InstrumentsDb.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1205 - (hide annotations) (download)
Thu May 24 21:55:41 2007 UTC (16 years, 11 months ago) by iliev
File size: 26904 byte(s)
* upgrading to version 0.5a

1 iliev 1205 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4     * Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com>
5     *
6     * This file is part of JSampler.
7     *
8     * JSampler is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License version 2
10     * as published by the Free Software Foundation.
11     *
12     * JSampler is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with JSampler; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20     * MA 02111-1307 USA
21     */
22    
23     package org.jsampler.task;
24    
25     import java.util.logging.Level;
26    
27     import org.jsampler.CC;
28     import org.jsampler.HF;
29    
30     import org.linuxsampler.lscp.DbDirectoryInfo;
31     import org.linuxsampler.lscp.DbInstrumentInfo;
32     import org.linuxsampler.lscp.DbSearchQuery;
33     import org.linuxsampler.lscp.ScanJobInfo;
34    
35     import static org.jsampler.JSI18n.i18n;
36     import static org.linuxsampler.lscp.Client.ScanMode;
37    
38     /**
39     * Provides the instruments database specific tasks.
40     * @author Grigor Iliev
41     */
42     public class InstrumentsDb {
43    
44     /** Forbits the instantiation of this class. */
45     private InstrumentsDb() { }
46    
47     /**
48     * This task retrieves the number of directories in the specified directory.
49     */
50     public static class GetDirectoryCount extends EnhancedTask<Integer> {
51     private String dir;
52     private boolean recursive;
53    
54     /**
55     * Creates a new instance of <code>GetDirectoryCount</code>.
56     * @param dir The absolute path name of the directory.
57     * @param recursive If <code>true</code>, the number of all directories
58     * in the specified subtree will be returned.
59     */
60     public
61     GetDirectoryCount(String dir, boolean recursive) {
62     setTitle("InstrumentsDb.GetDirectoryCount_task");
63     setDescription(i18n.getMessage("InstrumentsDb.GetDirectoryCount.desc"));
64     this.dir = dir;
65     this.recursive = recursive;
66     }
67    
68     /** The entry point of the task. */
69     public void
70     run() {
71     try { setResult(CC.getClient().getDbDirectoryCount(dir, recursive)); }
72     catch(Exception x) {
73     setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
74     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
75     }
76     }
77     }
78    
79     /**
80     * This task retrieves the number of instruments in the specified directory.
81     */
82     public static class GetInstrumentCount extends EnhancedTask<Integer> {
83     private String dir;
84     private boolean recursive;
85    
86     /**
87     * Creates a new instance of <code>GetInstrumentCount</code>.
88     * @param dir The absolute path name of the directory.
89     * @param recursive If <code>true</code>, the number of all instruments
90     * in the specified subtree will be returned.
91     */
92     public
93     GetInstrumentCount(String dir, boolean recursive) {
94     setTitle("InstrumentsDb.GetInstrumentCount_task");
95     setDescription(i18n.getMessage("InstrumentsDb.GetInstrumentCount.desc"));
96     this.dir = dir;
97     this.recursive = recursive;
98     }
99    
100     /** The entry point of the task. */
101     public void
102     run() {
103     try { setResult(CC.getClient().getDbInstrumentCount(dir, recursive)); }
104     catch(Exception x) {
105     setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
106     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
107     }
108     }
109     }
110    
111     /**
112     * This task retrieves the list of directories in the specified directory.
113     */
114     public static class GetDrectories extends EnhancedTask<DbDirectoryInfo[]> {
115     private String dir;
116    
117     /**
118     * Creates a new instance of <code>GetDrectories</code>.
119     * @param dir The absolute path name of the directory.
120     */
121     public
122     GetDrectories(String dir) {
123     setTitle("InstrumentsDb.GetDrectories_task");
124     setDescription(i18n.getMessage("InstrumentsDb.GetDrectories.desc"));
125     this.dir = dir;
126     }
127    
128     /** The entry point of the task. */
129     public void
130     run() {
131     try { setResult(CC.getClient().getDbDirectories(dir)); }
132     catch(Exception x) {
133     setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
134     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
135     }
136     }
137    
138     public String
139     getDirectory() { return dir; }
140    
141     /**
142     * Used to decrease the traffic. All task in the queue
143     * equal to this are removed.
144     */
145     public boolean
146     equals(Object obj) {
147     if(obj == null) return false;
148     if(!(obj instanceof GetDrectories)) return false;
149     String d = ((GetDrectories)obj).getDirectory();
150     if(getDirectory() == null) {
151     return d == null;
152     }
153     if(!getDirectory().equals(d)) return false;
154    
155     return true;
156     }
157     }
158    
159    
160     /**
161     * This task retrieves information about a directory.
162     */
163     public static class GetDrectory extends EnhancedTask<DbDirectoryInfo> {
164     private String dir;
165    
166     /**
167     * Creates a new instance of <code>GetDrectory</code>.
168     * @param dir The absolute path name of the directory.
169     */
170     public
171     GetDrectory(String dir) {
172     setTitle("InstrumentsDb.GetDrectory_task");
173     setDescription(i18n.getMessage("InstrumentsDb.GetDrectory.desc"));
174     this.dir = dir;
175     }
176    
177     /** The entry point of the task. */
178     public void
179     run() {
180     try { setResult(CC.getClient().getDbDirectoryInfo(dir)); }
181     catch(Exception x) {
182     setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
183     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
184     }
185     }
186     }
187    
188     /**
189     * This task creates a new directory.
190     */
191     public static class CreateDirectory extends EnhancedTask {
192     private String dir;
193    
194     /**
195     * Creates a new instance of <code>CreateDirectory</code>.
196     * @param dir The absolute path name of the directory to add.
197     */
198     public
199     CreateDirectory(String dir) {
200     setTitle("InstrumentsDb.CreateDirectory_task");
201     setDescription(i18n.getMessage("InstrumentsDb.CreateDirectory.desc"));
202     this.dir = dir;
203     }
204    
205     /** The entry point of the task. */
206     public void
207     run() {
208     try { CC.getClient().addDbDirectory(dir); }
209     catch(Exception x) {
210     setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
211     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
212     }
213     }
214     }
215    
216     /**
217     * This task renames the specified directory.
218     */
219     public static class RenameDirectory extends EnhancedTask {
220     private String dir;
221     private String newName;
222    
223     /**
224     * Creates a new instance of <code>RenameDirectory</code>.
225     * @param dir The absolute path name of the directory to rename.
226     * @param newName The new name for the specified directory.
227     */
228     public
229     RenameDirectory(String dir, String newName) {
230     setTitle("InstrumentsDb.RenameDirectory_task");
231     setDescription(i18n.getMessage("InstrumentsDb.RenameDirectory.desc"));
232     this.dir = dir;
233     this.newName = newName;
234     }
235    
236     /** The entry point of the task. */
237     public void
238     run() {
239     try { CC.getClient().renameDbDirectory(dir, newName); }
240     catch(Exception x) {
241     setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
242     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
243     }
244     }
245     }
246    
247     /**
248     * This task changes the description of a directory.
249     */
250     public static class SetDirectoryDescription extends EnhancedTask {
251     private String dir;
252     private String desc;
253    
254     /**
255     * Creates a new instance of <code>SetDirectoryDescription</code>.
256     * @param dir The absolute path name of the directory.
257     * @param desc The new description for the directory.
258     */
259     public
260     SetDirectoryDescription(String dir, String desc) {
261     setTitle("InstrumentsDb.SetDirectoryDescription_task");
262     String s = i18n.getMessage("InstrumentsDb.SetDirectoryDescription.desc");
263     setDescription(s);
264     this.dir = dir;
265     this.desc = desc;
266     }
267    
268     /** The entry point of the task. */
269     public void
270     run() {
271     try { CC.getClient().setDbDirectoryDescription(dir, desc); }
272     catch(Exception x) {
273     setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
274     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
275     }
276     }
277     }
278    
279     /**
280     * This task removes the specified directories.
281     */
282     public static class RemoveDirectories extends EnhancedTask {
283     private DbDirectoryInfo[] directories;
284    
285     /**
286     * Creates a new instance of <code>RemoveDirectories</code>.
287     * @param directories The directories to remove.
288     */
289     public
290     RemoveDirectories(DbDirectoryInfo[] directories) {
291     setTitle("InstrumentsDb.RemoveDirectories_task");
292     setDescription(i18n.getMessage("InstrumentsDb.RemoveDirectories.desc"));
293     this.directories = directories;
294     }
295    
296     /** The entry point of the task. */
297     public void
298     run() {
299     try {
300     removeDirectories();
301     } catch(Exception x) {
302     setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
303     setErrorDetails(x);
304     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
305     }
306     }
307    
308     private void
309     removeDirectories() throws Exception {
310     if(directories == null || directories.length == 0) return;
311     if(directories.length == 1) {
312     String path = directories[0].getDirectoryPath();
313     CC.getClient().removeDbDirectory(path, true);
314     } else {
315     String[] dirs = new String[directories.length];
316     for(int i = 0; i < directories.length; i++) {
317     dirs[i] = directories[i].getDirectoryPath();
318     }
319    
320     CC.getClient().removeDbDirectories(dirs, true);
321     }
322     }
323     }
324    
325     /**
326     * This task finds all directories in the specified directory
327     * that corresponds to the provided search criterias.
328     */
329     public static class FindDirectories extends EnhancedTask<DbDirectoryInfo[]> {
330     private String dir;
331     private DbSearchQuery query;
332    
333     /**
334     * Creates a new instance of <code>FindDirectories</code>.
335     * @param dir The absolute path name of the directory.
336     * @param query Provides the search criterias.
337     */
338     public
339     FindDirectories(String dir, DbSearchQuery query) {
340     setTitle("InstrumentsDb.FindDirectories_task");
341     setDescription(i18n.getMessage("InstrumentsDb.FindDirectories.desc"));
342     this.dir = dir;
343     this.query = query;
344     }
345    
346     /** The entry point of the task. */
347     public void
348     run() {
349     try { setResult(CC.getClient().findDbDirectories(dir, query)); }
350     catch(Exception x) {
351     setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
352     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
353     }
354     }
355     }
356    
357     /**
358     * This task retrieves the list of instruments in the specified directory.
359     */
360     public static class GetInstruments extends EnhancedTask<DbInstrumentInfo[]> {
361     private String dir;
362    
363     /**
364     * Creates a new instance of <code>GetInstruments</code>.
365     * @param dir The absolute path name of the directory.
366     */
367     public
368     GetInstruments(String dir) {
369     setTitle("InstrumentsDb.GetInstruments_task");
370     setDescription(i18n.getMessage("InstrumentsDb.GetInstruments.desc"));
371     this.dir = dir;
372     }
373    
374     /** The entry point of the task. */
375     public void
376     run() {
377     try { setResult(CC.getClient().getDbInstruments(dir)); }
378     catch(Exception x) {
379     setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
380     setErrorDetails(x);
381     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
382     }
383     }
384    
385     public String
386     getDirectory() { return dir; }
387    
388     /**
389     * Used to decrease the traffic. All task in the queue
390     * equal to this are removed.
391     */
392     public boolean
393     equals(Object obj) {
394     if(obj == null) return false;
395     if(!(obj instanceof GetInstruments)) return false;
396     String d = ((GetInstruments)obj).getDirectory();
397     if(getDirectory() == null) {
398     return d == null;
399     }
400     if(!getDirectory().equals(d)) return false;
401     return true;
402     }
403     }
404    
405     /**
406     * This task retrieves information about an instrument.
407     */
408     public static class GetInstrument extends EnhancedTask<DbInstrumentInfo> {
409     private String instr;
410    
411     /**
412     * Creates a new instance of <code>GetInstrument</code>.
413     * @param instr The absolute path name of the instrument.
414     */
415     public
416     GetInstrument(String instr) {
417     setTitle("InstrumentsDb.GetInstrument_task");
418     setDescription(i18n.getMessage("InstrumentsDb.GetInstrument.desc"));
419     this.instr = instr;
420     }
421    
422     /** The entry point of the task. */
423     public void
424     run() {
425     try { setResult(CC.getClient().getDbInstrumentInfo(instr)); }
426     catch(Exception x) {
427     setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
428     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
429     }
430     }
431     }
432    
433     /**
434     * This task finds all instruments in the specified directory
435     * that corresponds to the provided search criterias.
436     */
437     public static class FindInstruments extends EnhancedTask<DbInstrumentInfo[]> {
438     private String dir;
439     private DbSearchQuery query;
440    
441     /**
442     * Creates a new instance of <code>FindInstruments</code>.
443     * @param dir The absolute path name of the directory.
444     * @param query Provides the search criterias.
445     */
446     public
447     FindInstruments(String dir, DbSearchQuery query) {
448     setTitle("InstrumentsDb.FindInstruments_task");
449     setDescription(i18n.getMessage("InstrumentsDb.FindInstruments.desc"));
450     this.dir = dir;
451     this.query = query;
452     }
453    
454     /** The entry point of the task. */
455     public void
456     run() {
457     try { setResult(CC.getClient().findDbInstruments(dir, query)); }
458     catch(Exception x) {
459     setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
460     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
461     }
462     }
463     }
464    
465     /**
466     * This task renames the specified instrument.
467     */
468     public static class RenameInstrument extends EnhancedTask {
469     private String instr;
470     private String newName;
471    
472     /**
473     * Creates a new instance of <code>RenameInstrument</code>.
474     * @param instr The absolute path name of the instrument to rename.
475     * @param newName The new name for the specified instrument.
476     */
477     public
478     RenameInstrument(String instr, String newName) {
479     setTitle("InstrumentsDb.RenameInstrument_task");
480     setDescription(i18n.getMessage("InstrumentsDb.RenameInstrument.desc"));
481     this.instr = instr;
482     this.newName = newName;
483     }
484    
485     /** The entry point of the task. */
486     public void
487     run() {
488     try { CC.getClient().renameDbInstrument(instr, newName); }
489     catch(Exception x) {
490     setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
491     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
492     }
493     }
494     }
495    
496     /**
497     * This task changes the description of an instrument.
498     */
499     public static class SetInstrumentDescription extends EnhancedTask {
500     private String instr;
501     private String desc;
502    
503     /**
504     * Creates a new instance of <code>SetInstrumentDescription</code>.
505     * @param instr The absolute path name of the instrument.
506     * @param desc The new description for the instrument.
507     */
508     public
509     SetInstrumentDescription(String instr, String desc) {
510     setTitle("InstrumentsDb.SetInstrumentDescription_task");
511     String s = i18n.getMessage("InstrumentsDb.SetInstrumentDescription.desc");
512     setDescription(s);
513     this.instr = instr;
514     this.desc = desc;
515     }
516    
517     /** The entry point of the task. */
518     public void
519     run() {
520     try { CC.getClient().setDbInstrumentDescription(instr, desc); }
521     catch(Exception x) {
522     setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
523     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
524     }
525     }
526     }
527    
528     /**
529     * This task removes the specified instruments.
530     */
531     public static class RemoveInstruments extends EnhancedTask {
532     private DbInstrumentInfo[] instruments;
533    
534     /**
535     * Creates a new instance of <code>RemoveInstruments</code>.
536     * @param instruments The instruments to remove.
537     */
538     public
539     RemoveInstruments(DbInstrumentInfo[] instruments) {
540     setTitle("InstrumentsDb.RemoveInstruments_task");
541     setDescription(i18n.getMessage("InstrumentsDb.RemoveInstruments.desc"));
542     this.instruments = instruments;
543     }
544    
545     /** The entry point of the task. */
546     public void
547     run() {
548     try {
549     removeInstruments();
550     } catch(Exception x) {
551     setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
552     setErrorDetails(x);
553     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
554     }
555     }
556    
557     private void
558     removeInstruments() throws Exception {
559     if(instruments == null || instruments.length == 0) return;
560     if(instruments.length == 1) {
561     String path = instruments[0].getInstrumentPath();
562     CC.getClient().removeDbInstrument(path);
563     } else {
564     String[] instrs = new String[instruments.length];
565     for(int i = 0; i < instruments.length; i++) {
566     instrs[i] = instruments[i].getInstrumentPath();
567     }
568    
569     CC.getClient().removeDbInstruments(instrs);
570     }
571     }
572     }
573    
574     /**
575     * This task adds instruments from an instrument file to the instruments database.
576     */
577     public static class AddInstrumentsFromFile extends EnhancedTask<Integer> {
578     private String dbDir;
579     private String filePath;
580     private int instrIndex;
581    
582     /**
583     * Creates a new instance of <code>AddInstrumentsFromFile</code>.
584     * @param dbDir The absolute path name of the database directory
585     * in which all instruments from the specified instrument file will be added.
586     * @param filePath The absolute path name of the instrument file.
587     */
588     public
589     AddInstrumentsFromFile(String dbDir, String filePath) {
590     this(dbDir, filePath, -1);
591     }
592    
593     /**
594     * Creates a new instance of <code>AddInstrumentsFromFile</code>.
595     * @param dbDir The absolute path name of the database directory
596     * in which the specified instrument will be added.
597     * @param filePath The absolute path name of the instrument file.
598     * @param instrIndex The index of the instrument
599     * (in the given instrument file) to add. If -1 is specified, all
600     * instruments in the given instrument file will be added.
601     */
602     public
603     AddInstrumentsFromFile(String dbDir, String filePath, int instrIndex) {
604     setTitle("InstrumentsDb.AddInstrumentsFromFile_task");
605     String s = i18n.getMessage("InstrumentsDb.AddInstrumentsFromFile.desc");
606     setDescription(s);
607     this.dbDir = dbDir;
608     this.filePath = filePath;
609     this.instrIndex = instrIndex;
610     }
611    
612     /** The entry point of the task. */
613     public void
614     run() {
615     try {
616     int i;
617     if(instrIndex != -1) {
618     i = CC.getClient().addDbInstrument (
619     dbDir, filePath, instrIndex, true
620     );
621     } else {
622     i = CC.getClient().addDbInstruments(dbDir, filePath, true);
623     }
624    
625     setResult(i);
626     } catch(Exception x) {
627     setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
628     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
629     }
630     }
631     }
632    
633     /**
634     * This task adds instruments from a directory to the instruments database.
635     */
636     public static class AddInstruments extends EnhancedTask<Integer> {
637     private String dbDir;
638     private String fsDir;
639     private boolean flat;
640    
641     /**
642     * Creates a new instance of <code>AddInstruments</code>.
643     * @param dbDir The absolute path name of the database directory
644     * in which all instruments from the specified directory will be added.
645     * @param fsDir The absolute path name of the file system directory.
646     */
647     public
648     AddInstruments(String dbDir, String fsDir) {
649     this(dbDir, fsDir, false);
650     }
651    
652     /**
653     * Creates a new instance of <code>AddInstruments</code>.
654     * @param dbDir The absolute path name of the database directory
655     * in which all instruments from the specified directory will be added.
656     * @param fsDir The absolute path name of the file system directory.
657     * @param flat If <code>true</code>, the respective subdirectory structure
658     * will not be re-created in the supplied database directory.
659     */
660     public
661     AddInstruments(String dbDir, String fsDir, boolean flat) {
662     setTitle("InstrumentsDb.AddInstruments_task");
663     String s = i18n.getMessage("InstrumentsDb.AddInstruments.desc");
664     setDescription(s);
665     this.dbDir = dbDir;
666     this.fsDir = fsDir;
667     this.flat = flat;
668     }
669    
670     /** The entry point of the task. */
671     public void
672     run() {
673     try {
674     int i;
675     if(flat) {
676     i = CC.getClient().addDbInstruments (
677     ScanMode.FLAT, dbDir, fsDir, true
678     );
679     } else {
680     i = CC.getClient().addDbInstruments (
681     ScanMode.RECURSIVE, dbDir, fsDir, true
682     );
683     }
684    
685     setResult(i);
686     }
687     catch(Exception x) {
688     setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
689     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
690     }
691     }
692     }
693    
694     /**
695     * This task adds instruments from a file system directory (excluding
696     * the instruments in the subdirectories) to the instruments database.
697     */
698     public static class AddInstrumentsNonrecursive extends EnhancedTask<Integer> {
699     private String dbDir;
700     private String fsDir;
701    
702     /**
703     * Creates a new instance of <code>AddInstrumentsNonrecursive</code>.
704     * @param dbDir The absolute path name of the database directory
705     * in which the instruments from the specified directory (excluding
706     * the instruments in the subdirectories) will be added.
707     * @param fsDir The absolute path name of the file system directory.
708     */
709     public
710     AddInstrumentsNonrecursive(String dbDir, String fsDir) {
711     setTitle("InstrumentsDb.AddInstrumentsNonrecursive_task");
712     String s = i18n.getMessage("InstrumentsDb.AddInstrumentsNonrecursive.desc");
713     setDescription(s);
714     this.dbDir = dbDir;
715     this.fsDir = fsDir;
716     }
717    
718     /** The entry point of the task. */
719     public void
720     run() {
721     try {
722     int i = CC.getClient().addDbInstruments (
723     ScanMode.NON_RECURSIVE, dbDir, fsDir, true
724     );
725    
726     setResult(i);
727     }
728     catch(Exception x) {
729     setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
730     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
731     }
732     }
733     }
734    
735     /**
736     * This task moves the specified instruments
737     * and directories to the specified location.
738     */
739     public static class Move extends EnhancedTask {
740     private DbDirectoryInfo[] directories;
741     private DbInstrumentInfo[] instruments;
742     private String dest;
743    
744     /**
745     * Creates a new instance of <code>Move</code>.
746     * @param directories The directories to move.
747     * @param instruments The instruments to move.
748     * @param dest The absolute path name of the directory where
749     * the specified instruments and directories will be moved to.
750     */
751     public
752     Move(DbDirectoryInfo[] directories, DbInstrumentInfo[] instruments, String dest) {
753     setTitle("InstrumentsDb.Move_task");
754     setDescription(i18n.getMessage("InstrumentsDb.Move.desc"));
755     this.directories = directories;
756     this.instruments = instruments;
757     this.dest = dest;
758     }
759    
760     /** The entry point of the task. */
761     public void
762     run() {
763     try {
764     moveInstruments();
765     moveDirectories();
766     } catch(Exception x) {
767     setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
768     setErrorDetails(x);
769     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
770     }
771     }
772    
773     private void
774     moveInstruments() throws Exception {
775     if(instruments == null || instruments.length == 0) return;
776     if(instruments.length == 1) {
777     String path = instruments[0].getInstrumentPath();
778     CC.getClient().moveDbInstrument(path, dest);
779     } else {
780     String[] instrs = new String[instruments.length];
781     for(int i = 0; i < instruments.length; i++) {
782     instrs[i] = instruments[i].getInstrumentPath();
783     }
784    
785     CC.getClient().moveDbInstruments(instrs, dest);
786     }
787     }
788    
789     private void
790     moveDirectories() throws Exception {
791     if(directories == null || directories.length == 0) return;
792     if(directories.length == 1) {
793     String path = directories[0].getDirectoryPath();
794     CC.getClient().moveDbDirectory(path, dest);
795     } else {
796     String[] dirs = new String[directories.length];
797     for(int i = 0; i < directories.length; i++) {
798     dirs[i] = directories[i].getDirectoryPath();
799     }
800    
801     CC.getClient().moveDbDirectories(dirs, dest);
802     }
803     }
804     }
805    
806     /**
807     * This task copies the specified instruments
808     * and directories to the specified location.
809     */
810     public static class Copy extends EnhancedTask {
811     private DbDirectoryInfo[] directories;
812     private DbInstrumentInfo[] instruments;
813     private String dest;
814    
815     /**
816     * Creates a new instance of <code>Copy</code>.
817     * @param directories The directories to copy.
818     * @param instruments The instruments to copy.
819     * @param dest The absolute path name of the directory where
820     * the specified instruments and directories will be copied to.
821     */
822     public
823     Copy(DbDirectoryInfo[] directories, DbInstrumentInfo[] instruments, String dest) {
824     setTitle("InstrumentsDb.Copy_task");
825     setDescription(i18n.getMessage("InstrumentsDb.Copy.desc"));
826     this.directories = directories;
827     this.instruments = instruments;
828     this.dest = dest;
829     }
830    
831     /** The entry point of the task. */
832     public void
833     run() {
834     try {
835     copyInstruments();
836     copyDirectories();
837     } catch(Exception x) {
838     setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
839     setErrorDetails(x);
840     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
841     }
842     }
843    
844     private void
845     copyInstruments() throws Exception {
846     if(instruments == null || instruments.length == 0) return;
847     if(instruments.length == 1) {
848     String path = instruments[0].getInstrumentPath();
849     CC.getClient().copyDbInstrument(path, dest);
850     } else {
851     String[] instrs = new String[instruments.length];
852     for(int i = 0; i < instruments.length; i++) {
853     instrs[i] = instruments[i].getInstrumentPath();
854     }
855    
856     CC.getClient().copyDbInstruments(instrs, dest);
857     }
858     }
859    
860     private void
861     copyDirectories() throws Exception {
862     if(directories == null || directories.length == 0) return;
863     if(directories.length == 1) {
864     String path = directories[0].getDirectoryPath();
865     CC.getClient().copyDbDirectory(path, dest);
866     } else {
867     String[] dirs = new String[directories.length];
868     for(int i = 0; i < directories.length; i++) {
869     dirs[i] = directories[i].getDirectoryPath();
870     }
871    
872     CC.getClient().copyDbDirectories(dirs, dest);
873     }
874     }
875     }
876    
877     /**
878     * This task retrieves information about a scan job.
879     */
880     public static class GetScanJobInfo extends EnhancedTask<ScanJobInfo> {
881     private int jobId;
882    
883     /**
884     * Creates a new instance of <code>GetScanJobInfo</code>.
885     * @param jobId The ID of the scan job.
886     */
887     public
888     GetScanJobInfo(int jobId) {
889     setTitle("InstrumentsDb.GetScanJobInfo_task");
890     setDescription(i18n.getMessage("InstrumentsDb.GetScanJobInfo.desc"));
891     this.jobId = jobId;
892     }
893    
894     /** The entry point of the task. */
895     public void
896     run() {
897     try { setResult(CC.getClient().getDbInstrumentsJobInfo(jobId)); }
898     catch(Exception x) {
899     setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
900     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
901     }
902     }
903    
904     public int
905     getJobId() { return jobId; }
906    
907     /**
908     * Used to decrease the traffic. All task in the queue
909     * equal to this are removed.
910     */
911     public boolean
912     equals(Object obj) {
913     if(obj == null) return false;
914     if(!(obj instanceof GetScanJobInfo)) return false;
915     if(((GetScanJobInfo)obj).getJobId() != getJobId()) return false;
916    
917     return true;
918     }
919     }
920     }

  ViewVC Help
Powered by ViewVC