0001: /*
0002: * CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
0003: * NETSCAPE COMMUNICATIONS CORPORATION
0004: *
0005: * Copyright (c) 1996 Netscape Communications Corporation.
0006: * All Rights Reserved.
0007: * Use of this Source Code is subject to the terms of the applicable
0008: * license agreement from Netscape Communications Corporation.
0009: */
0010:
0011: package components;
0012:
0013: import communications.PostConnection;
0014:
0015: import graphical.DragArgument;
0016: import graphical.DragIGREView;
0017: import graphical.DragListView;
0018: import graphical.IconInternalWindow;
0019: import graphical.Minimize;
0020: import graphical.WindowTiler;
0021:
0022: import soif.AVPairs;
0023: import soif.CSID;
0024: import soif.Schema;
0025: import soif.SchemaGetter;
0026: import soif.Search;
0027: import soif.SOIF;
0028: import soif.SOIFParser;
0029: import soif.Taxonomy;
0030: import soif.TaxonomyGetter;
0031: import soif.TaxonomyNode;
0032:
0033: import util.BTreeNode;
0034: import util.ReportError;
0035:
0036: import netscape.application.*;
0037:
0038: import com.indius.base.*;
0039: import com.indius.grid.*;
0040:
0041: public class RDEditorWindow extends IconInternalWindow implements
0042: Target {
0043: public ExternalWindow m_externalWindow;
0044:
0045: private WindowTiler m_windowTiler;
0046:
0047: private SearchView searchView;
0048: private SimpleGrid resultsGrid = null;
0049: private DragIGREView resultsView;
0050: private IBorderView resultsBorder;
0051: private Popup targetPopup;
0052:
0053: private Image m_normalIcon;
0054: private Image m_selectedIcon;
0055:
0056: private String editAtts[];
0057: private String columnLabel[];
0058: private boolean columnEditable[];
0059: private int columnWidths[];
0060: private int columnTotal;
0061: private String searchAtts;
0062:
0063: private boolean editRDs;
0064: private boolean editTaxonomy;
0065: private boolean m_testMode;
0066: private boolean m_standAlone;
0067:
0068: private Schema m_schema;
0069: private Taxonomy m_taxonomy;
0070:
0071: private String m_readCGILocation;
0072: private String m_writeCGILocation;
0073: private CSID m_readCSID;
0074: private CSID m_writeCSID;
0075:
0076: private Bitmap bm;
0077:
0078: private RDPropertyWindow propertyWindow = null;
0079:
0080: private boolean m_updated = false; // Unsaved changes?
0081:
0082: private int m_activeRow;
0083: private String m_activeURL;
0084:
0085: public RDEditorWindow(ExternalWindow externalWindow,
0086: WindowTiler windowTiler, int x, int y, int w, int h,
0087: boolean testMode, boolean standAlone, Schema schema,
0088: Taxonomy taxonomy, String readCGILocation,
0089: String writeCGILocation, CSID readCSID, CSID writeCSID) {
0090: super (x, y, w, h, null);
0091:
0092: m_externalWindow = externalWindow;
0093: m_windowTiler = windowTiler;
0094: m_testMode = testMode;
0095: m_standAlone = standAlone;
0096: m_schema = schema;
0097: m_taxonomy = taxonomy;
0098: m_readCGILocation = readCGILocation;
0099: m_writeCGILocation = writeCGILocation;
0100: m_readCSID = readCSID;
0101: m_writeCSID = writeCSID;
0102:
0103: m_normalIcon = new Bitmap(Header.card,
0104: Header.cardImageSize.width, Header.cardImageSize.height);
0105: m_selectedIcon = new Bitmap(Header.cardselected,
0106: Header.cardImageSize.width, Header.cardImageSize.height);
0107: bm = new Bitmap(components.Header.minCompass,
0108: components.Header.minCompassSize.width,
0109: components.Header.minCompassSize.height);
0110:
0111: String windowTitle;
0112:
0113: setEditFlags();
0114:
0115: if (editRDs == true) {
0116: windowTitle = Messages.TITLE_RDSEARCHEDIT;
0117: } else {
0118: windowTitle = Messages.TITLE_RDSEARCHCLASSIFY;
0119: }
0120:
0121: searchView = new SearchView(0, 0,
0122: graphical.Header.IWINDWIDTH,
0123: 40, // SGP
0124: null, null, null, "URL, title, classification",
0125: "+URL, +classification", SEARCH_REC_LIMIT, "compass");
0126: searchView.sizeTo(searchView.width(),
0127: searchView.minSize().height);
0128: searchView.searchBtn.setTarget(this );
0129: searchView.searchTF.setTarget(this );
0130: searchView.setHorizResizeInstruction(View.WIDTH_CAN_CHANGE);
0131:
0132: searchView.searchTF
0133: .setSelectionColor(graphical.Header.SELECTEDCOLOR);
0134: searchView.searchTF.setTextColor(graphical.Header.TEXTCOLOR);
0135:
0136: // Create menu bar for window
0137: Menu menuBar = new Menu(true);
0138: MenuItem fileMenu = menuBar
0139: .addItemWithSubmenu(Messages.MENU_FILE);
0140: MenuItem saveItem = fileMenu.submenu().addItem(
0141: Messages.CMD_SAVE, Messages.SCUT_SAVE,
0142: Messages.CMD_SAVE, this );
0143: saveItem.setEnabled(editRDs);
0144: fileMenu.submenu().addSeparator();
0145: MenuItem closeItem = fileMenu.submenu().addItem(
0146: Messages.CMD_CLOSE, Messages.SCUT_CLOSE,
0147: Messages.CMD_CLOSE, this );
0148: /* No edit menu in beta 2
0149: MenuItem editMenu = menuBar.addItemWithSubmenu(Messages.MENU_EDIT);
0150: MenuItem cutItem = editMenu.submenu().addItem(Messages.CMD_EDIT_CUT,
0151: Messages.CMD_EDIT_CUT,
0152: this);
0153: cutItem.setEnabled(editRDs);
0154: editMenu.submenu().addItem(Messages.CMD_EDIT_COPY,
0155: Messages.CMD_EDIT_COPY,
0156: this);
0157: MenuItem pasteItem = editMenu.submenu().addItem(Messages.CMD_EDIT_PASTE,
0158: Messages.CMD_EDIT_PASTE,
0159: this);
0160: pasteItem.setEnabled(editRDs);
0161: editMenu.submenu().addSeparator();
0162: MenuItem undoItem = editMenu.submenu().addItem(Messages.CMD_EDIT_UNDO,
0163: Messages.CMD_EDIT_UNDO,
0164: this);
0165: undoItem.setEnabled(editRDs);
0166: */
0167:
0168: MenuItem windowMenu = menuBar
0169: .addItemWithSubmenu(Messages.MENU_WINDOW);
0170:
0171: windowMenu.submenu().addItem(Messages.CMD_NEWPROPWIND,
0172: Messages.CMD_NEWPROPWIND, this );
0173:
0174: if (m_standAlone == true) {
0175: windowMenu.submenu().addSeparator();
0176: windowMenu.submenu().addItem(Messages.CMD_NEWRDEDIT,
0177: Messages.CMD_NEWRDEDIT, this );
0178: windowMenu.submenu().addItem(Messages.CMD_NEWTAXWIND,
0179: Messages.CMD_NEWTAXWIND, this );
0180: }
0181:
0182: MenuView menuView = new MenuView(menuBar);
0183: menuView.sizeToMinSize();
0184:
0185: TextField searchLabel = TextField
0186: .createLabel(Messages.LBL_SEARCHFOR);
0187: searchLabel.setBounds(graphical.Header.WIDGETHGAP,
0188: graphical.Header.WIDGETVGAP
0189: + graphical.Header.LABELBORDERGAP, searchLabel
0190: .minSize().width, searchLabel.minSize().height);
0191:
0192: targetPopup = new Popup(searchLabel.x() + searchLabel.width()
0193: + graphical.Header.WIDGETHGAP, searchLabel.y() - 2, 50,
0194: searchView.searchBtn.height());
0195:
0196: targetPopup.setTarget(this );
0197: targetPopup.addItem(Messages.OPT_ALLURLS, Messages.OPT_ALLURLS);
0198: targetPopup.addItem(Messages.OPT_UNCLASSIFIEDRDS,
0199: Messages.OPT_UNCLASSIFIEDRDS);
0200: targetPopup.addItem(Messages.OPT_CLASSIFIEDRDS,
0201: Messages.OPT_CLASSIFIEDRDS);
0202: targetPopup.addItem(Messages.OPT_CLASSIFICATIONS,
0203: Messages.OPT_CLASSIFICATIONS);
0204: targetPopup.addItem(Messages.OPT_URL, Messages.OPT_URL);
0205: targetPopup.addItem(Messages.OPT_SEARCH, Messages.OPT_SEARCH);
0206: targetPopup.selectItemAt(1);
0207: searchView.showTextField(false);
0208:
0209: if (m_testMode == true)
0210: targetPopup.addItem("Testing", "Testing");
0211:
0212: targetPopup.sizeTo(targetPopup.popupList().minItemWidth()
0213: + (2 * targetPopup.popupImage().width()), targetPopup
0214: .height());
0215:
0216: searchView.moveTo(targetPopup.x() + targetPopup.width(), 0);
0217: searchView.sizeTo(graphical.Header.IWINDWIDTH - searchView.x()
0218: - 4, searchView.height());
0219:
0220: resultsGrid = new SimpleGrid();
0221:
0222: editAtts = schema.getEditable();
0223: initGridSupport(editAtts.length + STDCOLCOUNT);
0224: int j = STDCOLCOUNT;
0225: for (int i = 0; i < editAtts.length; i++) {
0226: if ("Title".equalsIgnoreCase(editAtts[i])) {
0227: columnEditable[COLTITLE] = true;
0228: } else if ("URL".equalsIgnoreCase(editAtts[i])) {
0229: columnEditable[COLURL] = true;
0230: } else if ("Classification".equalsIgnoreCase(editAtts[i])) {
0231: columnEditable[COLCLASS] = true;
0232: } else {
0233: columnLabel[j] = editAtts[i];
0234: columnEditable[j] = true;
0235: j++;
0236: }
0237: }
0238:
0239: columnTotal = j;
0240: newResultsGrid();
0241:
0242: if (editRDs) {
0243: resultsView = new DragIGREView(graphical.Header.WIDGETHGAP,
0244: searchView.y() + searchView.height(),
0245: graphical.Header.IWINDWIDTH - 4
0246: - (2 * graphical.Header.WIDGETHGAP),
0247: contentSize().height
0248: - (graphical.Header.WIDGETVGAP)
0249: - searchView.height() - menuView.height(),
0250: graphical.DragPolicy.DRAGFROMCOPY,
0251: graphical.DragPolicy.DRAGTOACCEPT, m_normalIcon,
0252: resultsGrid);
0253:
0254: resultsView.setEditableView(true);
0255: } else {
0256: resultsView = new DragIGREView(graphical.Header.WIDGETHGAP,
0257: searchView.y() + searchView.height(),
0258: graphical.Header.IWINDWIDTH - 4
0259: - (2 * graphical.Header.WIDGETHGAP),
0260: contentSize().height
0261: - (graphical.Header.WIDGETVGAP)
0262: - searchView.height() - menuView.height(),
0263: graphical.DragPolicy.DRAGFROMMOVE,
0264: graphical.DragPolicy.DRAGTODISALLOWED,
0265: m_normalIcon, resultsGrid);
0266:
0267: resultsView.setEditableView(false);
0268: }
0269: resultsView.setSourceTarget(this );
0270:
0271: // Register doubleClick command and target.
0272: resultsView.setSelectionTarget(this );
0273: resultsView.setSelectionCommand(
0274: Messages.CMD_SINGLEROWSELECTION,
0275: Messages.CMD_DOUBLEROWSELECTION);
0276: resultsView.setPopupAlways(false);
0277: resultsView.setHasHorizGridLines(false);
0278: resultsView.setHasVertGridLines(false);
0279: resultsView.setMultiSelect(true);
0280:
0281: // Set URL link column.
0282: resultsView.setUrlColumn(COLURL);
0283:
0284: // Set up Icons
0285: resultsView.setIconColumn(COLTAG);
0286: resultsView.setNormalIcon(m_normalIcon);
0287: resultsView.setSelectedIcon(m_selectedIcon);
0288:
0289: // Set selection colors.
0290: resultsView
0291: .setSelectBackgroundColor(graphical.Header.SELECTEDCOLOR);
0292: resultsView.setSelectTextColor(resultsView.textColor());
0293:
0294: setResultsViewGrid();
0295: resultsView.setDestinationTarget(this );
0296:
0297: /* assumes 0th point is icon, assumes 1th exists */
0298: StringBuffer sb = new StringBuffer(columnLabel[1]);
0299: for (int i = 2; i < resultsGrid.columns(); i++) {
0300: sb.append(",");
0301: sb.append(columnLabel[i]);
0302: }
0303:
0304: searchAtts = sb.toString();
0305:
0306: resultsBorder = new IBorderView(resultsView.bounds());
0307: resultsBorder.setBorder(BezelBorder.loweredBezel());
0308: resultsBorder.addSubview(resultsView);
0309: resultsBorder.setHorizResizeInstruction(View.WIDTH_CAN_CHANGE);
0310: resultsBorder.setVertResizeInstruction(View.HEIGHT_CAN_CHANGE);
0311:
0312: // note window width, not min window width
0313: setMinSize(graphical.Header.IWINDWIDTH,
0314: graphical.Header.IWINDMINHEIGHT);
0315: setTitle(windowTitle);
0316:
0317: setRootView(m_externalWindow.rootView());
0318: setMenuView(menuView);
0319: addSubview(searchLabel);
0320: addSubview(targetPopup);
0321: addSubview(searchView);
0322: addSubview(resultsBorder);
0323: setCloseable(true);
0324: setResizable(true);
0325: setCloseCommand(Messages.CMD_CLOSE);
0326: setCloseTarget(this );
0327: }
0328:
0329: private void setEditFlags() {
0330:
0331: // The idea here was to base the capabilities on the how the application
0332: // was started. We have backed off of this and now always use the same
0333: // mode. The rest of the application is set up to check the editRD flags
0334: // so we can easily implement these options again when/if needed.
0335:
0336: editRDs = true;
0337: editTaxonomy = false;
0338:
0339: /*
0340: String title = m_externalWindow.title();
0341:
0342: if (Messages.TITLE_CLASSRD.compareTo(title) == 0) {
0343: editRDs = true;
0344: editTaxonomy = false;
0345: }
0346: else if (Messages.TITLE_EDITRD.compareTo(title) == 0) {
0347: editRDs = true;
0348: editTaxonomy = false;
0349: }
0350: else if (Messages.TITLE_TAXIDERMIST.compareTo(title) == 0) {
0351: editRDs = false;
0352: editTaxonomy = true;
0353: }
0354: else if (Messages.TITLE_TAXIMATOR.compareTo(title) == 0) {
0355: editRDs = true;
0356: editTaxonomy = true;
0357: }
0358: else if (Messages.TITLE_DESKTOP.compareTo(title) == 0) { // Java Desktop
0359: editRDs = true;
0360: editTaxonomy = false;
0361: }
0362: else {
0363: ReportError.reportError(ReportError.ADMIN,
0364: "RDEdit",
0365: "constructor",
0366: Messages.UNKNOWNAPPLICATION
0367: + ": "
0368: + title);
0369: return;
0370: }
0371: */
0372: }
0373:
0374: /*---< grid stuff >--------------------------------------------*/
0375:
0376: private final static int COLTAG = 0;
0377: private final static int COLTITLE = 1;
0378: private final static int COLURL = 2;
0379: private final static int COLCLASS = 3;
0380:
0381: private final static int STDCOLCOUNT = 4;
0382:
0383: private void initGridSupport(int n) {
0384: /* if n < 3, arr outofbounds exceptions will arise */
0385:
0386: columnLabel = new String[n];
0387: columnEditable = new boolean[n];
0388:
0389: columnLabel[COLTAG] = "";
0390: columnLabel[COLTITLE] = "Title";
0391: columnLabel[COLURL] = "URL";
0392: columnLabel[COLCLASS] = "Classification";
0393:
0394: columnEditable[COLTAG] = false;
0395: columnEditable[COLTITLE] = false;
0396: columnEditable[COLURL] = false;
0397: columnEditable[COLCLASS] = false;
0398:
0399: columnTotal = n;
0400: }
0401:
0402: public void newResultsGrid() {
0403: // There is no easy way to remove the contents of a grid so a new
0404: // grid is set after every search. This is also causing the display
0405: // attributes in IGridView to be reset, not sure why it should but it
0406: // is. I need to preserve column widths so I save the column widths
0407: // of the current grid view.
0408:
0409: if (resultsView != null) {
0410: int columns = resultsGrid.columns();
0411: columnWidths = new int[columns];
0412:
0413: for (int i = 0; i < columns; i++) {
0414: columnWidths[i] = resultsView.getColumnWidth(i);
0415: }
0416: }
0417:
0418: resultsGrid = new SimpleGrid();
0419: for (int i = 0; i < columnTotal; i++) {
0420: resultsGrid.setColumnLabel(i, columnLabel[i]);
0421: }
0422: }
0423:
0424: public void setResultsViewGrid() {
0425: resultsView.setGrid(resultsGrid);
0426:
0427: /*
0428: * We are not going to have any editable cells in the search window,
0429: * bring up the properties window instead. But if you want some
0430: * editable rows/columns/cells, here is where you would set them
0431: *
0432: */
0433: /*
0434: if ( editRDs )
0435: {
0436: for ( int i = 0; i < columnTotal; i++ )
0437: {
0438: resultsView.setEditableColumn(i,
0439: columnEditable[ i ]);
0440: }
0441: }
0442: */
0443: }
0444:
0445: public void setNewResultsGrid() {
0446: setResultsViewGrid();
0447: resultsView.adviseSetGrid();
0448:
0449: // There is no easy way to remove the contents of a grid so a new
0450: // grid is set after every search. This is also causing the display
0451: // attributes in IGridView to be reset, not sure why it should but it
0452: // is. I need to preserve column widths so I restore the column widths
0453: // of the previous view.
0454:
0455: int columns = resultsGrid.columns();
0456:
0457: for (int i = 0; i < columns; i++) {
0458: resultsView.setColumnWidth(i, columnWidths[i]);
0459: }
0460:
0461: resultsView.draw();
0462: }
0463:
0464: /*---< perform command >---------------------------------------*/
0465:
0466: public String saveBtnPress() {
0467: StringBuffer sb = new StringBuffer();
0468: String result = null;
0469:
0470: boolean gotMilk = false;
0471:
0472: rootView().setOverrideCursor(View.WAIT_CURSOR);
0473: sb.append("@Request { -\n"
0474: + AVPairs.toSOIF("submit-csid", m_readCSID.toString())
0475: + "submit-type{10}:\tpersistent\n"
0476: + "submit-operation{5}:\tmerge\n"
0477: + "submit-view{14}:\tclassification\n" + "}\n");
0478:
0479: for (int i = 0; i < resultsGrid.rows(); i++) {
0480: Object classObject = resultsGrid.getValue(i, COLCLASS);
0481:
0482: if (classObject == null) {
0483: continue;
0484: }
0485:
0486: String classString = classObject.toString();
0487:
0488: // RD Editor does not fully support multivalues. It displays
0489: // the first value only prefixed by [MV]. I need to skip these,
0490: // they must not be updated. If a multivalue is updated via the
0491: // the drag and drop interface it becomes a single value and will
0492: // get updated correctly.
0493: if (classString.startsWith(Messages.TAG_MULTIVALUE) == true) {
0494: continue;
0495: }
0496:
0497: if (classString.length() > 0) {
0498: gotMilk = true;
0499: sb.append("\n" + "@DOCUMENT { "
0500: + resultsGrid.getValue(i, COLURL) + "\n"
0501: + AVPairs.toSOIF("classification", classString)
0502: + "}" + "\n");
0503: }
0504: }
0505:
0506: if (gotMilk) {
0507: // System.out.println("-----");
0508: // System.out.println(m_writeCGILocation + "bin/rdsubmit");
0509: // System.out.println("-----");
0510: // System.out.println(sb.toString());
0511: // System.out.println("-----");
0512:
0513: if (m_testMode == true) {
0514: System.out.println("Saving======\n" + sb.toString()
0515: + "\n=======");
0516: }
0517:
0518: result = PostConnection.doWrite(m_writeCGILocation
0519: + "bin/rdsubmit", sb.toString(), true);
0520: // System.out.println("Saved");
0521: }
0522:
0523: rootView().removeOverrideCursor();
0524: Alert.runAlertExternally(Alert.notificationImage(),
0525: Messages.SAVED_RD, "", Messages.CMD_OK, null, null);
0526: graphical.Header.showStatus(Messages.SAVED);
0527: m_updated = false; // No unsaved changes
0528: return result;
0529: }
0530:
0531: /**
0532: * Search constants.
0533: **/
0534: private final static int SEARCH_REC_LIMIT = 500;
0535:
0536: public void searchBtnPress() {
0537: String resp = null;
0538: SOIFParser sp = null;
0539: SOIF soifResult;
0540: SOIF soif = null;
0541: String targ = targetPopup.selectedItem().title();
0542: int res = 0;
0543:
0544: if (m_updated == true) { // Unsaved changes?
0545: int answer = Alert.runAlertExternally(Alert
0546: .notificationImage(), Messages.TITLE_RD_UNSAVED,
0547: "", Messages.CMD_SAVE, Messages.CMD_DISCARD,
0548: Messages.CMD_CANCEL);
0549: if (answer == Header.SAVE_SAVE) { // Save
0550: saveBtnPress();
0551: } else if (answer == Header.SAVE_CANCEL) { // Cancel?
0552: return;
0553: }
0554: }
0555:
0556: m_updated = false;
0557:
0558: if ("Testing".equals(targ)) {
0559: startSearch();
0560:
0561: resultsGrid.setValue(0, COLURL, "http://www.netscape.com");
0562: resultsGrid.setValue(0, COLCLASS, "Literature");
0563:
0564: resultsGrid.setValue(1, COLURL, "http://www.microsoft.com");
0565: resultsGrid.setValue(1, COLCLASS, "[MV]Literature");
0566:
0567: resultsGrid.setValue(2, COLURL, "http://www.ibm.com");
0568: resultsGrid.setValue(2, COLCLASS, "Literature");
0569:
0570: resultsGrid.setValue(3, COLURL, "http://www.lotus.com");
0571: resultsGrid.setValue(3, COLCLASS, "Literature");
0572:
0573: endSearch();
0574: } else if (Messages.OPT_ALLURLS.equals(targ)) {
0575: startSearch();
0576: Search search = new Search(
0577: " ", // '*' search broken, use space
0578: "", "", SEARCH_REC_LIMIT, "compass", m_readCSID,
0579: m_readCGILocation);
0580: // System.out.println("searching for======\n" + search.getQuery() + "\n=======");
0581:
0582: search.doQuery();
0583:
0584: if (search.getStatus() == Search.ABEND) {
0585: Alert.runAlertExternally(Alert.notificationImage(),
0586: Messages.ERROR_SEARCH, "", Messages.CMD_OK,
0587: null, null);
0588: } else if (search.resultCount() < search.hitCount()) {
0589: Alert.runAlertExternally(Alert.notificationImage(),
0590: Messages.TITLE_DB_MORE, "", Messages.CMD_OK,
0591: null, null);
0592: }
0593:
0594: soif = search.getSOIFResult();
0595:
0596: if (soif == null) {
0597: Alert.runAlertExternally(Alert.notificationImage(),
0598: Messages.TITLE_DB_EMPTY, "", Messages.CMD_OK,
0599: null, null);
0600: endSearch();
0601: return;
0602: }
0603:
0604: displayRD(0, soif);
0605: endSearch();
0606: } else if (Messages.OPT_UNCLASSIFIEDRDS.equals(targ)) {
0607: startSearch();
0608:
0609: /* Multivalue search is using OR, I need AND so changing search
0610: so the it will work. This should be replaced by a new AND
0611: search.
0612:
0613: Unclassified search: (Classification="")
0614: Changed to: <NOT> (Classification!="")
0615: */
0616:
0617: Search search = new Search("<NOT> (Classification!=\"\")",
0618: "", "", SEARCH_REC_LIMIT, "compass", m_readCSID,
0619: m_readCGILocation);
0620: // System.out.println("searching for======\n" + search.getQuery() + "\n=======");
0621:
0622: search.doQuery();
0623: if (search.getStatus() == Search.ABEND) {
0624: Alert.runAlertExternally(Alert.notificationImage(),
0625: Messages.ERROR_SEARCH, "", Messages.CMD_OK,
0626: null, null);
0627: } else if (search.resultCount() < search.hitCount()) {
0628: Alert.runAlertExternally(Alert.notificationImage(),
0629: Messages.TITLE_DB_MORE, "", Messages.CMD_OK,
0630: null, null);
0631: }
0632:
0633: soif = search.getSOIFResult();
0634:
0635: if (soif == null) {
0636: Alert.runAlertExternally(Alert.notificationImage(),
0637: Messages.TITLE_DB_EMPTY, "", Messages.CMD_OK,
0638: null, null);
0639: endSearch();
0640: return;
0641: }
0642:
0643: displayRD(0, soif);
0644: endSearch();
0645: } else if (Messages.OPT_CLASSIFIEDRDS.equals(targ)) {
0646: startSearch();
0647: Search search = new Search("(Classification!=\"\")", "",
0648: "", SEARCH_REC_LIMIT, "compass", m_readCSID,
0649: m_readCGILocation);
0650:
0651: search.doQuery();
0652: if (search.getStatus() == Search.ABEND) {
0653: Alert.runAlertExternally(Alert.notificationImage(),
0654: Messages.ERROR_SEARCH, "", Messages.CMD_OK,
0655: null, null);
0656: } else if (search.resultCount() < search.hitCount()) {
0657: Alert.runAlertExternally(Alert.notificationImage(),
0658: Messages.TITLE_DB_MORE, "", Messages.CMD_OK,
0659: null, null);
0660: }
0661:
0662: soif = search.getSOIFResult();
0663: // System.out.println("soif======\n" + soif + "\n=======");
0664:
0665: if (soif == null) {
0666: Alert.runAlertExternally(Alert.notificationImage(),
0667: Messages.TITLE_DB_EMPTY, "", Messages.CMD_OK,
0668: null, null);
0669: endSearch();
0670: return;
0671: }
0672:
0673: displayRD(0, soif);
0674: endSearch();
0675: } else if (Messages.OPT_CLASSIFICATIONS.equals(targ)) {
0676: startSearch();
0677: // System.out.println("searching for======\n" + "(Classification=" + searchView.searchPF.selectedItem().title() + ")" + "\n=======");
0678: Search search = new Search("(Classification="
0679: + searchView.searchPF.selectedItem().title() + ")",
0680: "", "", SEARCH_REC_LIMIT, "compass", m_readCSID,
0681: m_readCGILocation);
0682:
0683: search.doQuery();
0684: if (search.getStatus() == Search.ABEND) {
0685: Alert.runAlertExternally(Alert.notificationImage(),
0686: Messages.ERROR_SEARCH, "", Messages.CMD_OK,
0687: null, null);
0688: } else if (search.resultCount() < search.hitCount()) {
0689: Alert.runAlertExternally(Alert.notificationImage(),
0690: Messages.TITLE_DB_MORE, "", Messages.CMD_OK,
0691: null, null);
0692: }
0693:
0694: soif = search.getSOIFResult();
0695:
0696: if (soif == null) {
0697: Alert.runAlertExternally(Alert.notificationImage(),
0698: Messages.TITLE_DB_EMPTY, "", Messages.CMD_OK,
0699: null, null);
0700: endSearch();
0701: return;
0702: }
0703:
0704: displayRD(0, soif);
0705: endSearch();
0706: } else if (Messages.OPT_URL.equals(targ)) {
0707: startSearch();
0708: getEditableRD(0, searchView.searchTF.stringValue());
0709: endSearch();
0710: } else if (Messages.OPT_SEARCH.equals(targ)) {
0711: startSearch();
0712: Search search = new Search(searchView.searchTF
0713: .stringValue(), "", "", SEARCH_REC_LIMIT,
0714: "compass", m_readCSID, m_readCGILocation);
0715:
0716: search.doQuery();
0717: if (search.getStatus() == Search.ABEND) {
0718: Alert.runAlertExternally(Alert.notificationImage(),
0719: Messages.ERROR_SEARCH, "", Messages.CMD_OK,
0720: null, null);
0721: } else if (search.resultCount() < search.hitCount()) {
0722: Alert.runAlertExternally(Alert.notificationImage(),
0723: Messages.TITLE_DB_MORE, "", Messages.CMD_OK,
0724: null, null);
0725: }
0726:
0727: soif = search.getSOIFResult();
0728:
0729: if (soif == null) {
0730: Alert.runAlertExternally(Alert.notificationImage(),
0731: Messages.TITLE_DB_EMPTY, "", Messages.CMD_OK,
0732: null, null);
0733: endSearch();
0734: return;
0735: }
0736:
0737: displayRD(0, soif);
0738: endSearch();
0739: }
0740: }
0741:
0742: /**
0743: * getEditableRD - Get the editable RD fields for a specific URL
0744: * and load into the RD results grid.
0745: **/
0746: public void getEditableRD(int row, String url) {
0747: Search search = new Search(url, "", "", 1, "url", m_readCSID,
0748: m_readCGILocation);
0749: search.doQuery();
0750: SOIF soif = search.getSOIFResult();
0751:
0752: if (soif == null)
0753: Alert.runAlertExternally(Alert.notificationImage(),
0754: Messages.TITLE_DB_EMPTY, "", Messages.CMD_OK, null,
0755: null);
0756: else
0757: displayRD(row, soif);
0758: }
0759:
0760: /**
0761: * displayRD - Display the RD from the SOIF at the specified row.
0762: **/
0763: public void displayRD(int startingRow, SOIF soif) {
0764: if (soif != null) {
0765: int columnCount = resultsGrid.columns();
0766: int row = startingRow;
0767: String soifValue;
0768:
0769: for (; soif != null; soif = soif.next) {
0770: // Must exclude all exclude all no RD soif
0771: // returned as per Darren.
0772: if (soif.getSchemaName().compareTo("DOCUMENT") != 0) {
0773: continue;
0774: }
0775:
0776: for (int i = 1; i < columnCount; i++) {
0777: // Need to access single/multiple values differently. If multiple,
0778: // getValue(attribute) returns null rather than the 1st value so
0779: // I need to use getValue(attribute, 1); Only the first value in a
0780: // multiple value field will be displayed on this summary page.
0781:
0782: int attrCount = soif
0783: .attributeValueCount(resultsGrid
0784: .columnLabel(i).toString());
0785:
0786: if (attrCount == 1) {
0787: soifValue = soif.getValue(resultsGrid
0788: .columnLabel(i).toString());
0789: } else {
0790: soifValue = soif.getValue(resultsGrid
0791: .columnLabel(i).toString(), 1);
0792:
0793: if (soifValue != null) {
0794: soifValue = Messages.TAG_MULTIVALUE
0795: + soifValue;
0796: }
0797: }
0798:
0799: if (soifValue != null) {
0800: resultsGrid.setValue(row, i, soifValue);
0801: }
0802: }
0803:
0804: row++;
0805: }
0806: }
0807: }
0808:
0809: // onSingleClick.
0810: public void refreshPropertyWindow(int row) {
0811: if (propertyWindow == null)
0812: return;
0813:
0814: if (propertyWindow.isVisible() == false)
0815: return;
0816:
0817: Object urlObject = resultsGrid.getValue(row, COLURL);// Get URL
0818: // Classification may have been updated via drag and drop.
0819: Object classObject = resultsGrid.getValue(row, COLCLASS);
0820: propertyWindow.setNewRD(urlObject.toString(), classObject
0821: .toString());
0822: m_activeRow = row;
0823: m_activeURL = urlObject.toString();
0824: propertyWindow.show(); // Bring up Properties window
0825: }
0826:
0827: // onDoubleClick
0828: public void popupPropertyWindow(int row) {
0829: Object urlObject = resultsGrid.getValue(row, COLURL);// Get URL
0830: // Classification may have been updated via drag and drop.
0831: Object classObject = resultsGrid.getValue(row, COLCLASS);
0832:
0833: propertyWindow = new RDPropertyWindow(
0834: graphical.Header.WINDOWHGAP,
0835: graphical.Header.WINDOWVGAP,
0836: graphical.Header.IWINDWIDTH,
0837: graphical.Header.IWINDHEIGHT, urlObject.toString(),
0838: classObject.toString(), editRDs, m_schema, m_taxonomy,
0839: m_readCSID, m_writeCSID, m_readCGILocation,
0840: m_writeCGILocation, m_windowTiler);
0841: propertyWindow.setUpdateTarget(this );
0842: propertyWindow.setUpdateCommand(Messages.CMD_DBUPDATE);
0843:
0844: propertyWindow.setMinimize(bm, components.Messages.LBL_RDPROP,
0845: m_externalWindow, m_windowTiler);
0846: m_windowTiler.addWindow(propertyWindow); // Tile window (set position)
0847:
0848: propertyWindow.show(); // Bring up Properties window
0849: m_activeRow = row;
0850: m_activeURL = urlObject.toString();
0851: }
0852:
0853: /**
0854: * startSearch - Set up prior to starting a search, will set up a new grid,
0855: * display the wait mouse cursor etc.
0856: **/
0857: private void startSearch() {
0858: rootView().setOverrideCursor(View.WAIT_CURSOR);
0859: newResultsGrid();
0860: return;
0861: }
0862:
0863: /**
0864: * endSearch - Set up after a search, will display new grid,
0865: * restore the default mouse cursor etc.
0866: **/
0867: private void endSearch() {
0868: setNewResultsGrid();
0869: rootView().removeOverrideCursor();
0870: return;
0871: }
0872:
0873: /**
0874: * Inform desktop of unsaved changes.
0875: **/
0876: public boolean closeRequest() {
0877: // First check for unsave Rd Property changes
0878: if (propertyWindow != null) {
0879: int answer = propertyWindow.checkForUnsavedChanges();
0880:
0881: if (answer == Header.SAVE_SAVE) { // Save
0882: propertyWindow.saveCommand();
0883: } else if (answer == Header.SAVE_CANCEL) { // Cancel?
0884: return false;
0885: }
0886: }
0887:
0888: // Now check for RD Editor changes
0889: if (m_updated == true) { // Unsaved changes?
0890: int answer = Alert.runAlertExternally(Alert
0891: .notificationImage(), Messages.TITLE_RD_UNSAVED,
0892: "", Messages.CMD_SAVE, Messages.CMD_DISCARD,
0893: Messages.CMD_CANCEL);
0894: if (answer == Header.SAVE_SAVE) { // Save
0895: saveBtnPress();
0896: return true;
0897: } else if (answer == Header.SAVE_CONTINUE) { // Discard?
0898: return true;
0899: }
0900:
0901: return false; // Cancelled - stay open
0902: }
0903:
0904: return true; // No unsaved changes
0905: }
0906:
0907: public void performCommand(String command, Object arg) {
0908:
0909: if (arg instanceof DragArgument) {
0910: DragArgument da = (DragArgument) arg;
0911: // System.out.println( da.toString() );
0912:
0913: /* it's a cast fest! */
0914: // SGP: code reduction opp here, once both
0915: // clauses work
0916: if ((da.destination instanceof DragListView)
0917: && (da.source == resultsView)) {
0918: m_updated = true; // Unsaved changes!
0919: IntVector draggedRows = (IntVector) da.sourceData;
0920: ListItem li = (ListItem) da.destinationData;
0921: BTreeNode btn = (BTreeNode) li.data();
0922: Object o = btn.getValue();
0923:
0924: if (o instanceof TaxonomyNode) {
0925: // Loop thru array of dragged rows and set the value
0926: // of each row classification.
0927: for (int i = 0; i < draggedRows.count(); i++) {
0928: resultsGrid.setValue(draggedRows.elementAt(i),
0929: COLCLASS, ((TaxonomyNode) o).getId());
0930: }
0931:
0932: resultsView.draw();
0933: }
0934: } else if ((da.destination == resultsView)
0935: && (da.source instanceof DragListView)) {
0936: m_updated = true; // Unsaved changes!
0937: Point p = (Point) da.destinationData;
0938: ListItem li = (ListItem) da.sourceData;
0939: BTreeNode btn = (BTreeNode) li.data();
0940: Object o = btn.getValue();
0941: if (o instanceof TaxonomyNode) {
0942: resultsGrid.setValue(p.y, COLCLASS,
0943: ((TaxonomyNode) o).getId());
0944: resultsView.draw();
0945: }
0946: }
0947: } else if (Messages.CMD_NEWTAXWIND.equals(command)) {
0948: TaxonomyTreeWindow taxonomyTreeWindow = new TaxonomyTreeWindow(
0949: graphical.Header.WINDOWHGAP,
0950: graphical.Header.WINDOWVGAP,
0951: graphical.Header.IWINDWIDTH,
0952: graphical.Header.IWINDHEIGHT, m_taxonomy,
0953: editTaxonomy, false, null);
0954: taxonomyTreeWindow.setRootView(m_externalWindow.rootView()); // SGP ??
0955: taxonomyTreeWindow
0956: .setDragSourcePolicy(graphical.DragPolicy.DRAGFROMCOPY);
0957: taxonomyTreeWindow
0958: .setDragDestinationPolicy(graphical.DragPolicy.DRAGTOACCEPT);
0959: taxonomyTreeWindow.setDragDestinationTarget(this );
0960:
0961: taxonomyTreeWindow.setMinimize(bm,
0962: components.Messages.LBL_TAXONOMY, m_externalWindow,
0963: m_windowTiler);
0964:
0965: m_windowTiler.addWindow(taxonomyTreeWindow); // Tile window (set position)
0966: taxonomyTreeWindow.show();
0967: } else if (Messages.CMD_NEWPROPWIND.equals(command)) {
0968: if (resultsView.nothingSelected() == true) {
0969: Alert.runAlertExternally(Alert.notificationImage(),
0970: Messages.TITLE_NO_SEL, "", Messages.CMD_OK,
0971: null, null);
0972: return;
0973: }
0974:
0975: // System.out.println("selected row======\n" + resultsView.selectedRow(0) + "\n=======");
0976:
0977: if ((propertyWindow == null)
0978: || (propertyWindow.isVisible() == false)) {
0979: popupPropertyWindow(resultsView.selectedRow(0));
0980: } else {
0981: refreshPropertyWindow(resultsView.selectedRow(0));
0982: }
0983: } else if (Messages.CMD_NEWRDEDIT.equals(command)) {
0984: RDEditorWindow editorWindow = new RDEditorWindow(
0985: m_externalWindow, windowTiler,
0986: graphical.Header.WINDOWHGAP,
0987: graphical.Header.WINDOWVGAP,
0988: graphical.Header.IWINDWIDTH,
0989: graphical.Header.IWINDHEIGHT, m_testMode, false,
0990: m_schema, m_taxonomy, m_readCGILocation,
0991: m_writeCGILocation, m_readCSID, m_writeCSID);
0992:
0993: editorWindow.setMinimize(bm,
0994: components.Messages.LBL_RDEDIT, m_externalWindow,
0995: windowTiler);
0996: editorWindow.setRootView(m_externalWindow.rootView());
0997: windowTiler.addWindow(editorWindow); // Tile window (set position)
0998: editorWindow.show();
0999: } else if (Messages.CMD_SEARCH.equals(command)) {
1000: searchBtnPress();
1001: } else if (Messages.CMD_SAVE.equals(command)) {
1002: // System.out.println( saveBtnPress() );
1003: saveBtnPress();
1004: } else if (Messages.CMD_CLOSE.equals(command)) {
1005: if (m_updated == true) { // Unsaved changes?
1006: int answer = Alert.runAlertExternally(Alert
1007: .notificationImage(),
1008: Messages.TITLE_RD_UNSAVED, "",
1009: Messages.CMD_SAVE, Messages.CMD_DISCARD,
1010: Messages.CMD_CANCEL);
1011: if (answer == Header.SAVE_SAVE) { // Save
1012: saveBtnPress();
1013: } else if (answer == Header.SAVE_CANCEL) { // Cancel?
1014: return;
1015: }
1016: }
1017:
1018: m_updated = false;
1019:
1020: hide();
1021: return;
1022: }
1023:
1024: else if (Messages.CMD_SINGLEROWSELECTION.equals(command)) // onSingleClick
1025: {
1026: refreshPropertyWindow(((Integer) arg).intValue());
1027: } else if (Messages.CMD_DOUBLEROWSELECTION.equals(command)) // onDoubleClick
1028: {
1029: popupPropertyWindow(((Integer) arg).intValue());
1030: } else if (Messages.OPT_ALLURLS.equals(command)) {
1031: searchView.showPopupField(false);
1032: searchView.showTextField(false);
1033: } else if (Messages.OPT_UNCLASSIFIEDRDS.equals(command)) {
1034: searchView.showPopupField(false);
1035: searchView.showTextField(false);
1036: } else if (Messages.OPT_CLASSIFIEDRDS.equals(command)) {
1037: searchView.showPopupField(false);
1038: searchView.showTextField(false);
1039: } else if (Messages.OPT_CLASSIFICATIONS.equals(command)) {
1040: searchView.showTextField(false);
1041: searchView.showPopupField(true);
1042: searchView.loadPopupField(m_taxonomy);
1043: } else if (Messages.OPT_URL.equals(command)) {
1044: searchView.showPopupField(false);
1045: searchView.showTextField(true);
1046: searchView.enableTextField(true);
1047: } else if (Messages.OPT_SEARCH.equals(command)) {
1048: searchView.showPopupField(false);
1049: searchView.showTextField(true);
1050: searchView.enableTextField(true);
1051: } else if ("Testing".equals(command)) {
1052: searchView.showTextField(false);
1053: searchView.showPopupField(false);
1054: } else if (Messages.CMD_DBUPDATE.equals(command)) // DB Updated?
1055: {
1056: getEditableRD(m_activeRow, m_activeURL);
1057: // Classification may have been updated via properties window.
1058: Object classObject = resultsGrid.getValue(m_activeRow,
1059: COLCLASS);
1060: propertyWindow.setNewClass(classObject.toString());
1061: } else if (applications.Messages.CMD_DESKTOP_BROADCAST
1062: .equals(command)) {
1063: // System.out.println("RD Editor Tax Chg Recd======\n" + "\n=======");
1064:
1065: if (applications.Messages.CMD_TAX_CHG.equals(arg)) {
1066: searchView.loadPopupField(m_taxonomy);
1067: return;
1068: }
1069: } else {
1070: super.performCommand(command, arg);
1071: }
1072: }
1073: }
|