JavaDoc


001    /**
002     * Copyright (c) 2003 Daffodil Software Ltd all rights reserved,
003     * Modifications Copyright (c) 2008 Regiscope Digital Imaging Co, LLC, All rights reserved.
004     * This program is free software; you can redistribute it and/or modify
005     * it under the terms of version 2 of the GNU General Public License as
006     * published by the Free Software Foundation.
007     * There are special exceptions to the terms and conditions of the GPL
008     * as it is applied to this software. See the GNU General Public License for more details.
009     *
010     * This program is distributed in the hope that it will be useful,
011     * but WITHOUT ANY WARRANTY; without even the implied warranty of
012     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013     * GNU General Public License for more details.
014     *
015     * You should have received a copy of the GNU General Public License
016     * along with this program; if not, write to the Free Software
017     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018     */
019    
020    package org.dbreplicator.repconsole;
021    
022    import org.dbreplicator.replication.DBHandler.AbstractDataBaseHandler;
023    import javax.swing.border.TitledBorder;
024    import javax.swing.tree.DefaultMutableTreeNode;
025    import javax.swing.tree.DefaultTreeModel;
026    import org.dbreplicator.replication._ReplicationServer;
027    import org.dbreplicator.replication._Publication;
028    import javax.swing.border.Border;
029    import java.awt.Frame;
030    import javax.swing.border.EtchedBorder;
031    import java.awt.Color;
032    import java.awt.Rectangle;
033    import java.awt.SystemColor;
034    import java.util.ArrayList;
035    import javax.swing.*;
036    import java.awt.event.*;
037    import javax.swing.DefaultListModel;
038    
039    public class SelectTableToBreakCycle
040        extends JDialog
041        implements FocusListener, KeyListener {
042      JPanel panel1 = new JPanel();
043      JButton jButton_Select = new JButton();
044      JButton jButtonDeselect = new JButton();
045    
046      DefaultListModel dlmCyclicTables = new DefaultListModel();
047      JList jListCyclicTables = new JList(dlmCyclicTables);
048    
049      DefaultListModel dlmSelect = new DefaultListModel();
050      JList jListSelectedTables = new JList(dlmSelect);
051    
052      JLabel jLabel1 = new JLabel();
053      String pubName, conflictResolver;
054      _ReplicationServer repServer;
055      _Publication pub;
056      AbstractDataBaseHandler dbh;
057    
058      JButton jButtonOK = new JButton();
059      JButton jButton3 = new JButton();
060      JButton jButtonCancel = new JButton();
061      JDialog createPublication;
062      DefaultTreeModel defaultTreeModel;
063      DefaultMutableTreeNode pubRootNode;
064      JLabel jLabel2 = new JLabel();
065      JEditorPane help = new JEditorPane();
066      JScrollPane jscrollpane_td;
067      JScrollPane jscrollpane_st;
068      Border border1;
069      TitledBorder titledBorder1;
070      TitledBorder titledBorder2;
071      Border border2;
072      ArrayList tablesinCycle = new ArrayList();
073      ArrayList selectedBreakCycleRelation = new ArrayList();
074      JScrollPane jScrollPane1 = new JScrollPane();
075      DefaultListModel dlmSelectedCyclicRelation = new DefaultListModel();
076      JList jList1 = new JList();
077    
078      public SelectTableToBreakCycle(Frame frame, String title,ArrayList selectedBreakCycleRelation0, boolean modal) {
079        super(frame, title, modal);
080        try {
081          selectedBreakCycleRelation = selectedBreakCycleRelation0;
082          jbInit();
083          pack();
084        }
085        catch (Exception ex) {
086          JOptionPane.showMessageDialog(this, ex, "Error Message",
087                                        JOptionPane.ERROR_MESSAGE);
088          return;
089        }
090    
091      }
092    
093      public SelectTableToBreakCycle(DefaultTreeModel defaultTreeModel,
094                                     DefaultMutableTreeNode pubRootNode,
095                                     String pubName,
096                                     _ReplicationServer repServer,
097                                     String conflictResolver,
098                                     JDialog createPublication,
099                                     ArrayList tablesinCycle,
100                                     ArrayList selectedBreakCycleRelation0) {
101    
102        this(StartRepServer.getMainFrame(),
103             "Select Table To Break Cycle In Relation",selectedBreakCycleRelation0, true);
104        this.pubName = pubName;
105        this.repServer = repServer;
106        this.conflictResolver = conflictResolver;
107        this.createPublication = createPublication;
108        this.defaultTreeModel = defaultTreeModel;
109        this.pubRootNode = pubRootNode;
110        this.tablesinCycle = tablesinCycle;
111    
112        initListWithDatabaseTablesForCreate();
113      }
114    
115      private void jbInit() throws Exception {
116        border1 = BorderFactory.createEmptyBorder();
117        titledBorder1 = new TitledBorder("");
118        titledBorder2 = new TitledBorder("");
119        border2 = new EtchedBorder(EtchedBorder.RAISED, Color.white,
120                                   new Color(148, 145, 140));
121        panel1.setLayout(null);
122    
123        jButton_Select.setBounds(new Rectangle(238, 99, 52, 22));
124        jButton_Select.setEnabled(true);
125        jButton_Select.setFont(new java.awt.Font("Dialog", 1, 15));
126        jButton_Select.setText(">>");
127        jButton_Select.addActionListener(new
128                                         SelectTable_jButton_Select_actionAdapter(this));
129        jButtonDeselect.setBounds(new Rectangle(239, 129, 52, 22));
130        jButtonDeselect.setFont(new java.awt.Font("Dialog", 1, 15));
131        jButtonDeselect.setText("<<");
132        jButtonDeselect.addActionListener(new
133                                          SelectTable_jButtonDeselect_actionAdapter(this));
134        jListCyclicTables.setFont(new java.awt.Font("Dialog", 0, 12));
135    
136        jListCyclicTables.addFocusListener(this);
137        jListSelectedTables.addFocusListener(this);
138    
139        jListSelectedTables.setFont(new java.awt.Font("Dialog", 0, 12));
140    
141        jLabel1.setFont(new java.awt.Font("Serif", 3, 25));
142        jLabel1.setForeground(SystemColor.infoText);
143        jLabel1.setText("Select relations to be suppressed to break cycle");
144        jLabel1.setBounds(new Rectangle(15, 5, 494, 27));
145    
146        jButtonOK.setBounds(new Rectangle(178, 291, 81, 26));
147        jButtonOK.setEnabled(true);
148        jButtonOK.setFont(new java.awt.Font("Dialog", 1, 12));
149        jButtonOK.setFocusPainted(true);
150        jButtonOK.setText("OK");
151        jButtonOK.addActionListener(new SelectTable_jButtonOK_actionAdapter(this));
152    
153        jButtonCancel.setBounds(new Rectangle(274, 291, 81, 26));
154        jButtonCancel.setFont(new java.awt.Font("Dialog", 1, 12));
155        jButtonCancel.setFocusPainted(true);
156        jButtonCancel.setText("Cancel");
157        jButtonCancel.addActionListener(new SelectTable_jButtonCancel_actionAdapter(this));
158    
159        jLabel2.setFont(new java.awt.Font("Dialog", 1, 11));
160        jLabel2.setBorder(border2);
161        jLabel2.setText("");
162        jLabel2.setBounds(new Rectangle(15, 39, 503, 168));
163    
164        help.setBackground(UIManager.getColor("Button.background"));
165        help.setForeground(SystemColor.infoText);
166        help.setEnabled(true);
167        help.setFont(new java.awt.Font("Dialog", 2, 12));
168        help.setDoubleBuffered(false);
169        help.setRequestFocusEnabled(false);
170        help.setDisabledTextColor(Color.black);
171        help.setEditable(false);
172        help.setText("Already Selected relations to be suppressed to break cycle,if any");
173    
174        help.setBounds(new Rectangle(14, 210, 385, 22));
175    
176        jscrollpane_td = new JScrollPane(jListCyclicTables);
177        jscrollpane_td.setFont(new java.awt.Font("Dialog", 1, 11));
178        jscrollpane_td.setBounds(new Rectangle(19, 48, 210, 153));
179    
180        jscrollpane_st = new JScrollPane(jListSelectedTables);
181        jscrollpane_st.setBounds(new Rectangle(300, 49, 210, 153));
182    
183        titledBorder2.setTitleFont(new java.awt.Font("Dialog", 0, 12));
184        titledBorder1.setTitleFont(new java.awt.Font("Dialog", 0, 12));
185        jScrollPane1.setBounds(new Rectangle(21, 235, 497, 35));
186    
187        jList1.setEnabled(false);
188        jList1.setModel(dlmSelectedCyclicRelation);
189    //   System.out.println("selectedBreakCycleRelation size:"+selectedBreakCycleRelation.size());
190          for (int i = 0; i < selectedBreakCycleRelation.size(); i++) {
191    //        System.out.println("selectedBreakCycleRelation:"+selectedBreakCycleRelation.get(i));
192            dlmSelectedCyclicRelation.addElement(selectedBreakCycleRelation.get(i));
193          }
194    
195    
196        getContentPane().add(panel1);
197    
198        panel1.add(jLabel1, null);
199        panel1.add(jButtonOK, null);
200        panel1.add(jButtonCancel, null);
201        panel1.add(jscrollpane_td);
202        panel1.add(jscrollpane_st);
203        panel1.add(jButton_Select, null);
204        panel1.add(jLabel2, null);
205        panel1.add(jButtonDeselect, null);
206        panel1.add(help, null);
207        panel1.add(jScrollPane1, null);
208        jScrollPane1.getViewport().add(jList1, null);
209    
210        //    jListDatabaseTables.grabFocus();
211    
212        jscrollpane_st.setBorder(new TitledBorder("Selected Relations"));
213        jscrollpane_td.setBorder(new TitledBorder(
214            "Relations having cycle in publication"));
215      }
216    
217      void initListWithDatabaseTablesForCreate() {
218        jListCyclicTables.setAutoscrolls(true);
219        for (int i = 0; i < tablesinCycle.size(); i++) {
220          if(!selectedBreakCycleRelation.contains(tablesinCycle.get(i)))
221          dlmCyclicTables.addElement(tablesinCycle.get(i));
222        }
223      }
224    
225      /**
226       * keyPressed
227       *
228       * @param e KeyEvent
229       */
230      public void keyPressed(KeyEvent e) {
231      }
232    
233      /**
234       * keyReleased
235       *
236       * @param e KeyEvent
237       */
238      public void keyReleased(KeyEvent e) {
239      }
240    
241      /**
242       * keyTyped
243       *
244       * @param e KeyEvent
245       */
246      public void keyTyped(KeyEvent e) {
247      }
248    
249      /**
250       * focusGained
251       *
252       * @param e FocusEvent
253       */
254      public void focusGained(FocusEvent e) {
255      }
256    
257      /**
258       * focusLost
259       *
260       * @param e FocusEvent
261       */
262      public void focusLost(FocusEvent e) {
263      }
264    
265      class SelectTable_jButtonCancel_actionAdapter
266          implements java.awt.event.ActionListener {
267        SelectTableToBreakCycle adaptee;
268    
269        SelectTable_jButtonCancel_actionAdapter(SelectTableToBreakCycle adaptee) {
270          this.adaptee = adaptee;
271        }
272    
273        public void actionPerformed(ActionEvent e) {
274          adaptee.jButtonCancel_actionPerformed(e);
275        }
276      }
277    
278      void jButtonCancel_actionPerformed(ActionEvent e) {
279        hide();
280      }
281    
282      class SelectTable_jButtonOK_actionAdapter
283          implements java.awt.event.ActionListener {
284        SelectTableToBreakCycle adaptee;
285    
286        SelectTable_jButtonOK_actionAdapter(SelectTableToBreakCycle adaptee) {
287          this.adaptee = adaptee;
288        }
289    
290        public void actionPerformed(ActionEvent e) {
291          adaptee.jButtonOK_actionPerformed(e);
292        }
293      }
294    
295      void jButtonOK_actionPerformed(ActionEvent e) {
296        hide();
297      }
298    
299      class SelectTable_jButton_Select_actionAdapter
300          implements java.awt.event.ActionListener {
301        SelectTableToBreakCycle adaptee;
302    
303        SelectTable_jButton_Select_actionAdapter(SelectTableToBreakCycle adaptee) {
304          this.adaptee = adaptee;
305        }
306    
307        public void actionPerformed(ActionEvent e) {
308          adaptee.jButton_Select_actionPerformed(e);
309        }
310      }
311    
312      class SelectTable_jButtonDeselect_actionAdapter
313          implements java.awt.event.ActionListener {
314        SelectTableToBreakCycle adaptee;
315    
316        SelectTable_jButtonDeselect_actionAdapter(SelectTableToBreakCycle adaptee) {
317          this.adaptee = adaptee;
318        }
319    
320        public void actionPerformed(ActionEvent e) {
321          adaptee.jButtonDeselect_actionPerformed(e);
322        }
323      }
324    
325      void jButton_Select_actionPerformed(ActionEvent e) {
326        Object[] tableNames = jListCyclicTables.getSelectedValues();
327        for (int i = 0; i < tableNames.length; i++) {
328          String tableNameForPublishing = (String) tableNames[i];
329          if (! (tableNameForPublishing == null ||
330                 tableNameForPublishing.equalsIgnoreCase(""))) {
331            dlmCyclicTables.removeElement(tableNameForPublishing);
332            dlmSelect.addElement(tableNameForPublishing);
333          }
334        }
335      }
336    
337      void jButtonDeselect_actionPerformed(ActionEvent e) {
338        Object[] tableNames = jListSelectedTables.getSelectedValues();
339        for (int i = 0; i < tableNames.length; i++) {
340          String deselectTableNameForPublishing = (String) tableNames[i];
341          if (! (deselectTableNameForPublishing == null ||
342                 deselectTableNameForPublishing.equalsIgnoreCase(""))) {
343            dlmCyclicTables.addElement(deselectTableNameForPublishing);
344            dlmSelect.removeElement(deselectTableNameForPublishing);
345          }
346        }
347      }
348    
349      protected ArrayList getSelectedRelationToBreakCycle() {
350        int selectedNoOfTables = dlmSelect.getSize();
351    
352        if (selectedNoOfTables == 0) {
353          return new ArrayList();
354        }
355        ArrayList relationToBreakCycle = new ArrayList();
356        for (int i = 0; i < selectedNoOfTables; i++) {
357          relationToBreakCycle.add(dlmSelect.get(i));
358        }
359        return relationToBreakCycle;
360      }
361    
362    }





























































Powered by Drupal - Theme by Danger4k