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.graph;
042:
043: import java.awt.BorderLayout;
044: import java.awt.Dialog;
045: import java.awt.Point;
046: import java.awt.datatransfer.DataFlavor;
047: import java.awt.datatransfer.Transferable;
048: import java.awt.datatransfer.UnsupportedFlavorException;
049: import java.awt.dnd.DnDConstants;
050: import java.io.IOException;
051: import java.util.ArrayList;
052: import java.util.List;
053: import java.util.MissingResourceException;
054:
055: import javax.swing.BorderFactory;
056: import javax.swing.BoxLayout;
057: import javax.swing.ButtonGroup;
058: import javax.swing.JLabel;
059: import javax.swing.JPanel;
060: import javax.swing.JRadioButton;
061:
062: import org.netbeans.modules.sql.framework.common.utils.TagParserUtility;
063: import org.netbeans.modules.sql.framework.model.GUIInfo;
064: import org.netbeans.modules.sql.framework.model.SQLCanvasObject;
065: import org.netbeans.modules.sql.framework.model.SQLCastOperator;
066: import org.netbeans.modules.sql.framework.model.SQLConnectableObject;
067: import org.netbeans.modules.sql.framework.model.SQLConstants;
068: import org.netbeans.modules.sql.framework.model.SQLInputObject;
069: import org.netbeans.modules.sql.framework.model.SQLObject;
070: import org.netbeans.modules.sql.framework.model.SQLOperator;
071: import org.netbeans.modules.sql.framework.model.SQLOperatorArg;
072: import org.netbeans.modules.sql.framework.model.SQLPredicate;
073: import org.netbeans.modules.sql.framework.model.TargetColumn;
074: import org.netbeans.modules.sql.framework.model.VisibleSQLLiteral;
075: import org.netbeans.modules.sql.framework.model.impl.SQLCustomOperatorImpl;
076: import org.netbeans.modules.sql.framework.ui.graph.IGraphController;
077: import org.netbeans.modules.sql.framework.ui.graph.IGraphLink;
078: import org.netbeans.modules.sql.framework.ui.graph.IGraphNode;
079: import org.netbeans.modules.sql.framework.ui.graph.IGraphPort;
080: import org.netbeans.modules.sql.framework.ui.graph.IGraphView;
081: import org.netbeans.modules.sql.framework.ui.graph.IOperatorXmlInfo;
082: import org.netbeans.modules.sql.framework.ui.graph.impl.CustomOperatorNode;
083: import org.netbeans.modules.sql.framework.ui.model.SQLUIModel;
084: import org.openide.DialogDescriptor;
085: import org.openide.DialogDisplayer;
086: import org.openide.NotifyDescriptor;
087: import org.openide.nodes.Node;
088: import org.openide.windows.WindowManager;
089: import net.java.hulp.i18n.Logger;
090: import com.sun.sql.framework.exception.BaseException;
091: import org.netbeans.modules.etl.logger.Localizer;
092: import org.netbeans.modules.etl.logger.LogUtil;
093: import org.netbeans.modules.sql.framework.model.DBTable;
094: import org.netbeans.modules.sql.framework.model.DBTableCookie;
095:
096: /**
097: * @author Ritesh Adval
098: * @version $Revision$
099: */
100: public class SQLGraphController implements IGraphController {
101:
102: private static final String NETBEANS_NODE_MIMETYPE = "application/x-java-openide-nodednd; class=org.openide.nodes.Node";
103: private static final String LOG_CATEGORY = SQLGraphController.class
104: .getName();
105: private static transient final Logger mLogger = LogUtil
106: .getLogger(SQLGraphController.class.getName());
107: private static transient final Localizer mLoc = Localizer.get();
108: private static DataFlavor[] mDataFlavorArray = new DataFlavor[1];
109:
110: static {
111: try {
112: mDataFlavorArray[0] = new DataFlavor(NETBEANS_NODE_MIMETYPE);
113: } catch (ClassNotFoundException ex) {
114: ex.printStackTrace();
115: }
116: }
117: protected SQLUIModel collabModel;
118: protected IGraphView viewC;
119: private String srcParam = null;
120: private String destParam = null;
121: private transient int tableTypeSelected = SQLConstants.SOURCE_TABLE;
122:
123: /** Creates a new instance of SQLGraphController */
124: public SQLGraphController() {
125: }
126:
127: /**
128: * Handle drop.
129: *
130: * @param e DropTargetDropEvent
131: */
132: public void handleDrop(java.awt.dnd.DropTargetDropEvent e) {
133: if (!isEditAllowed()) {
134: return;
135: }
136:
137: Point loc = e.getLocation();
138: if (e.isDataFlavorSupported(mDataFlavorArray[0])) {
139: try {
140: Transferable t = e.getTransferable();
141: Object o = t.getTransferData(mDataFlavorArray[0]);
142: if (o instanceof Node) {
143: Node.Cookie tableCookie = ((Node) o)
144: .getCookie(DBTableCookie.class);
145: if (tableCookie != null) {
146: DBTable nodeTable = ((DBTableCookie) tableCookie)
147: .getDBTable();
148:
149: String dlgTitle = null;
150: String nbBundle1 = mLoc
151: .t("PRSR001: Add a table");
152: try {
153: dlgTitle = Localizer.parse(nbBundle1);
154: } catch (MissingResourceException mre) {
155: dlgTitle = "Add a table";
156: }
157:
158: // Recall and use most recently selected table type.
159: TypeSelectorPanel selectorPnl = new TypeSelectorPanel(
160: tableTypeSelected);
161: DialogDescriptor dlgDesc = new DialogDescriptor(
162: selectorPnl, dlgTitle, true,
163: NotifyDescriptor.OK_CANCEL_OPTION,
164: NotifyDescriptor.OK_OPTION,
165: DialogDescriptor.DEFAULT_ALIGN, null,
166: null);
167: Dialog dlg = DialogDisplayer.getDefault()
168: .createDialog(dlgDesc);
169: dlg
170: .getAccessibleContext()
171: .setAccessibleDescription(
172: "This dialog helps user to add a table");
173: dlg.setVisible(true);
174:
175: if (NotifyDescriptor.OK_OPTION == dlgDesc
176: .getValue()) {
177: tableTypeSelected = selectorPnl
178: .getSelectedType();
179: if (SQLConstants.SOURCE_TABLE == tableTypeSelected) {
180: collabModel.addSourceTable(nodeTable,
181: loc);
182: } else {
183: collabModel.addTargetTable(nodeTable,
184: loc);
185: }
186:
187: e
188: .acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
189: } else {
190: e.rejectDrop();
191: }
192: }
193: }
194: } catch (IOException ex) {
195: mLogger
196: .errorNoloc(
197: mLoc
198: .t(
199: "PRSR170: Caught IOException while handling DnD{0}",
200: LOG_CATEGORY), ex);
201:
202: e.rejectDrop();
203: } catch (UnsupportedFlavorException ex) {
204: mLogger
205: .errorNoloc(
206: mLoc
207: .t(
208: "PRSR171: Caught UnsupportedFlavorException while handling DnD{0}",
209: LOG_CATEGORY), ex);
210:
211: e.rejectDrop();
212: } catch (BaseException ex) {
213: DialogDisplayer.getDefault().notify(
214: new NotifyDescriptor.Message(ex
215: .getLocalizedMessage(),
216: NotifyDescriptor.WARNING_MESSAGE));
217: mLogger
218: .errorNoloc(
219: mLoc
220: .t(
221: "PRSR172: Caught BaseException while handling DnD{0}",
222: LOG_CATEGORY), ex);
223:
224: e.rejectDrop();
225: }
226: } else {
227: e.rejectDrop();
228: }
229: }
230:
231: /**
232: * Handle drop of arbitrary object.
233: *
234: * @param obj Object dropped onto canvas
235: */
236: public void handleObjectDrop(Object obj) {
237: if (!isEditAllowed()) {
238: return;
239: }
240: }
241:
242: /**
243: * handle new link
244: *
245: * @param from IGraphPort
246: * @param to IGraphPort
247: */
248: public void handleLinkAdded(IGraphPort from, IGraphPort to) {
249: if (!isEditAllowed()) {
250: return;
251: }
252:
253: IGraphNode srcGraphNode = null;
254: IGraphNode destGraphNode = null;
255:
256: srcGraphNode = from.getDataNode();
257: destGraphNode = to.getDataNode();
258:
259: if (srcGraphNode != null && destGraphNode != null
260: && srcGraphNode.equals(destGraphNode)) {
261: return;
262: }
263:
264: setParameters(from, to, srcGraphNode, destGraphNode);
265:
266: SQLCanvasObject srcObj = (SQLCanvasObject) srcGraphNode
267: .getDataObject();
268: SQLConnectableObject destObj = (SQLConnectableObject) destGraphNode
269: .getDataObject();
270:
271: if (srcObj == null && destObj == null) {
272: return;
273: }
274:
275: SQLInputObject inputObj = destObj.getInput(destParam);
276: SQLObject existing = (inputObj != null) ? inputObj
277: .getSQLObject() : null;
278: if (existing instanceof TargetColumn) {
279: existing = ((TargetColumn) existing).getValue();
280: }
281:
282: if (existing != null) {
283: return;
284: }
285:
286: try {
287: boolean userResponse = doTypeChecking(srcObj, destObj,
288: srcParam, destParam);
289:
290: if (srcObj != null && destObj != null && userResponse) {
291: collabModel.createLink(srcObj, srcParam, destObj,
292: destParam);
293: }
294: } catch (Exception sqle) {
295: NotifyDescriptor d = new NotifyDescriptor.Message(sqle
296: .toString(), NotifyDescriptor.INFORMATION_MESSAGE);
297: DialogDisplayer.getDefault().notify(d);
298: }
299: }
300:
301: private boolean doTypeChecking(SQLCanvasObject srcObj,
302: SQLConnectableObject destObj, String srcParam1,
303: String destParam1) throws BaseException {
304: // Ignore join for type checking purposes.
305: // if (srcObj.getObjectType() == SQLConstants.JOIN
306: // || destObj instanceof SQLJoinOperator) {
307: // return true;
308: // }
309:
310: String msg = null;
311: SQLObject input = srcObj;
312:
313: //get the specific sub object from srcObj which we are trying to link
314: input = srcObj.getOutput(srcParam1);
315: // Obtain SourceColumn (an SQLObject) if srcObj is a source table.
316: // if (srcObj.getObjectType() == SQLConstants.SOURCE_TABLE) {
317: // DBColumn srcColumn = ((SourceTable) srcObj).getColumn(srcParam1);
318: // if (srcColumn instanceof SourceColumn) {
319: // input = (SourceColumn) srcColumn;
320: // }
321: // }
322:
323: if (!destObj.isInputValid(destParam1, input)) {
324: try {
325: String srcObjType = TagParserUtility
326: .getDisplayStringFor(input.getObjectType());
327: String destObjType = TagParserUtility
328: .getDisplayStringFor(destObj.getObjectType());
329: String srcName = destObj.getDisplayName();
330:
331: if (srcName != null && destParam1 != null) {
332: String nbBundle2 = mLoc
333: .t(
334: "PRSR001: Cannot connect {0} to {1}-{2} at input {3}.",
335: srcObjType, destObjType, destObj
336: .getDisplayName(),
337: destParam1);
338: msg = Localizer.parse(nbBundle2);
339: } else {
340: String nbBundle3 = mLoc.t(
341: "PRSR001: Cannot connect {0} to {1}",
342: srcObjType, destObjType);
343: msg = Localizer.parse(nbBundle3);
344: }
345: } catch (Exception e) {
346: mLogger
347: .errorNoloc(
348: mLoc
349: .t(
350: "PRSR173: Caught Exception while resolving error message{0}",
351: LOG_CATEGORY), e);
352:
353: msg = "Cannot link these objects together.";
354: }
355:
356: NotifyDescriptor.Message m = new NotifyDescriptor.Message(
357: msg, NotifyDescriptor.ERROR_MESSAGE);
358:
359: DialogDisplayer.getDefault().notify(m);
360: return false;
361: }
362:
363: switch (destObj.isInputCompatible(destParam1, input)) {
364: case SQLConstants.TYPE_CHECK_INCOMPATIBLE:
365: try {
366: String nbBundle3 = mLoc
367: .t("PRSR001: Incompatible source and target datatypes.");
368: msg = Localizer.parse(nbBundle3);
369: } catch (MissingResourceException e) {
370: msg = "Incompatible source and target datatypes.";
371: }
372:
373: NotifyDescriptor.Message m = new NotifyDescriptor.Message(
374: msg, NotifyDescriptor.ERROR_MESSAGE);
375:
376: DialogDisplayer.getDefault().notify(m);
377: return false;
378:
379: case SQLConstants.TYPE_CHECK_DOWNCAST_WARNING:
380: try {
381: String nbBundle4 = mLoc
382: .t("PRSR001: Connecting these types may result in a loss of precision or data truncation. Continue?");
383: msg = Localizer.parse(nbBundle4);
384: } catch (MissingResourceException e) {
385: msg = "Connecting these datatypes may result in a loss of "
386: + "precision or data truncation in the target. Continue?";
387: }
388:
389: String title = null;
390: try {
391: String nbBundle5 = mLoc
392: .t("PRSR001: Datatype conversion");
393: title = Localizer.parse(nbBundle5);
394: } catch (MissingResourceException e) {
395: title = "Datatype conversion";
396: }
397:
398: NotifyDescriptor.Confirmation d = new NotifyDescriptor.Confirmation(
399: msg, title, NotifyDescriptor.OK_CANCEL_OPTION,
400: NotifyDescriptor.QUESTION_MESSAGE);
401:
402: return (DialogDisplayer.getDefault().notify(d) == NotifyDescriptor.OK_OPTION);
403:
404: case SQLConstants.TYPE_CHECK_COMPATIBLE:
405: default:
406: return true;
407: }
408: }
409:
410: private void setParameters(IGraphPort from, IGraphPort to,
411: IGraphNode srcGraphNode, IGraphNode destGraphNode) {
412: if (srcGraphNode != null && destGraphNode != null) {
413: srcParam = srcGraphNode.getFieldName(from);
414: destParam = destGraphNode.getFieldName(to);
415: }
416: }
417:
418: /**
419: * handle link deletion
420: *
421: * @param link IGraphLink
422: */
423: public void handleLinkDeleted(IGraphLink link) {
424: if (!isEditAllowed()) {
425: return;
426: }
427:
428: IGraphPort from = link.getFromGraphPort();
429: IGraphPort to = link.getToGraphPort();
430: IGraphNode srcGraphNode = from.getDataNode();
431: IGraphNode destGraphNode = to.getDataNode();
432:
433: setParameters(from, to, srcGraphNode, destGraphNode);
434:
435: //source is always canvas object and destination is always expression object
436: SQLCanvasObject srcObj = (SQLCanvasObject) srcGraphNode
437: .getDataObject();
438: SQLConnectableObject destObj = (SQLConnectableObject) destGraphNode
439: .getDataObject();
440:
441: if (srcObj == null && destObj == null) {
442: return;
443: }
444:
445: try {
446: collabModel
447: .removeLink(srcObj, srcParam, destObj, destParam);
448: } catch (Exception e) {
449: NotifyDescriptor d = new NotifyDescriptor.Message(e
450: .toString(), NotifyDescriptor.INFORMATION_MESSAGE);
451: DialogDisplayer.getDefault().notify(d);
452: }
453: }
454:
455: /**
456: * handle node add
457: *
458: * @param xmlInfo IOperatorXmlInfo
459: * @param dropLocation dropLocation
460: */
461: @SuppressWarnings("fallthrough")
462: public void handleNodeAdded(IOperatorXmlInfo xmlInfo,
463: Point dropLocation) {
464: if (!isEditAllowed()) {
465: return;
466: }
467:
468: //what object type is dropped
469: String className = xmlInfo.getObjectClassName();
470:
471: try {
472: //create object
473: SQLCanvasObject sqlObj = collabModel
474: .createObject(className);
475: sqlObj.setDisplayName(xmlInfo.getName());
476:
477: GUIInfo guiInfo = sqlObj.getGUIInfo();
478: guiInfo.setX(dropLocation.x);
479: guiInfo.setY(dropLocation.y);
480:
481: String nbBundle6 = mLoc.t("PRSR001: New Cast-As Operator");
482: //do special processing for following objects
483: switch (sqlObj.getObjectType()) {
484: case SQLConstants.CAST_OPERATOR:
485: CastAsDialog castDlg = new CastAsDialog(WindowManager
486: .getDefault().getMainWindow(), Localizer
487: .parse(nbBundle6), true);
488: castDlg.show();
489: if (castDlg.isCanceled()) {
490: return;
491: }
492:
493: SQLCastOperator castOp = (SQLCastOperator) sqlObj;
494: castOp.setOperatorXmlInfo(xmlInfo);
495:
496: castOp.setJdbcType(castDlg.getJdbcType());
497:
498: int precision = castDlg.getPrecision();
499: castOp.setPrecision(precision);
500:
501: int scale = castDlg.getScale();
502: castOp.setScale(scale);
503:
504: break;
505:
506: case SQLConstants.CUSTOM_OPERATOR:
507: CustomOperatorPane customOptPane = new CustomOperatorPane(
508: new ArrayList());
509: String nbBundle7 = mLoc.t("PRSR001: User Function");
510: String title = Localizer.parse(nbBundle7);
511: DialogDescriptor dlgDesc = new DialogDescriptor(
512: customOptPane, title, true,
513: NotifyDescriptor.OK_CANCEL_OPTION,
514: NotifyDescriptor.OK_OPTION,
515: DialogDescriptor.DEFAULT_ALIGN, null, null);
516: Dialog customOptDialog = DialogDisplayer.getDefault()
517: .createDialog(dlgDesc);
518: customOptDialog
519: .getAccessibleContext()
520: .setAccessibleDescription(
521: "This dialog hepls user to configure user-defined functions");
522: customOptDialog.setVisible(true);
523: if (NotifyDescriptor.CANCEL_OPTION == dlgDesc
524: .getValue()) {
525: return;
526: }
527: List inputArgs = customOptPane.getArgList();
528: SQLOperatorArg retType = customOptPane.getReturnType();
529: CustomOperatorNode customOptNode = new CustomOperatorNode(
530: xmlInfo, inputArgs, retType);
531: SQLCustomOperatorImpl custOp = (SQLCustomOperatorImpl) sqlObj;
532: custOp.setOperatorXmlInfo(customOptNode);
533: custOp.setCustomOperatorName(customOptPane
534: .getFunctionName());
535: custOp.getOperatorDefinition().setArgList(inputArgs);
536: custOp.initializeInputs(inputArgs.size());
537: /**
538: CustomOperatorDialog custOprDlg = new CustomOperatorDialog(WindowManager.getDefault().getMainWindow(), NbBundle.getMessage(
539: BasicSQLGraphController.class, "TITLE_user_function"), true);
540: custOprDlg.show();
541: if (custOprDlg.isCanceled()) {
542: return;
543: }
544:
545: SQLCustomOperatorImpl custOp = (SQLCustomOperatorImpl) sqlObj;
546: custOp.setOperatorXmlInfo(xmlInfo);
547: custOp.setCustomOperatorName(custOprDlg.getFunctionName());
548: custOp.initializeInputs(custOprDlg.getNumberOfArguments());
549: */
550: break;
551:
552: case SQLConstants.VISIBLE_PREDICATE:
553: ((SQLPredicate) sqlObj).setOperatorXmlInfo(xmlInfo);
554: // fall through to set XML info (using common SQLOperator interface)
555:
556: case SQLConstants.GENERIC_OPERATOR:
557: case SQLConstants.DATE_ARITHMETIC_OPERATOR:
558: //for operator we need to set the type of operator
559: // ((SQLGenericOperator) sqlObj).setOperatorType(xmlInfo.getName());
560: ((SQLOperator) sqlObj).setOperatorXmlInfo(xmlInfo);
561: sqlObj.setDisplayName(xmlInfo.getDisplayName());
562: break;
563:
564: case SQLConstants.VISIBLE_LITERAL:
565: String nbBundle8 = mLoc
566: .t("PRSR001: New Literal Object");
567: LiteralDialog dlg = new LiteralDialog(WindowManager
568: .getDefault().getMainWindow(), Localizer
569: .parse(nbBundle8), true);
570: dlg.show();
571:
572: // OK button is not pressed so return
573: if (dlg.isCanceled()) {
574: return;
575: }
576:
577: String value = dlg.getLiteral();
578: VisibleSQLLiteral lit = (VisibleSQLLiteral) sqlObj;
579: lit.setJdbcType(dlg.getType());
580: lit.setValue(value);
581: lit.setDisplayName(xmlInfo.getDisplayName());
582:
583: break;
584: }
585:
586: //now add the object
587: collabModel.addObject(sqlObj);
588: //also flag if java operators are to be used
589: } catch (BaseException e) {
590: NotifyDescriptor d = new NotifyDescriptor.Message(e
591: .toString(), NotifyDescriptor.INFORMATION_MESSAGE);
592: DialogDisplayer.getDefault().notify(d);
593: }
594: }
595:
596: /**
597: * handle node deletion
598: *
599: * @param node IGraphNode
600: */
601: public void handleNodeRemoved(IGraphNode node) {
602: if (!isEditAllowed()) {
603: return;
604: }
605:
606: try {
607: IGraphNode pNode = node.getParentGraphNode();
608: //if node has a parent then we should delete it from parent and return
609: //we do not need to go to collaboration as node is contained within
610: //its parent and deleting it from its parent should remove it
611: if (pNode != null) {
612: pNode.removeChildNode(node);
613: return;
614: }
615:
616: SQLCanvasObject sqlObj = (SQLCanvasObject) node
617: .getDataObject();
618: if (sqlObj != null) {
619: collabModel.removeObject(sqlObj);
620: }
621: } catch (Exception e) {
622:
623: mLogger
624: .errorNoloc(
625: mLoc
626: .t(
627: "PRSR174: Caught exception while removing object{0}",
628: LOG_CATEGORY), e);
629: NotifyDescriptor d = new NotifyDescriptor.Message(e
630: .toString(), NotifyDescriptor.INFORMATION_MESSAGE);
631: DialogDisplayer.getDefault().notify(d);
632: }
633: }
634:
635: /**
636: * Sets the data model which this controller modifies
637: *
638: * @param newModel new data model
639: */
640: public void setDataModel(Object newModel) {
641: collabModel = (SQLUIModel) newModel;
642:
643: }
644:
645: public Object getDataModel() {
646: return collabModel;
647: }
648:
649: class TypeSelectorPanel extends JPanel {
650:
651: private ButtonGroup bg;
652: private JRadioButton source;
653: private JRadioButton target;
654:
655: public TypeSelectorPanel() {
656: this (SQLConstants.SOURCE_TABLE);
657: }
658:
659: public TypeSelectorPanel(int newType) {
660: super ();
661: setLayout(new BorderLayout());
662:
663: JPanel insetPanel = new JPanel();
664: insetPanel.setLayout(new BoxLayout(insetPanel,
665: BoxLayout.PAGE_AXIS));
666: insetPanel.setBorder(BorderFactory.createEmptyBorder(10,
667: 15, 0, 15));
668:
669: String title = "";
670: try {
671: String nbBundle9 = mLoc
672: .t("PRSR001: Select table type:");
673: title = Localizer.parse(nbBundle9);
674: } catch (MissingResourceException mre) {
675: title = "Specify table type:";
676: }
677:
678: insetPanel.add(new JLabel(title));
679:
680: String sourceLabel = "";
681: try {
682: String nbBundle10 = mLoc.t("PRSR001: Source table");
683: sourceLabel = Localizer.parse(nbBundle10);
684: } catch (MissingResourceException mre) {
685: sourceLabel = "Source table";
686: }
687:
688: String targetLabel = "";
689: try {
690: String nbBundle11 = mLoc.t("PRSR001: Target table");
691: targetLabel = Localizer.parse(nbBundle11);
692: } catch (MissingResourceException mre) {
693: targetLabel = "Target table";
694: }
695:
696: source = new JRadioButton(sourceLabel);
697: target = new JRadioButton(targetLabel);
698:
699: insetPanel.add(source);
700: insetPanel.add(target);
701: add(insetPanel, BorderLayout.CENTER);
702:
703: bg = new ButtonGroup();
704: bg.add(source);
705: bg.add(target);
706:
707: setSelectedType(newType);
708: }
709:
710: public void setSelectedType(int type) {
711: switch (type) {
712: case SQLConstants.TARGET_TABLE:
713: bg.setSelected(target.getModel(), true);
714: break;
715:
716: case SQLConstants.SOURCE_TABLE:
717: default:
718: bg.setSelected(source.getModel(), true);
719: }
720: }
721:
722: public int getSelectedType() {
723: return target.isSelected() ? SQLConstants.TARGET_TABLE
724: : SQLConstants.SOURCE_TABLE;
725: }
726:
727: @Override
728: public void addNotify() {
729: super .addNotify();
730:
731: switch (getSelectedType()) {
732: case SQLConstants.TARGET_TABLE:
733: target.requestFocusInWindow();
734: break;
735:
736: case SQLConstants.SOURCE_TABLE:
737: default:
738: source.requestFocusInWindow();
739: break;
740: }
741: }
742: }
743:
744: protected boolean isEditAllowed() {
745: if (viewC != null) {
746: return viewC.canEdit();
747: }
748:
749: return true;
750: }
751:
752: /**
753: * set the view from which this controller interacts
754: *
755: * @param view view
756: */
757: public void setView(Object view) {
758: viewC = (IGraphView) view;
759: }
760: }
|