Beispiel #1
0
  /**
   * 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();
    }
  }
  /** @see OpenGLTab#createControls(Composite) */
  void createControls(Composite composite) {
    Group movementGroup = new Group(composite, SWT.NONE);
    movementGroup.setText("Translation");
    movementGroup.setLayout(new GridLayout(2, false));

    new Label(movementGroup, SWT.NONE).setText("X:");
    final Slider xMove = new Slider(movementGroup, SWT.NONE);
    xMove.setIncrement(1);
    xMove.setMaximum(12);
    xMove.setMinimum(0);
    xMove.setThumb(2);
    xMove.setPageIncrement(2);
    xMove.setSelection(5);
    xMove.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event e) {
            xPos = xMove.getSelection() - 5;
          }
        });

    new Label(movementGroup, SWT.NONE).setText("Y:");
    final Slider yMove = new Slider(movementGroup, SWT.NONE);
    yMove.setIncrement(1);
    yMove.setMaximum(12);
    yMove.setMinimum(0);
    yMove.setThumb(2);
    yMove.setPageIncrement(2);
    yMove.setSelection(5);
    yMove.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event e) {
            yPos = yMove.getSelection() - 5;
          }
        });

    new Label(movementGroup, SWT.NONE).setText("Z:");
    final Slider zMove = new Slider(movementGroup, SWT.NONE);
    zMove.setIncrement(1);
    zMove.setMaximum(24);
    zMove.setMinimum(0);
    zMove.setThumb(4);
    zMove.setPageIncrement(2);
    zMove.setSelection(10);
    zMove.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event e) {
            zPos = zMove.getSelection() - 25;
          }
        });

    Composite fogTypesGroup = new Composite(composite, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    fogTypesGroup.setLayout(layout);
    fogTypesGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    new Label(fogTypesGroup, SWT.NONE).setText("Fog Types:");
    final Combo fogTypeCombo = new Combo(fogTypesGroup, SWT.READ_ONLY);
    GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    data.grabExcessHorizontalSpace = true;
    fogTypeCombo.setLayoutData(data);
    fogTypeCombo.setItems(FOG_NAMES);
    fogTypeCombo.select(0);

    new Label(composite, SWT.NONE).setText("Fog Density:");
    final Slider fogDensitySlider = new Slider(composite, SWT.NONE);
    fogDensitySlider.setIncrement(1);
    fogDensitySlider.setMaximum(32);
    fogDensitySlider.setMinimum(0);
    fogDensitySlider.setThumb(2);
    fogDensitySlider.setPageIncrement(5);
    fogDensitySlider.setSelection(0);
    fogDensitySlider.setEnabled(false);
    fogDensitySlider.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event e) {
            float fogDensity = ((float) fogDensitySlider.getSelection()) / 100;
            GL.glFogf(GL.GL_FOG_DENSITY, fogDensity);
          }
        });
    fogTypeCombo.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event e) {
            int currentSelection = fogTypeCombo.getSelectionIndex();
            // fog type GL.GL_LINEAR does not utilize fogDensity, but the other fog types do
            fogDensitySlider.setEnabled(currentSelection != 0);
            GL.glFogf(GL.GL_FOG_MODE, FOG_TYPES[currentSelection]);
          }
        });
  }
Beispiel #3
0
  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;
  }