private void setCategories(Combo categoryCombo) { // set default category for combo box categoryCombo.add("Any Category"); categoryCombo.setText("Any Category"); categoryKey = "any"; categories = getCategories(); if (categories != null) { Iterator categoriesIterator = categories.iterator(); while (categoriesIterator.hasNext()) { ConceptType category = (ConceptType) categoriesIterator.next(); String name = category.getName(); categoryCombo.add(name); } } return; }
/** * Constructor to create an editor to update/create an ontology entry * * @param display - points back to the display * @param oureditOntEntry - the entry being edited * @param ontParent - the edited item's parent in the hierarchy * @param newItem - true if this is a new item */ public EditOntEntry( Display display, OntEntry oureditOntEntry, OntEntry ontParent, boolean newItem) { super(); shell = new Shell(display, SWT.DIALOG_TRIM | SWT.PRIMARY_MODAL); shell.setText("OntEntry Information"); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 3; gridLayout.marginHeight = 5; gridLayout.makeColumnsEqualWidth = true; shell.setLayout(gridLayout); ourOntEntry = oureditOntEntry; ourParent = ontParent; if (newItem) { ourOntEntry.setName(""); ourOntEntry.setImportance(Importance.MODERATE); } new Label(shell, SWT.NONE).setText("Name:"); nameField = new Text(shell, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL); nameField.setText(ourOntEntry.getName()); GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING); DisplayUtilities.setTextDimensions(nameField, gridData, 75); gridData.horizontalSpan = 2; nameField.setLayoutData(gridData); new Label(shell, SWT.NONE).setText("Description:"); descArea = new Text(shell, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL); descArea.setText(ourOntEntry.getDescription()); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); DisplayUtilities.setTextDimensions(descArea, gridData, 75, 5); gridData.horizontalSpan = 2; gridData.heightHint = descArea.getLineHeight() * 3; descArea.setLayoutData(gridData); new Label(shell, SWT.NONE).setText("Importance:"); importanceBox = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY); Enumeration impEnum = Importance.elements(); int l = 0; Importance itype; while (impEnum.hasMoreElements()) { itype = (Importance) impEnum.nextElement(); importanceBox.add(itype.toString()); if (itype.toString().compareTo(ourOntEntry.getImportance().toString()) == 0) { importanceBox.select(l); } l++; } // Error checking: if no such selection is valid, set it to select index 0 if (importanceBox.getSelectionIndex() == -1) { importanceBox.select(0); } importanceBox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); new Label(shell, SWT.NONE).setText(" "); new Label(shell, SWT.NONE).setText(" "); addButton = new Button(shell, SWT.PUSH); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING); addButton.setLayoutData(gridData); if (newItem) { addButton.setText("Add"); addButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { canceled = false; if (!nameField.getText().trim().equals("")) { ConsistencyChecker checker = new ConsistencyChecker(ourOntEntry.getID(), nameField.getText(), "OntEntries"); if (ourOntEntry.getName() == nameField.getText() || checker.check()) { ourParent.addChild(ourOntEntry); ourOntEntry.setLevel(ourParent.getLevel() + 1); ourOntEntry.setName(nameField.getText()); ourOntEntry.setDescription(descArea.getText()); ourOntEntry.setImportance( Importance.fromString( importanceBox.getItem(importanceBox.getSelectionIndex()))); // comment before this made no sense... ourOntEntry.setID(ourOntEntry.toDatabase(ourParent.getID())); System.out.println("Name of added item = " + ourOntEntry.getName()); shell.close(); shell.dispose(); } } else { MessageBox mbox = new MessageBox(shell, SWT.ICON_ERROR); mbox.setMessage("Need to provide the OntEntry name"); mbox.open(); } } }); } else { addButton.setText("Save"); addButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { canceled = false; ConsistencyChecker checker = new ConsistencyChecker(ourOntEntry.getID(), nameField.getText(), "OntEntries"); if (ourOntEntry.getName() == nameField.getText() || checker.check()) { ourOntEntry.setName(nameField.getText()); ourOntEntry.setDescription(descArea.getText()); ourOntEntry.setImportance( Importance.fromString( importanceBox.getItem(importanceBox.getSelectionIndex()))); // since this is a save, not an add, the type and parent are ignored ourOntEntry.setID(ourOntEntry.toDatabase(0)); // RationaleDB db = RationaleDB.getHandle(); // db.addOntEntry(ourOntEntry); shell.close(); shell.dispose(); } } }); } cancelButton = new Button(shell, SWT.PUSH); cancelButton.setText("Cancel"); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING); cancelButton.setLayoutData(gridData); cancelButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { canceled = true; shell.close(); shell.dispose(); } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }
public Control getFindTabControl(TabFolder tabFolder) { // Find Composite Composite compositeFind = new Composite(tabFolder, SWT.NULL); GridLayout gridLayout = new GridLayout(2, false); compositeFind.setLayout(gridLayout); /* GridData fromTreeGridData = new GridData (GridData.FILL_BOTH); fromTreeGridData.grabExcessHorizontalSpace = true; fromTreeGridData.grabExcessVerticalSpace = true; // fromTreeGridData.widthHint = 300; compositeFind.setLayoutData(fromTreeGridData); */ // First Set up the match combo box final Combo matchCombo = new Combo(compositeFind, SWT.READ_ONLY); matchCombo.add("Starting with"); matchCombo.add("Ending with"); matchCombo.add("Containing"); matchCombo.add("Exact"); // set default category matchCombo.setText("Containing"); match = "Containing"; matchCombo.addSelectionListener( new SelectionListener() { public void widgetSelected(SelectionEvent e) { // Item in list has been selected match = matchCombo.getItem(matchCombo.getSelectionIndex()); } public void widgetDefaultSelected(SelectionEvent e) { // this is not an option (text cant be entered) } }); // Then set up the Find text combo box final Combo findCombo = new Combo(compositeFind, SWT.DROP_DOWN); GridData findComboData = new GridData(GridData.FILL_HORIZONTAL); findComboData.widthHint = 200; findComboData.horizontalSpan = 1; findCombo.setLayoutData(findComboData); findCombo.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent e) { // Text Item has been entered // Does not require 'return' to be entered findText = findCombo.getText(); } }); findCombo.addSelectionListener( new SelectionListener() { public void widgetSelected(SelectionEvent e) {} public void widgetDefaultSelected(SelectionEvent e) { findText = findCombo.getText(); if (findCombo.indexOf(findText) < 0) { findCombo.add(findText); } if (findButton.getText().equals("Find")) { slm.setMessage("Performing search"); slm.update(true); browser.flush(); ModifierComposite.getInstance().disableComposite(); System.setProperty("statusMessage", "Calling WebService"); TreeNode placeholder = new TreeNode(1, "placeholder", "working...", "C-UNDEF"); browser.rootNode.addChild(placeholder); browser.refresh(); browser.getFindData(categoryKey, categories, findText, match).start(); findButton.setText("Cancel"); } else { System.setProperty("statusMessage", "Canceling WebService call"); browser.refresh(); browser.stopRunning = true; findButton.setText("Find"); } } }); // Next include 'Find' Button findButton = new Button(compositeFind, SWT.PUSH); findButton.setText("Find"); GridData findButtonData = new GridData(); if (OS.startsWith("mac")) findButtonData.widthHint = 80; else findButtonData.widthHint = 60; findButton.setLayoutData(findButtonData); findButton.addMouseListener( new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { // Add item to findCombo drop down list if not already there if (findText == null) { return; } if (findCombo.indexOf(findText) < 0) { findCombo.add(findText); } if (findButton.getText().equals("Find")) { ModifierComposite.getInstance().disableComposite(); browser.flush(); System.setProperty("statusMessage", "Calling WebService"); TreeNode placeholder = new TreeNode(1, "placeholder", "working...", "C-UNDEF"); browser.rootNode.addChild(placeholder); browser.refresh(); browser.getFindData(categoryKey, categories, findText, match).start(); findButton.setText("Cancel"); } else { System.setProperty("statusMessage", "Canceling WebService call"); browser.refresh(); browser.stopRunning = true; findButton.setText("Find"); } } }); // Next set up the category combo box final Combo categoryCombo = new Combo(compositeFind, SWT.READ_ONLY); setCategories(categoryCombo); categoryCombo.addSelectionListener( new SelectionListener() { public void widgetSelected(SelectionEvent e) { // Item in list has been selected if (categoryCombo.getSelectionIndex() == 0) categoryKey = "any"; else { ConceptType concept = (ConceptType) categories.get(categoryCombo.getSelectionIndex() - 1); categoryKey = StringUtil.getTableCd(concept.getKey()); } } public void widgetDefaultSelected(SelectionEvent e) { // this is not an option (text cant be entered) } }); ModifierComposite.setInstance(compositeFind); browser = new NodeBrowser(compositeFind, 1, findButton, slm); return compositeFind; }