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

Quick Search    Search Deep

Source code: medi/swing/util/MediTreeNodeLinker.java


1   /*
2    * MediTreeNodeLinker.java
3    *
4    * Created on 28 settembre 2002, 10.39
5       Medi - A media archiver. Archives media files for easy management.
6       Copyright (C) 2002  Antonio Petrelli
7   
8       This program is free software; you can redistribute it and/or modify
9       it under the terms of the GNU General Public License as published by
10      the Free Software Foundation; either version 2 of the License, or
11      (at your option) any later version.
12  
13      This program is distributed in the hope that it will be useful,
14      but WITHOUT ANY WARRANTY; without even the implied warranty of
15      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16      GNU General Public License for more details.
17  
18      You should have received a copy of the GNU General Public License
19      along with this program; if not, write to the Free Software
20      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  
22      Contact me at: brenmcguire@users.sourceforge.net
23   */
24  
25  package medi.swing.util;
26  
27  import javatools.db.*;
28  import medi.base.Provider;
29  
30  /** It is a class containing only static methods, to be used to link
31   * <CODE>MediTreeNode</CODE>'s between themselves.
32   * @author Antonio Petrelli
33   * @version 0.1.2
34   */
35  public class MediTreeNodeLinker {
36      
37      /** Creates a new instance of MediTreeNodeLinker */
38      public MediTreeNodeLinker() {
39      }
40      
41      /** Sets the provider to use.
42       * @param pPrv The provider to use.
43       */    
44      public static void setProvider (Provider pPrv) {
45          prv = pPrv;
46      }
47      
48      /** Links two nodes.
49       * @param father The node to attach the son into.
50       * @param son The node to be pasted.
51       * @throws DbException If something goes wrong.
52       */    
53      public static void link(MediTreeNode father, MediTreeNode son) throws DbException {
54          String fatherType, sonType;
55          Object[] fatherID, sonID, newID;
56          
57          fatherType = father.getType();
58          if (fatherType == null)
59              fatherType = "";
60          sonType = son.getType();
61          if (sonType == null)
62              sonType = "";
63          fatherID = father.getID();
64          sonID = son.getID();
65          if (fatherType.equals("Container") && sonType.equals("Volume"))
66              prv.moveLinkVolumeToContainer((Integer) fatherID[0], (Integer) sonID[0]);
67          else if (fatherType.equals("Volume") && sonType.equals("Session"))
68              prv.moveLinkSessionToFatherSession((Integer) sonID[0], (Integer) sonID[1], (Integer) fatherID[0],
69                  null);
70          else if (fatherType.equals("Session")) {
71              if (sonType.equals("Session")) {
72                  newID = new Object[2];
73                  newID[0] = fatherID[0];
74                  newID[1] = prv.moveLinkSessionToFatherSession((Integer) sonID[0], (Integer) sonID[1],
75                      (Integer) fatherID[0], (Integer) fatherID[1]);
76                  son.setID(newID);
77              }
78              else if (sonType.equals("Data"))
79                  prv.linkDataToSession((Long) sonID[0], (Integer) fatherID[0], (Integer) fatherID[1]);
80          }
81          else if (fatherType.equals("GenreRoot") && sonType.equals("Genre"))
82              prv.moveLinkParentGenre((Integer) sonID[0], null);
83          else if (fatherType.equals("Genre")) {
84              if (sonType.equals("Genre"))
85                  prv.moveLinkParentGenre((Integer) sonID[0], (Integer) fatherID[0]);
86              else if (sonType.equals("Data"))
87                  prv.linkDataToGenre((Long) sonID[0], (Integer) fatherID[0]);
88          }
89          else if (fatherType.equals("Author") && sonType.equals("Data"))
90              prv.linkDataToAuthor((Long) sonID[0], (Integer) fatherID[0]);
91          else if (fatherType.equals("Editor") && sonType.equals("Data"))
92              prv.linkDataToEditor((Long) sonID[0], (Integer) fatherID[0]);
93          else if ((fatherType.equals("FileType") ||
94              fatherType.equals("DataFileTypeContainer")) &&
95              sonType.equals("Data"))
96              prv.linkDataToFileType((Long) sonID[0], (Integer) fatherID[0]);
97          else if ((fatherType.equals("FileType") ||
98              fatherType.equals("ProgramFileTypeContainer")) &&
99              sonType.equals("Program"))
100             prv.linkFileTypeToProgram((Integer) fatherID[0], (Long) sonID[0], new Integer(0));
101         else if (fatherType.equals("Program") && sonType.equals("FileType"))
102             prv.linkFileTypeToProgram((Integer) sonID[0], (Long) fatherID[0], new Integer(0));
103         else if (fatherType.equals("DataSet") && sonType.equals("Data"))
104             prv.linkDataToDataSet((Long) sonID[0], (Long) fatherID[0]);
105     }
106     
107     /** Removes a link between two nodes.
108      * @param father The node from which the son is going to be removed.
109      * @param son The node to be removed from the father.
110      * @throws DbException If something goes wrong.
111      */    
112     public static void unlink(MediTreeNode father, MediTreeNode son) throws DbException {
113         String fatherType, sonType;
114         Object[] fatherID, sonID, newID;
115         
116         fatherType = father.getType();
117         if (fatherType == null)
118             fatherType = "";
119         sonType = son.getType();
120         if (sonType == null)
121             sonType = "";
122         fatherID = father.getID();
123         sonID = son.getID();
124         if (fatherType.equals("Session") && sonType.equals("Data"))
125             prv.unlinkDataFromSession((Long) sonID[0], (Integer) fatherID[0], (Integer) fatherID[1]);
126         else if (fatherType.equals("Genre") && sonType.equals("Data"))
127             prv.unlinkDataFromGenre((Long) sonID[0], (Integer) fatherID[1]);
128         else if (fatherType.equals("Author") && sonType.equals("Data"))
129             prv.unlinkDataFromAuthor((Long) sonID[0], (Integer) fatherID[0]);
130         else if (fatherType.equals("Editor") && sonType.equals("Data"))
131             prv.unlinkDataFromEditor((Long) sonID[0], (Integer) fatherID[0]);
132         else if ((fatherType.equals("FileType") ||
133             fatherType.equals("ProgramFileTypeContainer")) &&
134             sonType.equals("Program"))
135             prv.unlinkFileTypeFromProgram((Integer) fatherID[0], (Long) sonID[0]);
136         else if (fatherType.equals("Program") && sonType.equals("FileType"))
137             prv.unlinkFileTypeFromProgram((Integer) sonID[0], (Long) fatherID[0]);
138         else if (fatherType.equals("DataSet") && sonType.equals("Data"))
139             prv.unlinkDataFromDataSet((Long) sonID[0], (Long) fatherID[0]);
140     }
141     
142     private static Provider prv;
143 }