Source Code Cross Referenced for JoinMainPanel.java in  » IDE-Netbeans » etl.project » org » netbeans » modules » sql » framework » ui » view » join » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » etl.project » org.netbeans.modules.sql.framework.ui.view.join 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:        package org.netbeans.modules.sql.framework.ui.view.join;
042:
043:        import java.awt.BorderLayout;
044:        import java.awt.Color;
045:        import java.awt.Component;
046:        import java.awt.Dimension;
047:        import java.awt.GridBagConstraints;
048:        import java.awt.GridBagLayout;
049:        import java.awt.Insets;
050:        import java.net.URL;
051:        import java.util.ArrayList;
052:        import java.util.Collection;
053:        import java.util.List;
054:
055:        import javax.swing.BorderFactory;
056:        import javax.swing.DefaultListCellRenderer;
057:        import javax.swing.ImageIcon;
058:        import javax.swing.JLabel;
059:        import javax.swing.JList;
060:        import javax.swing.JPanel;
061:        import javax.swing.JSeparator;
062:        import javax.swing.JSplitPane;
063:        import javax.swing.JTabbedPane;
064:        import javax.swing.ListModel;
065:        import javax.swing.ListSelectionModel;
066:        import javax.swing.event.ChangeEvent;
067:        import javax.swing.event.ChangeListener;
068:        import javax.swing.event.ListDataEvent;
069:        import javax.swing.event.ListDataListener;
070:
071:        import org.netbeans.modules.sql.framework.model.SQLJoinOperator;
072:        import org.netbeans.modules.sql.framework.model.SQLJoinView;
073:        import org.netbeans.modules.sql.framework.model.SourceTable;
074:        import org.netbeans.modules.sql.framework.ui.graph.IGraphView;
075:        import org.netbeans.modules.sql.framework.ui.view.TableColumnTreePanel;
076:        import org.openide.DialogDisplayer;
077:        import org.openide.NotifyDescriptor;
078:        import net.java.hulp.i18n.Logger;
079:        import org.netbeans.modules.etl.logger.Localizer;
080:        import org.netbeans.modules.etl.logger.LogUtil;
081:        import org.netbeans.modules.sql.framework.model.DBTable;
082:
083:        /**
084:         * This is the main join configuration view, where user selects table to join and can see
085:         * the preview of the join, can define join order and can select columns to appear in join
086:         * view in the canvas.
087:         * 
088:         * @author radval
089:         */
090:        public class JoinMainPanel extends JPanel {
091:
092:            private static final String LOG_CATEGORY = JoinMainPanel.class
093:                    .getName();
094:            private static transient final Logger mLogger = LogUtil
095:                    .getLogger(JoinMainPanel.class.getName());
096:            private static transient final Localizer mLoc = Localizer.get();
097:            private ListTransferPanel listPanel;
098:            private JTabbedPane bottomTabPane;
099:            private JSplitPane splitPane;
100:            private JoinPreviewPanel previewPanel;
101:            private TableColumnTreePanel tableColumnPanel;
102:            private Collection sources = new ArrayList();
103:            private Collection<DBTable> targets = new ArrayList<DBTable>();
104:            private URL tableImgUrl = getClass()
105:                    .getResource(
106:                            "/org/netbeans/modules/sql/framework/ui/resources/images/SourceTable.png");
107:            private SQLJoinView initialJoinView;
108:            private SQLJoinView copiedJoinView;
109:            private IGraphView mainGraphView;
110:            private transient boolean refreshPreview = true;
111:            private transient boolean showInstruction = true;
112:            private boolean isReordering = false;
113:
114:            /** Creates a new instance of JoinMainPanel */
115:            public JoinMainPanel(IGraphView aGraphView) {
116:                this (aGraphView, true);
117:            }
118:
119:            /**
120:             * Creates a new instance of JoinMainPanel associated with the given IGraphView
121:             * instance, toggling whether to display the instruction label based on the value of
122:             * <code>displayInstruction</code>.
123:             * 
124:             * @param graphView IGraphView instance to associate with this new instance
125:             * @param displayInstruction true if instruction label should be displayed; false
126:             *        otherwise
127:             */
128:            public JoinMainPanel(IGraphView graphView,
129:                    boolean displayInstruction) {
130:                this .mainGraphView = graphView;
131:                showInstruction = displayInstruction;
132:                initGUI();
133:            }
134:
135:            public JoinMainPanel(Collection joinSources) {
136:                this .sources = joinSources;
137:                initGUI();
138:
139:            }
140:
141:            private void initGUI() {
142:                // initialize and layout all the components here
143:                this .setLayout(new BorderLayout());
144:                splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
145:                splitPane.setOneTouchExpandable(true);
146:                this .add(splitPane, BorderLayout.CENTER);
147:
148:                GridBagLayout l = new GridBagLayout();
149:
150:                GridBagConstraints gc = new GridBagConstraints();
151:                gc.weightx = 1.0;
152:                gc.weighty = 1.0;
153:                gc.fill = GridBagConstraints.BOTH;
154:                gc.gridwidth = GridBagConstraints.REMAINDER;
155:
156:                JPanel mainTopPanel = new JPanel();
157:                mainTopPanel.setLayout(l);
158:                splitPane.setTopComponent(mainTopPanel);
159:
160:                // initialize a panel which will contain list transfer panel
161:                // and more table button
162:                JPanel topPanel = new JPanel();
163:                topPanel.setMinimumSize(new Dimension(150, 215));
164:
165:                topPanel.setLayout(new BorderLayout());
166:
167:                mainTopPanel.add(topPanel, gc);
168:
169:                // Initialize the join instruction label.
170:                if (showInstruction) {
171:                    JPanel labelPnl = new JPanel();
172:                    labelPnl.setLayout(new BorderLayout());
173:
174:                    String nbBundle1 = mLoc
175:                            .t("PRSR001: Select which tables you would like to join.");
176:                    JLabel joinLabel = new JLabel(Localizer.parse(nbBundle1));
177:                    joinLabel.getAccessibleContext().setAccessibleName(
178:                            Localizer.parse(nbBundle1));
179:
180:                    labelPnl.add(joinLabel, BorderLayout.NORTH);
181:                    labelPnl.add(new JSeparator(), BorderLayout.SOUTH);
182:                    labelPnl.setBorder(BorderFactory.createEmptyBorder(0, 0,
183:                            10, 0));
184:
185:                    topPanel.add(labelPnl, BorderLayout.NORTH);
186:                }
187:
188:                // initialize list transfer panel
189:                String nbBundle2 = mLoc.t("PRSR001: Available Tables:");
190:                String nbBundle3 = mLoc.t("PRSR001: Selected Tables:");
191:                listPanel = new ListTransferPanel(this , Localizer
192:                        .parse(nbBundle2), Localizer.parse(nbBundle3), sources,
193:                        targets);
194:
195:                // set the target list to allow continuous selection for up and down purpose
196:                listPanel.getDestinationJList().setSelectionMode(
197:                        ListSelectionModel.SINGLE_INTERVAL_SELECTION);
198:
199:                // add a listener to listen for updates in list model so that
200:                // preview panel can be refreshed.
201:                listPanel.getDestinationJList().getModel().addListDataListener(
202:                        new TargetListDataListener());
203:                // set the list cell renderer
204:                listPanel.setSourceListCellRenderer(new SourceListRenderer());
205:                listPanel
206:                        .setDestinationListCellRenderer(new TargetListRenderer());
207:
208:                listPanel.getListTransferModel().addChangeListener(
209:                        new ListTransferChangeListener());
210:
211:                topPanel.add(listPanel, BorderLayout.CENTER);
212:
213:                // initialize bottom tab panel
214:                bottomTabPane = new JTabbedPane();
215:                bottomTabPane.setBorder(BorderFactory.createEmptyBorder(5, 0,
216:                        0, 0));
217:                gc.weighty = 1.0;
218:
219:                splitPane.setBottomComponent(bottomTabPane);
220:
221:                // initalize join preview panel which is the first tab
222:                previewPanel = new JoinPreviewPanel(this );
223:                String nbBundle4 = mLoc.t("PRSR001: Preview");
224:                previewPanel.setName(Localizer.parse(nbBundle4));
225:                previewPanel.getAccessibleContext().setAccessibleName(
226:                        Localizer.parse(nbBundle4));
227:                // initialize select table column panel
228:                tableColumnPanel = new TableColumnTreePanel(new ArrayList());
229:                String nbBundle5 = mLoc.t("PRSR001: Select Columns");
230:                tableColumnPanel.setName(Localizer.parse(nbBundle5));
231:
232:                // add these above two panel as tabs to bottom tab panel
233:                bottomTabPane.add(previewPanel);
234:                bottomTabPane.add(tableColumnPanel);
235:            }
236:
237:            private List<DBTable> getJoinSourceTables() {
238:                List<DBTable> tables = new ArrayList<DBTable>();
239:
240:                if (this .copiedJoinView != null) {
241:                    SQLJoinOperator op = this .copiedJoinView.getRootJoin();
242:                    if (op != null) {
243:                        tables = JoinUtility.getJoinSourceTables(op);
244:                    } else {
245:                        tables = this .copiedJoinView.getSourceTables();
246:                    }
247:                }
248:
249:                return tables;
250:            }
251:
252:            public void setTargetList(Collection<DBTable> tList) {
253:                if (tList != null) {
254:                    this .targets = tList;
255:                    listPanel.enableButton(false);
256:                    listPanel.setDestinationList(tList);
257:                }
258:            }
259:
260:            public List getTargetList() {
261:                return listPanel.getDestinationList();
262:            }
263:
264:            public void setSourceList(Collection sList) {
265:                if (sList != null) {
266:                    this .sources = sList;
267:                    listPanel.setSourceList(sList);
268:                }
269:            }
270:
271:            public List getSourceList() {
272:                return listPanel.getSourceList();
273:            }
274:
275:            public void setDividerLocation() {
276:                Dimension d = this .getSize();
277:                int divLocation = d.height * 1 / 2;
278:                splitPane.setDividerLocation(divLocation);
279:                splitPane.setResizeWeight(0.5);
280:            }
281:
282:            public void setDividerLocation(int divLocation) {
283:                splitPane.setDividerLocation(divLocation);
284:                splitPane.setResizeWeight(0.5);
285:            }
286:
287:            public void setPreviewModifiable(boolean b) {
288:                this .previewPanel.setModifiable(b);
289:            }
290:
291:            public void reset(IGraphView mainView) {
292:                this .mainGraphView = mainView;
293:
294:                listPanel.reset();
295:                previewPanel.reset(mainView);
296:                tableColumnPanel.setTables(listPanel.getDestinationList());
297:            }
298:
299:            private void refreshPanels(ListDataEvent e) {
300:                if (!refreshPreview) {
301:                    return;
302:                }
303:                List<DBTable> currentList = listPanel.getDestinationList();
304:
305:                if (isReordering) {
306:                    previewPanel.refresh(currentList);
307:
308:                } else {
309:
310:                    ListModel model = listPanel.getDestinationJList()
311:                            .getModel();
312:                    int startIdx = e.getIndex0();
313:                    int endIdx = e.getIndex1();
314:
315:                    for (int i = startIdx; i <= endIdx; i++) {
316:                        SourceTable sTable = (SourceTable) model
317:                                .getElementAt(i);
318:                        previewPanel.refresh(sTable);
319:                    }
320:                    tableColumnPanel.setTables(currentList);
321:                }
322:            }
323:
324:            private void removeTable(SourceTable sTable, int index) {
325:                previewPanel.removeTable(sTable);
326:                List<DBTable> currentList = listPanel.getDestinationList();
327:                ArrayList<Object> sTables = new ArrayList<Object>();
328:                // index is in the index of already removed table
329:                // if index is zero then we want to recreate all the joins again
330:                // other wise we will preserver joins created among tables before index
331:                if (index != 0) {
332:                    for (int i = index; i < currentList.size(); i++) {
333:                        sTables.add(currentList.get(i));
334:                    }
335:                    previewPanel.createJoin(sTables);
336:                } else {
337:                    previewPanel.refresh(currentList);
338:                }
339:
340:                tableColumnPanel.setTables(currentList);
341:            }
342:
343:            class SourceListRenderer extends DefaultListCellRenderer {
344:
345:                /**
346:                 * Return a component that has been configured to display the specified value.
347:                 * That component's <code>paint</code> method is then called to "render" the
348:                 * cell. If it is necessary to compute the dimensions of a list because the list
349:                 * cells do not have a fixed size, this method is called to generate a component
350:                 * on which <code>getPreferredSize</code> can be invoked.
351:                 * 
352:                 * @param list The JList we're painting.
353:                 * @param value The value returned by list.getModel().getElementAt(index).
354:                 * @param index The cells index.
355:                 * @param isSelected True if the specified cell was selected.
356:                 * @param cellHasFocus True if the specified cell has the focus.
357:                 * @return A component whose paint() method will render the specified value.
358:                 * @see JList
359:                 * @see ListSelectionModel
360:                 * @see ListModel
361:                 */
362:                @Override
363:                public Component getListCellRendererComponent(JList list,
364:                        Object value, int index, boolean isSelected,
365:                        boolean cellHasFocus) {
366:
367:                    JLabel renderer = (JLabel) super 
368:                            .getListCellRendererComponent(list, value, index,
369:                                    isSelected, cellHasFocus);
370:
371:                    if (value instanceof  SourceTable) {
372:                        renderer.setText(((SourceTable) value)
373:                                .getQualifiedName());
374:                        renderer.setIcon(new ImageIcon(tableImgUrl));
375:                    }
376:
377:                    return renderer;
378:                }
379:            }
380:
381:            class TargetListRenderer extends DefaultListCellRenderer {
382:
383:                /**
384:                 * Return a component that has been configured to display the specified value.
385:                 * That component's <code>paint</code> method is then called to "render" the
386:                 * cell. If it is necessary to compute the dimensions of a list because the list
387:                 * cells do not have a fixed size, this method is called to generate a component
388:                 * on which <code>getPreferredSize</code> can be invoked.
389:                 * 
390:                 * @param list The JList we're painting.
391:                 * @param value The value returned by list.getModel().getElementAt(index).
392:                 * @param index The cells index.
393:                 * @param isSelected True if the specified cell was selected.
394:                 * @param cellHasFocus True if the specified cell has the focus.
395:                 * @return A component whose paint() method will render the specified value.
396:                 * @see JList
397:                 * @see ListSelectionModel
398:                 * @see ListModel
399:                 */
400:                @Override
401:                public Component getListCellRendererComponent(JList list,
402:                        Object value, int index, boolean isSelected,
403:                        boolean cellHasFocus) {
404:
405:                    JLabel renderer = (JLabel) super 
406:                            .getListCellRendererComponent(list, value, index,
407:                                    isSelected, cellHasFocus);
408:
409:                    JPanel cellRenderer = new JPanel();
410:                    cellRenderer.setLayout(new GridBagLayout());
411:                    GridBagConstraints gc = new GridBagConstraints();
412:                    gc.weightx = 0.0;
413:                    gc.weighty = 1.0;
414:                    gc.fill = GridBagConstraints.BOTH;
415:                    gc.gridwidth = GridBagConstraints.RELATIVE;
416:                    // gc.insets = new Insets(0, 5, 0, 5);
417:
418:                    JLabel numLabel = new JLabel(" " + (++index) + " ");
419:                    // numLabel.setSize(16, 16);
420:                    numLabel.setBackground(Color.blue);
421:                    numLabel.setBorder(BorderFactory.createCompoundBorder(
422:                            BorderFactory.createLineBorder(Color.black),
423:                            BorderFactory.createEmptyBorder(0, 2, 0, 2)));
424:
425:                    cellRenderer.add(numLabel, gc);
426:
427:                    if (value instanceof  SourceTable) {
428:                        gc.weightx = 1.0;
429:                        gc.weighty = 1.0;
430:                        gc.gridwidth = GridBagConstraints.REMAINDER;
431:                        gc.insets = new Insets(0, 2, 0, 0);
432:
433:                        renderer.setText(((SourceTable) value)
434:                                .getQualifiedName());
435:                        renderer.setIcon(new ImageIcon(tableImgUrl));
436:                        cellRenderer.add(renderer, gc);
437:                        return cellRenderer;
438:                    }
439:
440:                    return renderer;
441:                }
442:            }
443:
444:            void moveUp() {
445:                if (!previewPanel.checkForUserDefinedCondition()) {
446:                    return;
447:                }
448:
449:                JList destList = JoinMainPanel.this .listPanel
450:                        .getDestinationJList();
451:                int[] selectedIdxs = destList.getSelectedIndices();
452:
453:                // if selected index is 0 then it can not be moved up any further
454:                if (selectedIdxs.length == 0 || selectedIdxs[0] == 0) {
455:                    return;
456:                }
457:
458:                ListModel model = destList.getModel();
459:
460:                ArrayList<Object> newOrderedList = new ArrayList<Object>();
461:
462:                int cumulativeElmCount = 0;
463:
464:                // first add all the elements except the one before the first selected element to
465:                // newOrderedList
466:                for (int i = 0; i < model.getSize(); i++) {
467:                    // check if i is not the one before the first selected element
468:                    if (i == selectedIdxs[0] - 1) {
469:                        break;
470:                    }
471:                    newOrderedList.add(model.getElementAt(i));
472:                    cumulativeElmCount++;
473:                }
474:
475:                int[] newSelectedIdxs = new int[selectedIdxs.length];
476:
477:                // Now add all the selected elements
478:                for (int i = 0; i < selectedIdxs.length; i++) {
479:                    int idx = selectedIdxs[i];
480:
481:                    // if selected index is 0 then it can not be moved up any further
482:                    newOrderedList.add(model.getElementAt(idx));
483:                    newSelectedIdxs[i] = newOrderedList.indexOf(model
484:                            .getElementAt(idx));
485:                }
486:
487:                // Now first add the element which was one before the first selected element
488:                if (selectedIdxs[0] - 1 >= 0) {
489:                    newOrderedList.add(model.getElementAt(selectedIdxs[0] - 1));
490:                    cumulativeElmCount++;
491:                }
492:
493:                // then add all the element after the last selection element
494:                for (int i = selectedIdxs[selectedIdxs.length - 1] + 1; i < model
495:                        .getSize(); i++) {
496:                    // check if i is not the one before the first selected element
497:                    if (i == selectedIdxs[0] - 1) {
498:                        break;
499:                    }
500:                    newOrderedList.add(model.getElementAt(i));
501:                }
502:
503:                isReordering = true;
504:                // now set new collection in the destination list
505:                JoinMainPanel.this .listPanel.setDestinationList(newOrderedList);
506:
507:                destList.setSelectedIndices(newSelectedIdxs);
508:
509:                isReordering = false;
510:            }
511:
512:            void moveDown() {
513:                if (!previewPanel.checkForUserDefinedCondition()) {
514:                    return;
515:                }
516:
517:                JList destList = JoinMainPanel.this .listPanel
518:                        .getDestinationJList();
519:                ListModel model = destList.getModel();
520:
521:                int[] selectedIdxs = destList.getSelectedIndices();
522:
523:                // if selected index is last item then it can not be moved down any further
524:                if (selectedIdxs.length == 0
525:                        || selectedIdxs[selectedIdxs.length - 1] == model
526:                                .getSize() - 1) {
527:                    return;
528:                }
529:
530:                ArrayList<Object> newOrderedList = new ArrayList<Object>();
531:
532:                int cumulativeElmCount = 0;
533:
534:                // first add all the elements except the one before the first selected element to
535:                // newOrderedList
536:                for (int i = 0; i < model.getSize(); i++) {
537:                    // check if i is not the one before the first selected element
538:                    if (i == selectedIdxs[0]) {
539:                        break;
540:                    }
541:                    newOrderedList.add(model.getElementAt(i));
542:                    cumulativeElmCount++;
543:                }
544:
545:                // Now add the element which was one after the last selected element
546:                newOrderedList
547:                        .add(model
548:                                .getElementAt(selectedIdxs[selectedIdxs.length - 1] + 1));
549:                cumulativeElmCount++;
550:
551:                int[] newSelectedIdxs = new int[selectedIdxs.length];
552:
553:                // Now add all the selected elements
554:                for (int i = 0; i < selectedIdxs.length; i++) {
555:                    int idx = selectedIdxs[i];
556:
557:                    // if selected index is 0 then it can not be moved up any further
558:                    newOrderedList.add(model.getElementAt(idx));
559:                    newSelectedIdxs[i] = newOrderedList.indexOf(model
560:                            .getElementAt(idx));
561:                }
562:
563:                // then add all the element after the last selection element
564:                for (int i = selectedIdxs[selectedIdxs.length - 1] + 2; i < model
565:                        .getSize(); i++) {
566:                    newOrderedList.add(model.getElementAt(i));
567:                }
568:
569:                isReordering = true;
570:                // now set new collection in the destination list
571:                JoinMainPanel.this .listPanel.setDestinationList(newOrderedList);
572:
573:                destList.setSelectedIndices(newSelectedIdxs);
574:                isReordering = false;
575:            }
576:
577:            class TargetListDataListener implements  ListDataListener {
578:
579:                /**
580:                 * Sent when the contents of the list has changed in a way that's too complex to
581:                 * characterize with the previous methods. For example, this is sent when an item
582:                 * has been replaced. Index0 and index1 bracket the change.
583:                 * 
584:                 * @param e a <code>ListDataEvent</code> encapsulating the event information
585:                 */
586:                public void contentsChanged(ListDataEvent e) {
587:                    // refreshPanels(e);
588:                }
589:
590:                /**
591:                 * Sent after the indices in the index0,index1 interval have been inserted in the
592:                 * data model. The new interval includes both index0 and index1.
593:                 * 
594:                 * @param e a <code>ListDataEvent</code> encapsulating the event information
595:                 */
596:                public void intervalAdded(ListDataEvent e) {
597:                    refreshPanels(e);
598:                }
599:
600:                /**
601:                 * Sent after the indices in the index0,index1 interval have been removed from the
602:                 * data model. The interval includes both index0 and index1.
603:                 * 
604:                 * @param e a <code>ListDataEvent</code> encapsulating the event information
605:                 */
606:                public void intervalRemoved(ListDataEvent e) {
607:                    // refreshPanels(e);
608:                }
609:            }
610:
611:            class ListTransferChangeListener implements  ChangeListener {
612:
613:                /**
614:                 * Invoked when the target of the listener has changed its state.
615:                 * 
616:                 * @param e a ChangeEvent object
617:                 */
618:                public void stateChanged(ChangeEvent e) {
619:                    if (e instanceof  ListTransferPanel.TransferEvent) {
620:                        ListTransferPanel.TransferEvent tev = (ListTransferPanel.TransferEvent) e;
621:                        if (tev.getType() == ListTransferPanel.TransferEvent.REMOVED) {
622:                            SourceTable sTable = (SourceTable) tev.getItem();
623:                            removeTable(sTable, tev.getItemIndex());
624:                        }
625:                    }
626:                }
627:            }
628:
629:            public SQLJoinView getSQLJoinView() {
630:                return this .previewPanel.getSQLJoinView();
631:            }
632:
633:            public SQLJoinView getInitialSQLJoinView() {
634:                return this .initialJoinView;
635:            }
636:
637:            public void setSQLJoinView(SQLJoinView jView) {
638:                try {
639:                    this .initialJoinView = jView;
640:                    this .copiedJoinView = (SQLJoinView) jView.cloneSQLObject();
641:
642:                    this .targets = getJoinSourceTables();
643:                    this .previewPanel.setSQLJoinView(this .copiedJoinView);
644:                    tableColumnPanel.setTables(new ArrayList<DBTable>(targets));
645:
646:                    // setDestinationList will again refresh preview which we don't want
647:                    refreshPreview = false;
648:                    this .listPanel.setDestinationList(this .targets);
649:                    refreshPreview = true;
650:
651:                } catch (CloneNotSupportedException ex) {
652:                    mLogger.errorNoloc(mLoc.t(
653:                            "PRSR179: cannot clone existing SQLJoinView{0}",
654:                            LOG_CATEGORY), ex);
655:                    DialogDisplayer.getDefault().notify(
656:                            new NotifyDescriptor.Message(
657:                                    "Join View model is corrupted. "
658:                                            + ex.getMessage(),
659:                                    NotifyDescriptor.ERROR_MESSAGE));
660:
661:                    return;
662:                }
663:            }
664:
665:            public void setEditSQLJoinView(SourceTable sTable, SQLJoinView jView) {
666:                try {
667:                    this .initialJoinView = jView;
668:                    this .copiedJoinView = (SQLJoinView) jView.cloneSQLObject();
669:                    this .targets = new ArrayList<DBTable>();
670:                    List<DBTable> joinSources = getJoinSourceTables();
671:                    this .targets.addAll(joinSources);
672:                    this .targets.add(sTable);
673:
674:                    this .previewPanel.setSQLJoinView(this .copiedJoinView);
675:                    tableColumnPanel.setTables(new ArrayList<DBTable>(targets));
676:
677:                    // setDestinationList will again refresh preview which we don't want for
678:                    // the tables of exsting join view
679:                    refreshPreview = false;
680:                    this .listPanel.setDestinationList(joinSources);
681:                    refreshPreview = true;
682:
683:                    // now we want to add the new table to destination list and also want preview
684:                    // to be refreshed
685:                    this .listPanel.addToDestination(sTable);
686:
687:                } catch (CloneNotSupportedException ex) {
688:                    mLogger.errorNoloc(mLoc.t(
689:                            "PRSR180: Join View model is corrupted.{0}{1}", ex
690:                                    .getMessage(),
691:                            NotifyDescriptor.ERROR_MESSAGE), ex);
692:                    DialogDisplayer.getDefault().notify(
693:                            new NotifyDescriptor.Message(
694:                                    "Join View model is corrupted. "
695:                                            + ex.getMessage(),
696:                                    NotifyDescriptor.ERROR_MESSAGE));
697:
698:                    return;
699:                }
700:            }
701:
702:            public List getTableColumnNodes() {
703:                return this .tableColumnPanel.getTableColumnNodes();
704:            }
705:
706:            public ListTransferPanel getListTransferPanel() {
707:                return this .listPanel;
708:            }
709:
710:            public IGraphView getMainGraphView() {
711:                return this .mainGraphView;
712:            }
713:
714:            public void handleCancel() {
715:                this.listPanel.removeMoreTablesOnCancel();
716:            }
717:        }
w_w___w._j__a__v_a2___s.___c__o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.