001: /*
002: * CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
003: * NETSCAPE COMMUNICATIONS CORPORATION
004: *
005: * Copyright (c) 1996 Netscape Communications Corporation.
006: * All Rights Reserved.
007: * Use of this Source Code is subject to the terms of the applicable
008: * license agreement from Netscape Communications Corporation.
009: */
010:
011: package components;
012:
013: import communications.PostConnection;
014: import communications.ReadConnection;
015: import graphical.ComboBox;
016: import graphical.DragArgument;
017: import graphical.DragListView;
018: import graphical.DragPolicy;
019: import graphical.DragPolicyContext;
020: import graphical.Header;
021: import graphical.HyperTextField;
022: import graphical.TreeView;
023: import soif.Schema;
024: import soif.SchemaColNode;
025: import soif.Taxonomy;
026: import soif.TaxonomyNode;
027: import util.AltSTokenizer;
028: import util.BinaryTree;
029: import util.BTreeNode;
030: import util.ReportError;
031:
032: import java.awt.Dimension;
033: import java.util.StringTokenizer;
034: import java.io.DataInputStream;
035:
036: import netscape.application.Alert;
037: import netscape.application.BezelBorder;
038: import netscape.application.Button;
039: import netscape.application.Color;
040: import netscape.application.ContainerView;
041: import netscape.application.DragDestination;
042: import netscape.application.DragSession;
043: import netscape.application.ListView;
044: import netscape.application.ListItem;
045: import netscape.application.Point;
046: import netscape.application.Popup;
047: import netscape.application.ScrollGroup;
048: import netscape.application.Size;
049: import netscape.application.Target;
050: import netscape.application.TextField;
051: import netscape.application.View;
052:
053: /**
054: * <b>Open Issues</b>
055: * <ul>
056: * <li>Sizing of popups is arbitrary in the way that the
057: * image is taken into account.
058: * Can't see how the image is handled, so just doubling
059: * the width to make up for positioning.
060: * </ul>
061: */
062: public class ClassificationView extends View implements Target,
063: DragDestination {
064: private DragPolicyContext dpc;
065:
066: private Button newButton;
067: private Button deleteButton;
068:
069: private ScrollGroup scrollGroup;
070: private ListView listView;
071:
072: private TextField whereLabel;
073: private Popup targetPopup;
074: private ComboBox schemaComboBox;
075: private boolean schemaComboVisible;
076: private Popup operatorPopup;
077: private HyperTextField stringField;
078: private TextField classifyLabel;
079: public ComboBox taxonomyComboBox;
080:
081: private Taxonomy m_taxonomy;
082:
083: private ContainerView detailView;
084:
085: private String CGILocation;
086: private String CGITarget;
087: private String CGIRead;
088: private String CGIWrite;
089:
090: private StringBuffer rulesHeader;
091: private StringBuffer rulesFooter;
092:
093: public Target notifyOfChange;
094:
095: /**
096: * Construct instance of ClassificationView.
097: * @param x x
098: * @param y y
099: * @param w width
100: * @param h height
101: * @param schema schema
102: * @param taxonomy taxonomy
103: * @param CGILocation cgi location
104: * @param CGITarget cgi target
105: * @param CGIRead cgi read argument
106: * @param CGIWrite cgi write argument
107: */
108: public ClassificationView(int x, int y, int width, int height,
109: Schema schema, Taxonomy taxonomy, String CGILocation,
110: String CGITarget, String CGIRead, String CGIWrite) {
111: super (x, y, width, height);
112:
113: this .CGILocation = CGILocation;
114: this .CGITarget = CGITarget;
115: this .CGIRead = CGIRead;
116: this .CGIWrite = CGIWrite;
117:
118: commonConstruction(x, y, width, height, schema, taxonomy);
119: obtainClassRules();
120: synchRule();
121: }
122:
123: /**
124: * Construct instance of ClassificationView.
125: * @param x x
126: * @param y y
127: * @param w width
128: * @param h height
129: * @param schema schema
130: * @param taxonomy taxonomy
131: * @param ruleset rule set
132: */
133: public ClassificationView(int x, int y, int width, int height,
134: Schema schema, Taxonomy taxonomy, String ruleset[]) {
135: super (x, y, width, height);
136:
137: this .CGILocation = "";
138: this .CGITarget = "";
139: this .CGIRead = "";
140: this .CGIWrite = "";
141:
142: commonConstruction(x, y, width, height, schema, taxonomy);
143:
144: for (int i = 0; ((i < ruleset.length) && (ruleset[i] != null)); i++)
145: addRuleLine(ruleset[i]);
146: suckRule();
147: synchRule();
148: }
149:
150: public void hideEditButtons() {
151: int hdiff = (scrollGroup.y() - newButton.y())
152: - graphical.Header.WIDGETVGAP;
153: detailView.moveTo(detailView.x(), detailView.y() - hdiff);
154: scrollGroup.setBounds(newButton.x(), newButton.y(), scrollGroup
155: .width(), scrollGroup.height());
156: newButton.moveTo(Integer.MIN_VALUE, newButton.y());
157: deleteButton.moveTo(Integer.MIN_VALUE, deleteButton.y());
158: }
159:
160: private void commonConstruction(int x, int y, int width,
161: int height, Schema schema, Taxonomy taxonomy) {
162: m_taxonomy = taxonomy;
163:
164: dpc = new DragPolicyContext();
165: notifyOfChange = null;
166:
167: Size btnSize = new Size();
168:
169: newButton = new Button();
170: newButton.setTitle(Messages.CMD_NEW);
171: newButton.setCommand(Messages.CMD_NEW);
172: btnSize.union(newButton.minSize());
173:
174: deleteButton = new Button();
175: deleteButton.setTitle(Messages.CMD_DELETE);
176: deleteButton.setCommand(Messages.CMD_DELETE);
177: btnSize.union(deleteButton.minSize());
178:
179: newButton.setBounds(Header.WIDGETHGAP, Header.WIDGETVGAP,
180: btnSize.width, btnSize.height);
181: deleteButton.setBounds(Header.WIDGETHGAP
182: + ((btnSize.width + Header.WIDGETHGAP) * 1),
183: Header.WIDGETVGAP, btnSize.width, btnSize.height);
184:
185: scrollGroup = new ScrollGroup(Header.WIDGETHGAP, btnSize.height
186: + (Header.WIDGETVGAP * 2), width
187: - (Header.WIDGETHGAP * 2), height
188: - (Header.WIDGETVGAP * 3) - Header.CREEPYFUDGEGAP
189: - btnSize.height * 1 - Header.DETAILVGAP);
190: scrollGroup.setHasHorizScrollBar(true);
191: scrollGroup.setHasVertScrollBar(true);
192: scrollGroup.setBorder(new BezelBorder(BezelBorder.LOWERED,
193: Color.lightGray));
194: // scrollGroup.scrollView().setBuffered(true);
195: scrollGroup.setBuffered(true);
196: scrollGroup.scrollView().setBackgroundColor(Color.white);
197: scrollGroup.setHorizResizeInstruction(View.WIDTH_CAN_CHANGE);
198: scrollGroup.setVertResizeInstruction(View.HEIGHT_CAN_CHANGE);
199:
200: ListItem protoListItem = new ListItem();
201: protoListItem.setSelectedColor(Color.lightGray);
202: protoListItem
203: .setData("Classification"
204: + " src=\"url\" by-exact=\"http://home.netscape.com:80/\" action=\"\"");
205: updateTitle(protoListItem);
206: listView = new ListView(0, 0, 20, 20);
207: listView.setBuffered(true);
208: listView.sizeToMinSize();
209: listView.setTarget(this );
210: listView.setCommand("clickCommand");
211: listView.setBackgroundColor(Color.white);
212: listView.setPrototypeItem(protoListItem);
213:
214: scrollGroup.scrollView().setContentView(listView);
215:
216: detailView = new ContainerView();
217:
218: whereLabel = TextField.createLabel(Messages.LBL_WHERE);
219: whereLabel.setBounds(graphical.Header.WIDGETHGAP,
220: graphical.Header.WIDGETVGAP
221: + graphical.Header.LABELBORDERGAP, whereLabel
222: .minSize().width, whereLabel.minSize().height);
223:
224: targetPopup = new Popup(whereLabel.x() + whereLabel.width()
225: + graphical.Header.WIDGETHGAP, whereLabel.y(), 50, // SGP
226: btnSize.height);
227:
228: targetPopup.addItem("url", "synchRule");
229: targetPopup.addItem("host", "synchRule");
230: targetPopup.addItem("protocol", "synchRule");
231: targetPopup.addItem("ip", "synchRule");
232: targetPopup.addItem("path", "synchRule");
233: targetPopup.addItem("type", "synchRule");
234: targetPopup.addItem("attribute", "synchRule");
235: // targetPopup.itemAt(6).setEnabled(false); // SGP
236: targetPopup.sizeTo(targetPopup.popupList().minItemWidth()
237: // SGP: arbitrary times 2
238: + (2 * targetPopup.popupImage().width()), targetPopup
239: .height());
240:
241: schemaComboBox = new ComboBox(targetPopup.x()
242: + targetPopup.width() + graphical.Header.WIDGETHGAP,
243: targetPopup.y(), 50, btnSize.height);
244: schemaComboBox.setTypeAhead(true); // SGP
245: schemaComboBox.setEditable(false);
246: schema.hideInternal();
247: schema.binaryTree.resetEnumeration();
248: while (schema.binaryTree.hasMoreElements(true)) {
249: schema.binaryTree.nextElement(true);
250: if (schema.binaryTree.getCurrent().display) {
251: Object o = schema.binaryTree.getValue();
252: if (o instanceof SchemaColNode)
253: schemaComboBox.addItem(((SchemaColNode) o)
254: .getLabel());
255: }
256: }
257: schemaComboBox.sizeTo(schemaComboBox.comboboxList()
258: .minItemWidth()
259: + schemaComboBox.fudgeWidth(), schemaComboBox.height());
260:
261: operatorPopup = new Popup(targetPopup.x(), whereLabel.y()
262: + whereLabel.height() + graphical.Header.WIDGETVGAP,
263: 50, btnSize.height);
264: // SGP: bad - needs to be kept in synch w/ other
265: // stuff - make table
266: // by exact
267: operatorPopup.addItem("is", "synchRule");
268: // by substr
269: operatorPopup.addItem("contains", "synchRule");
270: // by prefix
271: operatorPopup.addItem("begins with", "synchRule");
272: // by suffix
273: operatorPopup.addItem("ends with", "synchRule");
274: // by regex ?matches?
275: operatorPopup.addItem("regular expression", "synchRule");
276: operatorPopup.sizeTo(operatorPopup.popupList().minItemWidth()
277: // SGP: arbitrary times 2
278: + (2 * operatorPopup.popupImage().width()),
279: operatorPopup.height());
280:
281: /* a quick fiddle to get the popups to line up all pretty */
282: int popW = Math.max(operatorPopup.width(), targetPopup.width());
283: int hdiff;
284: hdiff = popW - operatorPopup.width();
285: operatorPopup.sizeTo(hdiff + operatorPopup.width(),
286: operatorPopup.height());
287: hdiff = popW - targetPopup.width();
288: targetPopup.sizeTo(hdiff + targetPopup.width(), targetPopup
289: .height());
290: schemaComboBox.moveTo(schemaComboBox.x() + hdiff,
291: schemaComboBox.y());
292:
293: stringField = new HyperTextField(operatorPopup.x()
294: + operatorPopup.width() + graphical.Header.WIDGETHGAP,
295: operatorPopup.y(), 250, // SGP
296: btnSize.height);
297: /* stringField.setContentsChangedCommandAndTarget("synchRule", this); */
298: stringField.setKeyDownTarget(this );
299:
300: classifyLabel = TextField.createLabel(Messages.LBL_CLASSIFYAS);
301: classifyLabel.setBounds(whereLabel.x(), operatorPopup.y()
302: + operatorPopup.height()
303: + (graphical.Header.WIDGETVGAP * 2), classifyLabel
304: .minSize().width, classifyLabel.minSize().height);
305:
306: taxonomyComboBox = new ComboBox(classifyLabel.x()
307: + classifyLabel.width() + graphical.Header.WIDGETHGAP,
308: classifyLabel.y(), 50, btnSize.height);
309: taxonomyComboBox.setTypeAhead(true); // SGP
310: taxonomyComboBox.setEditable(false);
311: updateTaxonomyComboBox(taxonomy);
312:
313: detailView.sizeTo(scrollGroup.width()
314: - graphical.Header.WIDGETHGAP, taxonomyComboBox.y()
315: + taxonomyComboBox.height()
316: + graphical.Header.WIDGETVGAP);
317: scrollGroup.sizeTo(scrollGroup.width(), scrollGroup.height()
318: - detailView.height());
319: detailView.moveTo(scrollGroup.x(), scrollGroup.y()
320: + scrollGroup.height() + graphical.Header.WIDGETVGAP);
321:
322: detailView.addSubview(whereLabel);
323: detailView.addSubview(targetPopup);
324: detailView.addSubview(schemaComboBox);
325: schemaComboVisible = true;
326: detailView.addSubview(operatorPopup);
327: detailView.addSubview(stringField);
328: detailView.addSubview(classifyLabel);
329: detailView.addSubview(taxonomyComboBox);
330: detailView.setHorizResizeInstruction(View.WIDTH_CAN_CHANGE);
331: detailView.setVertResizeInstruction(View.TOP_MARGIN_CAN_CHANGE);
332:
333: addSubview(newButton);
334: addSubview(deleteButton);
335: addSubview(scrollGroup);
336: addSubview(detailView);
337:
338: newButton.setTarget(this );
339: deleteButton.setTarget(this );
340: targetPopup.setTarget(this );
341: operatorPopup.setTarget(this );
342:
343: schemaComboBox.setTarget(this );
344: taxonomyComboBox.setTarget(this );
345:
346: schemaComboBox.setCommand("synchRule");
347: taxonomyComboBox.setCommand("synchRule");
348: }
349:
350: public void updateTaxonomyComboBox(Taxonomy taxonomy) {
351: taxonomyComboBox.removeAllItems();
352: taxonomy.binaryTree.currentBackup();
353: taxonomy.binaryTree.resetEnumeration();
354: while (taxonomy.binaryTree.hasMoreElements(true)) {
355: taxonomy.binaryTree.nextElement(true);
356: Object o = taxonomy.binaryTree.getValue();
357: if (o instanceof TaxonomyNode)
358: taxonomyComboBox.addItem(((TaxonomyNode) o).getId());
359: }
360: taxonomyComboBox.sizeTo(Math.max(taxonomyComboBox
361: .comboboxList().minItemWidth(), 20 /* SGP */)
362: + taxonomyComboBox.fudgeWidth(), taxonomyComboBox
363: .height());
364: taxonomy.binaryTree.currentRestore();
365: suckRule();
366: }
367:
368: private void setEnabled(boolean b) {
369: targetPopup.setEnabled(b);
370: schemaComboBox.setEnabled(b);
371: operatorPopup.setEnabled(b);
372: taxonomyComboBox.setEnabled(b);
373:
374: stringField.setEditable(b);
375: if (b)
376: stringField
377: .setBackgroundColor(graphical.Header.ACTIVECOLOR);
378: else {
379: stringField
380: .setBackgroundColor(graphical.Header.INACTIVECOLOR);
381: stringField.setStringValue("");
382: }
383:
384: targetPopup.setDirty(true);
385: schemaComboBox.setDirty(true);
386: operatorPopup.setDirty(true);
387: stringField.setDirty(true);
388: taxonomyComboBox.setDirty(true);
389: }
390:
391: private void sizeListView() {
392: listView.sizeTo(listView.minItemWidth(), listView.height());
393: listView.sizeToMinSize();
394: listView.setDirty(true);
395: if (listView.count() == 0)
396: setEnabled(false);
397: else if (!targetPopup.isEnabled())
398: setEnabled(true);
399: }
400:
401: private void addRuleLine(String s) {
402: ListItem listItem = new ListItem();
403:
404: listItem.setData(s);
405: updateTitle(listItem);
406: listItem.setSelectedColor(Color.lightGray);
407: listView.addItem(listItem);
408: }
409:
410: /* SGP: seperate method for form - for necessity? */
411: private void obtainClassRules() {
412: rulesHeader = new StringBuffer();
413: rulesFooter = new StringBuffer();
414:
415: boolean inheader = true;
416: boolean infooter = false;
417:
418: String s;
419:
420: listView.removeAllItems();
421:
422: ReadConnection rc = new ReadConnection(CGILocation + CGITarget
423: + CGIRead);
424:
425: if (rc.openIn() == false) {
426: return;
427: }
428:
429: try {
430: DataInputStream dis = new DataInputStream(rc.getIS());
431: while ((s = dis.readLine()) != null) {
432: if (s.startsWith("Classification"))
433: addRuleLine(s);
434: else if (s
435: .startsWith("<Preprocess directive=\"Generate\">")) {
436: rulesHeader.append(s + "\n");
437: inheader = false;
438: } else if (s.startsWith("</Preprocess>")) {
439: rulesFooter.append(s + "\n");
440: infooter = true;
441: } else if (inheader)
442: rulesHeader.append(s + "\n");
443: else if (infooter)
444: rulesFooter.append(s + "\n");
445: }
446: } catch (java.io.IOException e) {
447: ReportError.reportError(util.ReportError.INTERNAL,
448: "ClassificationView", "obtainClasRules",
449: Messages.ERROR_GETCLASSRULES);
450: }
451:
452: if (rc.closeIn() == false) {
453: return;
454: }
455:
456: suckRule();
457: sizeListView();
458: }
459:
460: public String toStringClassRules() {
461: int n = listView.count();
462: StringBuffer sb = new StringBuffer();
463:
464: // sb.append(rulesHeader.toString());
465: for (int i = 0; i < n; i++)
466: sb.append(((String) listView.itemAt(i).data()) + "\n");
467: // sb.append(rulesFooter.toString());
468:
469: return sb.toString();
470: }
471:
472: public String writeClassRules() {
473: int n = listView.count();
474:
475: PostConnection pc = new PostConnection(CGILocation + CGITarget
476: + CGIWrite);
477:
478: // SGP: come back and turn this into a pc.doWrite()
479:
480: if (pc.openOut() == false) {
481: return null;
482: }
483:
484: pc.writeBytes(rulesHeader.toString());
485: for (int i = 0; i < n; i++) {
486: pc.writeBytes(((String) listView.itemAt(i).data()) + "\n");
487: }
488: pc.writeBytes(rulesFooter.toString());
489:
490: if (pc.closeOut() == false) {
491: return null;
492: }
493:
494: String s = pc.doRead();
495:
496: if (s != null) {
497: s.trim();
498: }
499:
500: return s;
501: }
502:
503: public void clickCommand() {
504: suckRule();
505: synchRule();
506: schemaComboVis();
507: }
508:
509: public void newButtonPress() {
510: ListItem li = listView.selectedItem();
511: // SGP: relying on an empty set (null) to
512: // give back an index of -1 so that we end up
513: // inserting at 0.
514: int i = listView.indexOfItem(li) + 1;
515:
516: listView.insertItemAt(i);
517: listView.selectItemAt(i);
518: suckRule();
519: spitRule();
520: sizeListView();
521: listView.setDirty(true);
522:
523: if (notifyOfChange != null)
524: notifyOfChange.performCommand(
525: graphical.Messages.MSG_CHANGED_DATA, null);
526: }
527:
528: public void deleteButtonPress() {
529: ListItem li = listView.selectedItem();
530: if (li == null) {
531: return;
532: }
533:
534: listView.removeItem(li);
535: suckRule();
536: sizeListView();
537: listView.setDirty(true);
538:
539: if (notifyOfChange != null)
540: notifyOfChange.performCommand(
541: graphical.Messages.MSG_CHANGED_DATA, null);
542: }
543:
544: /* SGP */
545: /**
546: * This is overridden in an attempt to deal with
547: * a drawing problem which shows up only on the ultras.
548: * If this component is in an InternalWindow and the window
549: * is resized (and only after resizing) in a way that allows
550: * scrolling to be valid, scrolling can cause big chunks of
551: * the ListView area to be painted black.
552: * For some reason, setting the ListView to dirty (not drawing
553: * it, not messing with any of the other relevant components)
554: * makes the situation "better" - the black only appears if
555: * the scrolling is pretty rapid.
556: * <p>
557: * In an ideal world, this method is doomed and will be
558: * reviewed in the future for need.
559: */
560: public void didSizeBy(int width, int height) {
561: super .didSizeBy(width, height);
562: listView.setDirty(true);
563:
564: // best:
565: // 3 (hard to imagine why, but makes the
566: // blackness harder to aggravate,
567: // doesn't eliminate it)
568: // 5 (not as good as 3)
569: // bad:
570: // 1
571: // 2
572: // 4 (goes black on resize!!)
573: // System.out.println("1 draw()");
574: // draw();
575: // System.out.println("2 listView.draw()");
576: // listView.draw();
577: // System.out.println("3 listView.setDirty(true)");
578: // listView.setDirty(true);
579: // System.out.println(
580: // "4 scrollGroup.scrollView().setDirty(true)"
581: //);
582: // scrollGroup.scrollView().setDirty(true);
583: // System.out.println("5 setDirty(true)");
584: // setDirty(true);
585:
586: // try { Thread.sleep(100); }
587: // catch (InterruptedException e) { }
588: }
589:
590: // SGP merge suckRule() and updateTitle()
591: /**
592: * From data to title - very like suckRule().
593: */
594: private void updateTitle(ListItem li) {
595: String rule = (String) li.data();
596: AltSTokenizer st = new AltSTokenizer(rule);
597: String s;
598: String s2;
599: StringBuffer sb = new StringBuffer();
600:
601: st.setRespectQuotedStrings(true);
602: // System.out.println("rule [" + rule + "]");
603:
604: st.nextToken(); // eat the class tag
605: // src pair
606: s = st.nextToken();
607: // System.out.println("s 1 [" + s + "]");
608: s = s.substring(s.indexOf("=") + 2);
609: s = s.substring(0, s.length() - 1);
610: if ("uri".equals(s)) {
611: s = "path";
612: }
613:
614: sb.append(Messages.LBL_WHERE);
615: sb.append(" ");
616:
617: sb.append(s);
618: sb.append(" ");
619:
620: s = st.nextToken();
621: s2 = s.substring(0, s.indexOf("="));
622:
623: // SGP: barf-o-drome
624: if (s2.compareTo("by-exact") == 0)
625: sb.append("is");
626: else if (s2.compareTo("by-substr") == 0)
627: sb.append("contains");
628: else if (s2.compareTo("by-prefix") == 0)
629: sb.append("begins with");
630: else if (s2.compareTo("by-suffix") == 0)
631: sb.append("ends with");
632: else if (s2.compareTo("by-regex") == 0)
633: sb.append("regular expression");
634: sb.append(" ");
635:
636: s = s.substring(s.indexOf("=") + 2);
637: s = s.substring(0, s.length() - 1);
638: sb.append(s);
639: sb.append(" ");
640:
641: sb.append(Messages.LBL_CLASSIFYAS);
642: sb.append(" ");
643:
644: s = st.peekRemains();
645: s = s.substring(s.indexOf("=") + 2);
646: s = s.substring(0, s.length() - 1);
647: sb.append(s);
648:
649: li.setTitle(sb.toString());
650: }
651:
652: /**
653: * From list to detail.
654: */
655: private void suckRule() {
656: ListItem li = listView.selectedItem();
657:
658: if (li == null) {
659: return;
660: }
661:
662: String rule = (String) li.data();
663: AltSTokenizer st = new AltSTokenizer(rule);
664: String s;
665: String s2;
666:
667: st.setRespectQuotedStrings(true);
668:
669: st.nextToken(); // eat the class tag
670: // src pair
671: s = st.nextToken();
672: s = s.substring(s.indexOf("=") + 2);
673: s = s.substring(0, s.length() - 1);
674:
675: // SGP: no pride whatsoever
676: if (s.compareTo("url") == 0)
677: targetPopup.selectItemAt(0);
678: else if (s.compareTo("host") == 0)
679: targetPopup.selectItemAt(1);
680: else if (s.compareTo("protocol") == 0)
681: targetPopup.selectItemAt(2);
682: else if (s.compareTo("ip") == 0)
683: targetPopup.selectItemAt(3);
684: else if (s.compareTo("uri") == 0)
685: targetPopup.selectItemAt(4);
686: else if (s.compareTo("type") == 0)
687: targetPopup.selectItemAt(5);
688: else // if (s.compareTo("attribute") == 0)
689: {
690: targetPopup.selectItemAt(6);
691: schemaComboBox.selectRowWithTitle(s);
692: }
693:
694: // SGP: heh. not this instance, particularly. just in general. heh.
695: schemaComboVis();
696:
697: s = st.nextToken();
698: s2 = s.substring(0, s.indexOf("="));
699:
700: // SGP: still no pride whatsoever
701: if (s2.compareTo("by-exact") == 0)
702: operatorPopup.selectItemAt(0);
703: else if (s2.compareTo("by-substr") == 0)
704: operatorPopup.selectItemAt(1);
705: else if (s2.compareTo("by-prefix") == 0)
706: operatorPopup.selectItemAt(2);
707: else if (s2.compareTo("by-suffix") == 0)
708: operatorPopup.selectItemAt(3);
709: else if (s2.compareTo("by-regex") == 0)
710: operatorPopup.selectItemAt(4);
711:
712: s = s.substring(s.indexOf("=") + 2);
713: s = s.substring(0, s.length() - 1);
714: // weaselDebug("suR", 1);
715: // freeze the textfield value or else resaving the
716: // same value will cancel the editing and revert to
717: // the previous value (why does ifc do this?)
718: stringField.completeEditing();
719: stringField.setStringValue(s);
720: // weaselDebug("suR", 2);
721:
722: s = st.peekRemains();
723: s = s.substring(s.indexOf("=") + 2);
724: s = s.substring(0, s.length() - 1);
725: taxonomyComboBox.selectRowWithTitle(s);
726:
727: if (taxonomyComboBox.stringValue().equals("")) {
728: // If no Category selected, then Category is not in ComboBox
729: // and therefore not in Category tree. Invalid Category
730: Alert.runAlertExternally(Alert.notificationImage(),
731: Messages.ERROR_INV_CATEGORY, "", Messages.CMD_OK,
732: null, null);
733: }
734: }
735:
736: /**
737: * From detail to list.
738: */
739: private void spitRule() {
740: // weaselDebug("spR", 1);
741: ListItem li = listView.selectedItem();
742:
743: if (li == null) {
744: return;
745: }
746:
747: String rule = (String) li.data();
748:
749: StringBuffer sb = new StringBuffer();
750: sb.append("Classification");
751: sb.append(" ");
752: sb.append("src=\"");
753:
754: if (targetPopup.selectedIndex() == 6)
755: sb.append(schemaComboBox.stringValue());
756: else if (targetPopup.selectedIndex() == 4)
757: sb.append("uri");
758: else
759: sb.append(targetPopup.selectedItem().title());
760:
761: sb.append("\"");
762: sb.append(" ");
763:
764: if (operatorPopup.selectedIndex() == 0)
765: sb.append("by-exact");
766: else if (operatorPopup.selectedIndex() == 1)
767: sb.append("by-substr");
768: else if (operatorPopup.selectedIndex() == 2)
769: sb.append("by-prefix");
770: else if (operatorPopup.selectedIndex() == 3)
771: sb.append("by-suffix");
772: else if (operatorPopup.selectedIndex() == 4)
773: sb.append("by-regex");
774:
775: sb.append("=\"");
776: sb.append(stringField.stringValue());
777: sb.append("\" action=\"");
778: sb.append(taxonomyComboBox.stringValue());
779: sb.append("\"");
780:
781: li.setData(sb.toString());
782: updateTitle(li);
783: sizeListView();
784: // weaselDebug("spR", 2);
785: }
786:
787: public void schemaComboVis() {
788: if ("attribute".compareTo(targetPopup.selectedItem().title()) == 0) {
789: if (schemaComboVisible == false) {
790: detailView.addSubview(schemaComboBox);
791: schemaComboVisible = true;
792: detailView.draw();
793: }
794: } else {
795: if (schemaComboVisible == true) {
796: schemaComboBox.removeFromSuperview();
797: schemaComboVisible = false;
798: detailView.draw();
799: }
800: }
801: }
802:
803: public void synchRule() {
804: // weaselDebug("syR", 1);
805:
806: spitRule();
807: schemaComboVis();
808: listView.setDirty(true);
809: if (notifyOfChange != null)
810: notifyOfChange.performCommand(
811: graphical.Messages.MSG_CHANGED_DATA, null);
812:
813: // listView.draw();
814: // weaselDebug("syR", 2);
815: }
816:
817: /*
818: private void weaselDebug(String s, int i)
819: {
820: System.out.println(
821: s
822: + " "
823: + i
824: + ":"
825: + stringField.isSelectable()
826: + " "
827: + stringField.isInViewHierarchy()
828: + " "
829: + stringField.isBeingEdited()
830: + " "
831: + stringField.isEditable()
832: + " "
833: + stringField.stringValue()
834: );
835: }
836: */
837:
838: public void performCommand(String command, Object arg) {
839: if (graphical.HyperTextField.KEYDOWN.equals(command))
840: synchRule();
841: else if ("clickCommand".equals(command))
842: clickCommand();
843: else if (Messages.CMD_NEW.equals(command))
844: newButtonPress();
845: else if (Messages.CMD_DELETE.equals(command))
846: deleteButtonPress();
847: else if ("synchRule".equals(command))
848: synchRule();
849: }
850:
851: /**************/
852: /* DragPolicy */
853: /**************/
854:
855: public void setDragDestinationPolicy(int dragDestinationPolicy)
856: throws IllegalArgumentException {
857: if (DragPolicyContext
858: .validateDragDestinationPolicy(dragDestinationPolicy))
859: dpc.dragDestinationPolicy = dragDestinationPolicy;
860: else
861: throw new IllegalArgumentException(
862: graphical.Messages.UNKNOWNDRAGPOLICY + " "
863: + dragDestinationPolicy);
864: }
865:
866: /*******************/
867: /* DragDestination */
868: /*******************/
869:
870: public boolean dragEntered(DragSession ds) {
871: // System.out.println("dragEntered()");
872: if (dpc.dragDestinationPolicy != DragPolicy.DRAGTODISALLOWED) {
873: dpc.sourceDragSession = ds;
874: return true;
875: } else
876: return false;
877: }
878:
879: public boolean dragMoved(DragSession ds) {
880: // System.out.println("dragMoved()");
881: return true;
882: }
883:
884: public void dragExited(DragSession ds) {
885: // System.out.println("dragExited()");
886: if (dpc.dragDestinationPolicy != DragPolicy.DRAGTODISALLOWED) {
887: dpc.sourceDragSession = null;
888: draw(); // SGP??
889: }
890: }
891:
892: public boolean dragDropped(DragSession ds) {
893: // System.out.println("dragDropped()");
894:
895: Point destPoint = ds.destinationMousePoint();
896: DragArgument da;
897:
898: if (taxonomyComboBox.bounds().contains(
899: convertPointToView(detailView, destPoint))) {
900: da = new DragArgument(DragArgument.DRAGDROPPED, this ,
901: taxonomyComboBox, ds.source(), ds.data());
902:
903: if (!(da.source instanceof DragListView)
904: || !(da.sourceData instanceof ListItem))
905: return true;
906:
907: if (!(((ListItem) da.sourceData).data() instanceof BTreeNode))
908: return true;
909:
910: if (!(((BTreeNode) ((ListItem) da.sourceData).data())
911: .getValue() instanceof TaxonomyNode))
912: return true;
913:
914: taxonomyComboBox
915: .selectRowWithTitle(((TaxonomyNode) (((BTreeNode) ((ListItem) da.sourceData)
916: .data()).getValue())).getId());
917: synchRule();
918: } else if (schemaComboBox.bounds().contains(
919: convertPointToView(detailView, destPoint))) {
920: da = new DragArgument(DragArgument.DRAGDROPPED, this ,
921: schemaComboBox, ds.source(), ds.data());
922:
923: if (schemaComboVisible == false)
924: return true;
925:
926: if (!(da.source instanceof DragListView)
927: || !(da.sourceData instanceof ListItem))
928: return true;
929:
930: if (!(((ListItem) da.sourceData).data() instanceof BTreeNode))
931: return true;
932:
933: if (!(((BTreeNode) ((ListItem) da.sourceData).data())
934: .getValue() instanceof SchemaColNode))
935: return true;
936:
937: schemaComboBox
938: .selectRowWithTitle(((SchemaColNode) (((BTreeNode) ((ListItem) da.sourceData)
939: .data()).getValue())).getLabel());
940:
941: synchRule();
942: } else
943: return true;
944:
945: if (dpc.destinationTarget != null)
946: dpc.destinationTarget.performCommand("", da);
947:
948: if (dpc.dragDestinationPolicy == DragPolicy.DRAGTOACCEPT) {
949: dpc.sourceDragSession = null;
950: return true;
951: } else if (dpc.dragDestinationPolicy == DragPolicy.DRAGTOACCEPTINCLUDE) {
952: /* not meaningful */
953: } else if (dpc.dragDestinationPolicy == DragPolicy.DRAGTOACCEPTDISPLACE) {
954: /* not meaningful */
955: }
956:
957: return true;
958: }
959:
960: public DragDestination acceptsDrag(DragSession ds, int x, int y) {
961: // System.out.println("acceptsDrag()");
962: // System.out.println("source [" + ds.source().toString() + "]");
963: // System.out.println("data [" + ds.data().toString() + "]");
964:
965: // must be open for business
966: if (dpc.dragDestinationPolicy == DragPolicy.DRAGTODISALLOWED)
967: return null;
968:
969: return this;
970: }
971:
972: }
|