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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1734 - (show annotations) (download)
Sun May 4 18:40:13 2008 UTC (15 years, 11 months ago) by iliev
File size: 29542 byte(s)
* bugfix: JSampler took forever to load a configuration with
  too many sampler channels
* Implemented option to show different channel view when
  the mouse pointer is over sampler channel
  (choose Edit/Preferences, then click the `Defaults' tab)

1 /*
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 if added using {@link org.jsampler.CC#scheduleTask}.
144 * @see org.jsampler.CC#addTask
145 */
146 public boolean
147 equals(Object obj) {
148 if(obj == null) return false;
149 if(!(obj instanceof GetDrectories)) return false;
150 String d = ((GetDrectories)obj).getDirectory();
151 if(getDirectory() == null) {
152 return d == null;
153 }
154 if(!getDirectory().equals(d)) return false;
155
156 return true;
157 }
158 }
159
160
161 /**
162 * This task retrieves information about a directory.
163 */
164 public static class GetDrectory extends EnhancedTask<DbDirectoryInfo> {
165 private String dir;
166
167 /**
168 * Creates a new instance of <code>GetDrectory</code>.
169 * @param dir The absolute path name of the directory.
170 */
171 public
172 GetDrectory(String dir) {
173 setTitle("InstrumentsDb.GetDrectory_task");
174 setDescription(i18n.getMessage("InstrumentsDb.GetDrectory.desc"));
175 this.dir = dir;
176 }
177
178 /** The entry point of the task. */
179 public void
180 run() {
181 try { setResult(CC.getClient().getDbDirectoryInfo(dir)); }
182 catch(Exception x) {
183 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
184 CC.getLogger().log(Level.FINE, getErrorMessage(), x);
185 }
186 }
187 }
188
189 /**
190 * This task creates a new directory.
191 */
192 public static class CreateDirectory extends EnhancedTask {
193 private String dir;
194
195 /**
196 * Creates a new instance of <code>CreateDirectory</code>.
197 * @param dir The absolute path name of the directory to add.
198 */
199 public
200 CreateDirectory(String dir) {
201 setTitle("InstrumentsDb.CreateDirectory_task");
202 setDescription(i18n.getMessage("InstrumentsDb.CreateDirectory.desc"));
203 this.dir = dir;
204 }
205
206 /** The entry point of the task. */
207 public void
208 run() {
209 try { CC.getClient().addDbDirectory(dir); }
210 catch(Exception x) {
211 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
212 CC.getLogger().log(Level.FINE, getErrorMessage(), x);
213 }
214 }
215 }
216
217 /**
218 * This task renames the specified directory.
219 */
220 public static class RenameDirectory extends EnhancedTask {
221 private String dir;
222 private String newName;
223
224 /**
225 * Creates a new instance of <code>RenameDirectory</code>.
226 * @param dir The absolute path name of the directory to rename.
227 * @param newName The new name for the specified directory.
228 */
229 public
230 RenameDirectory(String dir, String newName) {
231 setTitle("InstrumentsDb.RenameDirectory_task");
232 setDescription(i18n.getMessage("InstrumentsDb.RenameDirectory.desc"));
233 this.dir = dir;
234 this.newName = newName;
235 }
236
237 /** The entry point of the task. */
238 public void
239 run() {
240 try { CC.getClient().renameDbDirectory(dir, newName); }
241 catch(Exception x) {
242 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
243 CC.getLogger().log(Level.FINE, getErrorMessage(), x);
244 }
245 }
246 }
247
248 /**
249 * This task changes the description of a directory.
250 */
251 public static class SetDirectoryDescription extends EnhancedTask {
252 private String dir;
253 private String desc;
254
255 /**
256 * Creates a new instance of <code>SetDirectoryDescription</code>.
257 * @param dir The absolute path name of the directory.
258 * @param desc The new description for the directory.
259 */
260 public
261 SetDirectoryDescription(String dir, String desc) {
262 setTitle("InstrumentsDb.SetDirectoryDescription_task");
263 String s = i18n.getMessage("InstrumentsDb.SetDirectoryDescription.desc");
264 setDescription(s);
265 this.dir = dir;
266 this.desc = desc;
267 }
268
269 /** The entry point of the task. */
270 public void
271 run() {
272 try { CC.getClient().setDbDirectoryDescription(dir, desc); }
273 catch(Exception x) {
274 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
275 CC.getLogger().log(Level.FINE, getErrorMessage(), x);
276 }
277 }
278 }
279
280 /**
281 * This task removes the specified directories.
282 */
283 public static class RemoveDirectories extends EnhancedTask {
284 private DbDirectoryInfo[] directories;
285
286 /**
287 * Creates a new instance of <code>RemoveDirectories</code>.
288 * @param directories The directories to remove.
289 */
290 public
291 RemoveDirectories(DbDirectoryInfo[] directories) {
292 setTitle("InstrumentsDb.RemoveDirectories_task");
293 setDescription(i18n.getMessage("InstrumentsDb.RemoveDirectories.desc"));
294 this.directories = directories;
295 }
296
297 /** The entry point of the task. */
298 public void
299 run() {
300 try {
301 removeDirectories();
302 } catch(Exception x) {
303 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
304 setErrorDetails(x);
305 CC.getLogger().log(Level.FINE, getErrorMessage(), x);
306 }
307 }
308
309 private void
310 removeDirectories() throws Exception {
311 if(directories == null || directories.length == 0) return;
312 if(directories.length == 1) {
313 String path = directories[0].getDirectoryPath();
314 CC.getClient().removeDbDirectory(path, true);
315 } else {
316 String[] dirs = new String[directories.length];
317 for(int i = 0; i < directories.length; i++) {
318 dirs[i] = directories[i].getDirectoryPath();
319 }
320
321 CC.getClient().removeDbDirectories(dirs, true);
322 }
323 }
324 }
325
326 /**
327 * This task finds all directories in the specified directory
328 * that corresponds to the provided search criterias.
329 */
330 public static class FindDirectories extends EnhancedTask<DbDirectoryInfo[]> {
331 private String dir;
332 private DbSearchQuery query;
333
334 /**
335 * Creates a new instance of <code>FindDirectories</code>.
336 * @param dir The absolute path name of the directory.
337 * @param query Provides the search criterias.
338 */
339 public
340 FindDirectories(String dir, DbSearchQuery query) {
341 setTitle("InstrumentsDb.FindDirectories_task");
342 setDescription(i18n.getMessage("InstrumentsDb.FindDirectories.desc"));
343 this.dir = dir;
344 this.query = query;
345 }
346
347 /** The entry point of the task. */
348 public void
349 run() {
350 try { setResult(CC.getClient().findDbDirectories(dir, query)); }
351 catch(Exception x) {
352 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
353 CC.getLogger().log(Level.FINE, getErrorMessage(), x);
354 }
355 }
356 }
357
358 /**
359 * This task retrieves the list of instruments in the specified directory.
360 */
361 public static class GetInstruments extends EnhancedTask<DbInstrumentInfo[]> {
362 private String dir;
363
364 /**
365 * Creates a new instance of <code>GetInstruments</code>.
366 * @param dir The absolute path name of the directory.
367 */
368 public
369 GetInstruments(String dir) {
370 setTitle("InstrumentsDb.GetInstruments_task");
371 setDescription(i18n.getMessage("InstrumentsDb.GetInstruments.desc"));
372 this.dir = dir;
373 }
374
375 /** The entry point of the task. */
376 public void
377 run() {
378 try { setResult(CC.getClient().getDbInstruments(dir)); }
379 catch(Exception x) {
380 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
381 setErrorDetails(x);
382 CC.getLogger().log(Level.FINE, getErrorMessage(), x);
383 }
384 }
385
386 public String
387 getDirectory() { return dir; }
388
389 /**
390 * Used to decrease the traffic. All task in the queue
391 * equal to this are removed if added using {@link org.jsampler.CC#scheduleTask}.
392 * @see org.jsampler.CC#addTask
393 */
394 public boolean
395 equals(Object obj) {
396 if(obj == null) return false;
397 if(!(obj instanceof GetInstruments)) return false;
398 String d = ((GetInstruments)obj).getDirectory();
399 if(getDirectory() == null) {
400 return d == null;
401 }
402 if(!getDirectory().equals(d)) return false;
403 return true;
404 }
405 }
406
407 /**
408 * This task retrieves information about an instrument.
409 */
410 public static class GetInstrument extends EnhancedTask<DbInstrumentInfo> {
411 private String instr;
412
413 /**
414 * Creates a new instance of <code>GetInstrument</code>.
415 * @param instr The absolute path name of the instrument.
416 */
417 public
418 GetInstrument(String instr) {
419 setTitle("InstrumentsDb.GetInstrument_task");
420 setDescription(i18n.getMessage("InstrumentsDb.GetInstrument.desc"));
421 this.instr = instr;
422 }
423
424 /** The entry point of the task. */
425 public void
426 run() {
427 try { setResult(CC.getClient().getDbInstrumentInfo(instr)); }
428 catch(Exception x) {
429 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
430 CC.getLogger().log(Level.FINE, getErrorMessage(), x);
431 }
432 }
433 }
434
435 /**
436 * This task finds all instruments in the specified directory
437 * that corresponds to the provided search criterias.
438 */
439 public static class FindInstruments extends EnhancedTask<DbInstrumentInfo[]> {
440 private String dir;
441 private DbSearchQuery query;
442
443 /**
444 * Creates a new instance of <code>FindInstruments</code>.
445 * @param dir The absolute path name of the directory.
446 * @param query Provides the search criterias.
447 */
448 public
449 FindInstruments(String dir, DbSearchQuery query) {
450 setTitle("InstrumentsDb.FindInstruments_task");
451 setDescription(i18n.getMessage("InstrumentsDb.FindInstruments.desc"));
452 this.dir = dir;
453 this.query = query;
454 }
455
456 /** The entry point of the task. */
457 public void
458 run() {
459 try { setResult(CC.getClient().findDbInstruments(dir, query)); }
460 catch(Exception x) {
461 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
462 CC.getLogger().log(Level.FINE, getErrorMessage(), x);
463 }
464 }
465 }
466
467 /**
468 * This task renames the specified instrument.
469 */
470 public static class RenameInstrument extends EnhancedTask {
471 private String instr;
472 private String newName;
473
474 /**
475 * Creates a new instance of <code>RenameInstrument</code>.
476 * @param instr The absolute path name of the instrument to rename.
477 * @param newName The new name for the specified instrument.
478 */
479 public
480 RenameInstrument(String instr, String newName) {
481 setTitle("InstrumentsDb.RenameInstrument_task");
482 setDescription(i18n.getMessage("InstrumentsDb.RenameInstrument.desc"));
483 this.instr = instr;
484 this.newName = newName;
485 }
486
487 /** The entry point of the task. */
488 public void
489 run() {
490 try { CC.getClient().renameDbInstrument(instr, newName); }
491 catch(Exception x) {
492 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
493 CC.getLogger().log(Level.FINE, getErrorMessage(), x);
494 }
495 }
496 }
497
498 /**
499 * This task changes the description of an instrument.
500 */
501 public static class SetInstrumentDescription extends EnhancedTask {
502 private String instr;
503 private String desc;
504
505 /**
506 * Creates a new instance of <code>SetInstrumentDescription</code>.
507 * @param instr The absolute path name of the instrument.
508 * @param desc The new description for the instrument.
509 */
510 public
511 SetInstrumentDescription(String instr, String desc) {
512 setTitle("InstrumentsDb.SetInstrumentDescription_task");
513 String s = i18n.getMessage("InstrumentsDb.SetInstrumentDescription.desc");
514 setDescription(s);
515 this.instr = instr;
516 this.desc = desc;
517 }
518
519 /** The entry point of the task. */
520 public void
521 run() {
522 try { CC.getClient().setDbInstrumentDescription(instr, desc); }
523 catch(Exception x) {
524 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
525 CC.getLogger().log(Level.FINE, getErrorMessage(), x);
526 }
527 }
528 }
529
530 /**
531 * This task removes the specified instruments.
532 */
533 public static class RemoveInstruments extends EnhancedTask {
534 private DbInstrumentInfo[] instruments;
535
536 /**
537 * Creates a new instance of <code>RemoveInstruments</code>.
538 * @param instruments The instruments to remove.
539 */
540 public
541 RemoveInstruments(DbInstrumentInfo[] instruments) {
542 setTitle("InstrumentsDb.RemoveInstruments_task");
543 setDescription(i18n.getMessage("InstrumentsDb.RemoveInstruments.desc"));
544 this.instruments = instruments;
545 }
546
547 /** The entry point of the task. */
548 public void
549 run() {
550 try {
551 removeInstruments();
552 } catch(Exception x) {
553 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
554 setErrorDetails(x);
555 CC.getLogger().log(Level.FINE, getErrorMessage(), x);
556 }
557 }
558
559 private void
560 removeInstruments() throws Exception {
561 if(instruments == null || instruments.length == 0) return;
562 if(instruments.length == 1) {
563 String path = instruments[0].getInstrumentPath();
564 CC.getClient().removeDbInstrument(path);
565 } else {
566 String[] instrs = new String[instruments.length];
567 for(int i = 0; i < instruments.length; i++) {
568 instrs[i] = instruments[i].getInstrumentPath();
569 }
570
571 CC.getClient().removeDbInstruments(instrs);
572 }
573 }
574 }
575
576 /**
577 * This task adds instruments from an instrument file to the instruments database.
578 */
579 public static class AddInstrumentsFromFile extends EnhancedTask<Integer> {
580 private String dbDir;
581 private String filePath;
582 private int instrIndex;
583
584 /**
585 * Creates a new instance of <code>AddInstrumentsFromFile</code>.
586 * @param dbDir The absolute path name of the database directory
587 * in which all instruments from the specified instrument file will be added.
588 * @param filePath The absolute path name of the instrument file.
589 */
590 public
591 AddInstrumentsFromFile(String dbDir, String filePath) {
592 this(dbDir, filePath, -1);
593 }
594
595 /**
596 * Creates a new instance of <code>AddInstrumentsFromFile</code>.
597 * @param dbDir The absolute path name of the database directory
598 * in which the specified instrument will be added.
599 * @param filePath The absolute path name of the instrument file.
600 * @param instrIndex The index of the instrument
601 * (in the given instrument file) to add. If -1 is specified, all
602 * instruments in the given instrument file will be added.
603 */
604 public
605 AddInstrumentsFromFile(String dbDir, String filePath, int instrIndex) {
606 setTitle("InstrumentsDb.AddInstrumentsFromFile_task");
607 String s = i18n.getMessage("InstrumentsDb.AddInstrumentsFromFile.desc");
608 setDescription(s);
609 this.dbDir = dbDir;
610 this.filePath = filePath;
611 this.instrIndex = instrIndex;
612 }
613
614 /** The entry point of the task. */
615 public void
616 run() {
617 try {
618 int i;
619 if(instrIndex != -1) {
620 i = CC.getClient().addDbInstrument (
621 dbDir, filePath, instrIndex, true
622 );
623 } else {
624 i = CC.getClient().addDbInstruments(dbDir, filePath, true);
625 }
626
627 setResult(i);
628 } catch(Exception x) {
629 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
630 CC.getLogger().log(Level.FINE, getErrorMessage(), x);
631 }
632 }
633 }
634
635 /**
636 * This task adds instruments from a directory to the instruments database.
637 */
638 public static class AddInstruments extends EnhancedTask<Integer> {
639 private String dbDir;
640 private String fsDir;
641 private boolean flat;
642
643 /**
644 * Creates a new instance of <code>AddInstruments</code>.
645 * @param dbDir The absolute path name of the database directory
646 * in which all instruments from the specified directory will be added.
647 * @param fsDir The absolute path name of the file system directory.
648 */
649 public
650 AddInstruments(String dbDir, String fsDir) {
651 this(dbDir, fsDir, false);
652 }
653
654 /**
655 * Creates a new instance of <code>AddInstruments</code>.
656 * @param dbDir The absolute path name of the database directory
657 * in which all instruments from the specified directory will be added.
658 * @param fsDir The absolute path name of the file system directory.
659 * @param flat If <code>true</code>, the respective subdirectory structure
660 * will not be re-created in the supplied database directory.
661 */
662 public
663 AddInstruments(String dbDir, String fsDir, boolean flat) {
664 setTitle("InstrumentsDb.AddInstruments_task");
665 String s = i18n.getMessage("InstrumentsDb.AddInstruments.desc");
666 setDescription(s);
667 this.dbDir = dbDir;
668 this.fsDir = fsDir;
669 this.flat = flat;
670 }
671
672 /** The entry point of the task. */
673 public void
674 run() {
675 try {
676 int i;
677 if(flat) {
678 i = CC.getClient().addDbInstruments (
679 ScanMode.FLAT, dbDir, fsDir, true
680 );
681 } else {
682 i = CC.getClient().addDbInstruments (
683 ScanMode.RECURSIVE, dbDir, fsDir, true
684 );
685 }
686
687 setResult(i);
688 }
689 catch(Exception x) {
690 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
691 CC.getLogger().log(Level.FINE, getErrorMessage(), x);
692 }
693 }
694 }
695
696 /**
697 * This task adds instruments from a file system directory (excluding
698 * the instruments in the subdirectories) to the instruments database.
699 */
700 public static class AddInstrumentsNonrecursive extends EnhancedTask<Integer> {
701 private String dbDir;
702 private String fsDir;
703
704 /**
705 * Creates a new instance of <code>AddInstrumentsNonrecursive</code>.
706 * @param dbDir The absolute path name of the database directory
707 * in which the instruments from the specified directory (excluding
708 * the instruments in the subdirectories) will be added.
709 * @param fsDir The absolute path name of the file system directory.
710 */
711 public
712 AddInstrumentsNonrecursive(String dbDir, String fsDir) {
713 setTitle("InstrumentsDb.AddInstrumentsNonrecursive_task");
714 String s = i18n.getMessage("InstrumentsDb.AddInstrumentsNonrecursive.desc");
715 setDescription(s);
716 this.dbDir = dbDir;
717 this.fsDir = fsDir;
718 }
719
720 /** The entry point of the task. */
721 public void
722 run() {
723 try {
724 int i = CC.getClient().addDbInstruments (
725 ScanMode.NON_RECURSIVE, dbDir, fsDir, true
726 );
727
728 setResult(i);
729 }
730 catch(Exception x) {
731 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
732 CC.getLogger().log(Level.FINE, getErrorMessage(), x);
733 }
734 }
735 }
736
737 /**
738 * This task moves the specified instruments
739 * and directories to the specified location.
740 */
741 public static class Move extends EnhancedTask {
742 private DbDirectoryInfo[] directories;
743 private DbInstrumentInfo[] instruments;
744 private String dest;
745
746 /**
747 * Creates a new instance of <code>Move</code>.
748 * @param directories The directories to move.
749 * @param instruments The instruments to move.
750 * @param dest The absolute path name of the directory where
751 * the specified instruments and directories will be moved to.
752 */
753 public
754 Move(DbDirectoryInfo[] directories, DbInstrumentInfo[] instruments, String dest) {
755 setTitle("InstrumentsDb.Move_task");
756 setDescription(i18n.getMessage("InstrumentsDb.Move.desc"));
757 this.directories = directories;
758 this.instruments = instruments;
759 this.dest = dest;
760 }
761
762 /** The entry point of the task. */
763 public void
764 run() {
765 try {
766 moveInstruments();
767 moveDirectories();
768 } catch(Exception x) {
769 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
770 setErrorDetails(x);
771 CC.getLogger().log(Level.FINE, getErrorMessage(), x);
772 }
773 }
774
775 private void
776 moveInstruments() throws Exception {
777 if(instruments == null || instruments.length == 0) return;
778 if(instruments.length == 1) {
779 String path = instruments[0].getInstrumentPath();
780 CC.getClient().moveDbInstrument(path, dest);
781 } else {
782 String[] instrs = new String[instruments.length];
783 for(int i = 0; i < instruments.length; i++) {
784 instrs[i] = instruments[i].getInstrumentPath();
785 }
786
787 CC.getClient().moveDbInstruments(instrs, dest);
788 }
789 }
790
791 private void
792 moveDirectories() throws Exception {
793 if(directories == null || directories.length == 0) return;
794 if(directories.length == 1) {
795 String path = directories[0].getDirectoryPath();
796 CC.getClient().moveDbDirectory(path, dest);
797 } else {
798 String[] dirs = new String[directories.length];
799 for(int i = 0; i < directories.length; i++) {
800 dirs[i] = directories[i].getDirectoryPath();
801 }
802
803 CC.getClient().moveDbDirectories(dirs, dest);
804 }
805 }
806 }
807
808 /**
809 * This task copies the specified instruments
810 * and directories to the specified location.
811 */
812 public static class Copy extends EnhancedTask {
813 private DbDirectoryInfo[] directories;
814 private DbInstrumentInfo[] instruments;
815 private String dest;
816
817 /**
818 * Creates a new instance of <code>Copy</code>.
819 * @param directories The directories to copy.
820 * @param instruments The instruments to copy.
821 * @param dest The absolute path name of the directory where
822 * the specified instruments and directories will be copied to.
823 */
824 public
825 Copy(DbDirectoryInfo[] directories, DbInstrumentInfo[] instruments, String dest) {
826 setTitle("InstrumentsDb.Copy_task");
827 setDescription(i18n.getMessage("InstrumentsDb.Copy.desc"));
828 this.directories = directories;
829 this.instruments = instruments;
830 this.dest = dest;
831 }
832
833 /** The entry point of the task. */
834 public void
835 run() {
836 try {
837 copyInstruments();
838 copyDirectories();
839 } catch(Exception x) {
840 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
841 setErrorDetails(x);
842 CC.getLogger().log(Level.FINE, getErrorMessage(), x);
843 }
844 }
845
846 private void
847 copyInstruments() throws Exception {
848 if(instruments == null || instruments.length == 0) return;
849 if(instruments.length == 1) {
850 String path = instruments[0].getInstrumentPath();
851 CC.getClient().copyDbInstrument(path, dest);
852 } else {
853 String[] instrs = new String[instruments.length];
854 for(int i = 0; i < instruments.length; i++) {
855 instrs[i] = instruments[i].getInstrumentPath();
856 }
857
858 CC.getClient().copyDbInstruments(instrs, dest);
859 }
860 }
861
862 private void
863 copyDirectories() throws Exception {
864 if(directories == null || directories.length == 0) return;
865 if(directories.length == 1) {
866 String path = directories[0].getDirectoryPath();
867 CC.getClient().copyDbDirectory(path, dest);
868 } else {
869 String[] dirs = new String[directories.length];
870 for(int i = 0; i < directories.length; i++) {
871 dirs[i] = directories[i].getDirectoryPath();
872 }
873
874 CC.getClient().copyDbDirectories(dirs, dest);
875 }
876 }
877 }
878
879 /**
880 * This task gets a list of all instrument files in the database
881 * that that doesn't exist in the filesystem.
882 */
883 public static class FindLostInstrumentFiles extends EnhancedTask<String[]> {
884
885 /**
886 * Creates a new instance of <code>FindLostInstrumentFiles</code>.
887 */
888 public
889 FindLostInstrumentFiles() {
890 setTitle("InstrumentsDb.FindLostInstrumentFiles_task");
891 setDescription(i18n.getMessage("InstrumentsDb.FindLostInstrumentFiles.desc"));
892 }
893
894 /** The entry point of the task. */
895 public void
896 run() {
897 try { setResult(CC.getClient().findLostDbInstrumentFiles()); }
898 catch(Exception x) {
899 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
900 CC.getLogger().log(Level.FINE, getErrorMessage(), x);
901 }
902 }
903 }
904
905 /**
906 * This task substitutes all occurrences of the specified instrument file
907 * in the database, with the specified new path.
908 */
909 public static class SetInstrumentFilePath extends EnhancedTask {
910 private String oldPath;
911 private String newPath;
912
913 /**
914 * Creates a new instance of <code>SetInstrumentFilePath</code>.
915 * @param oldPath The absolute path name of the instrument file to substitute.
916 * @param newPath The new absolute path name.
917 */
918 public
919 SetInstrumentFilePath(String oldPath, String newPath) {
920 setTitle("InstrumentsDb.SetInstrumentFilePath_task");
921 setDescription(i18n.getMessage("InstrumentsDb.SetInstrumentFilePath.desc"));
922 this.oldPath = oldPath;
923 this.newPath = newPath;
924 }
925
926 /** The entry point of the task. */
927 public void
928 run() {
929 try { CC.getClient().setDbInstrumentFilePath(oldPath, newPath); }
930 catch(Exception x) {
931 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
932 CC.getLogger().log(Level.FINE, getErrorMessage(), x);
933 }
934 }
935 }
936
937 /**
938 * This task retrieves information about a scan job.
939 */
940 public static class GetScanJobInfo extends EnhancedTask<ScanJobInfo> {
941 private int jobId;
942
943 /**
944 * Creates a new instance of <code>GetScanJobInfo</code>.
945 * @param jobId The ID of the scan job.
946 */
947 public
948 GetScanJobInfo(int jobId) {
949 setTitle("InstrumentsDb.GetScanJobInfo_task");
950 setDescription(i18n.getMessage("InstrumentsDb.GetScanJobInfo.desc"));
951 this.jobId = jobId;
952 }
953
954 /** The entry point of the task. */
955 public void
956 run() {
957 try { setResult(CC.getClient().getDbInstrumentsJobInfo(jobId)); }
958 catch(Exception x) {
959 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
960 CC.getLogger().log(Level.FINE, getErrorMessage(), x);
961 }
962 }
963
964 public int
965 getJobId() { return jobId; }
966
967 /**
968 * Used to decrease the traffic. All task in the queue
969 * equal to this are removed if added using {@link org.jsampler.CC#scheduleTask}.
970 * @see org.jsampler.CC#addTask
971 */
972 public boolean
973 equals(Object obj) {
974 if(obj == null) return false;
975 if(!(obj instanceof GetScanJobInfo)) return false;
976 if(((GetScanJobInfo)obj).getJobId() != getJobId()) return false;
977
978 return true;
979 }
980 }
981
982 /**
983 * This task formats the instruments database.
984 */
985 public static class Format extends EnhancedTask {
986 /**
987 * Formats the instruments database..
988 */
989 public
990 Format() {
991 setTitle("InstrumentsDb.Format_task");
992 String s = i18n.getMessage("InstrumentsDb.Format.desc");
993 setDescription(s);
994 }
995
996 /** The entry point of the task. */
997 public void
998 run() {
999 try { CC.getClient().formatInstrumentsDb(); }
1000 catch(Exception x) {
1001 setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
1002 CC.getLogger().log(Level.FINE, getErrorMessage(), x);
1003 }
1004 }
1005 }
1006 }

  ViewVC Help
Powered by ViewVC