public void actionPerformed(ActionEvent actionevent) {
    OResource selectedNode = ((OResourceNode) selectedNodes.get(0).getUserObject()).getResource();
    String ns = selectedNode.getONodeID().getNameSpace();
    if (gate.creole.ontology.Utils.hasSystemNameSpace(selectedNode.getONodeID().toString())) {
      ns = ontology.getDefaultNameSpace();
    }
    nameSpace.setText(ns);

    nameSpace.setText(
        ontology.getDefaultNameSpace() == null
            ? "http://gate.ac.uk/example#"
            : ontology.getDefaultNameSpace());
    JOptionPane pane =
        new JOptionPane(
            mainPanel,
            JOptionPane.QUESTION_MESSAGE,
            JOptionPane.OK_CANCEL_OPTION,
            MainFrame.getIcon("ontology-instance")) {
          public void selectInitialValue() {
            instanceName.requestFocusInWindow();
            instanceName.selectAll();
          }
        };
    pane.createDialog(MainFrame.getInstance(), "New Instance").setVisible(true);
    Object selectedValue = pane.getValue();
    if (selectedValue != null
        && selectedValue instanceof Integer
        && (Integer) selectedValue == JOptionPane.OK_OPTION) {
      String s = nameSpace.getText();
      if (!Utils.isValidNameSpace(s)) {
        JOptionPane.showMessageDialog(
            MainFrame.getInstance(),
            "Invalid Name Space: " + s + "\nExample: http://gate.ac.uk/example#");
        return;
      }
      if (!Utils.isValidOntologyResourceName(instanceName.getText())) {
        JOptionPane.showMessageDialog(
            MainFrame.getInstance(), "Invalid Instance: " + instanceName.getText());
        return;
      }
      if (Utils.getOResourceFromMap(ontology, s + instanceName.getText()) != null) {
        JOptionPane.showMessageDialog(
            MainFrame.getInstance(),
            "<html>" + "Resource <b>" + s + instanceName.getText() + "</b> already exists.");
        return;
      }

      for (int i = 0; i < selectedNodes.size(); i++) {
        Object obj = ((OResourceNode) selectedNodes.get(i).getUserObject()).getResource();
        if (obj instanceof OClass) {
          ontology.addOInstance(
              ontology.createOURI(nameSpace.getText() + instanceName.getText()), (OClass) obj);
        }
      }
    }
  }
Beispiel #2
0
  public void actionPerformed(ActionEvent ae) {
    JDialog saveDialog = new JDialog(MainFrame.getInstance(), "Save Termbank as CSV", true);
    MainFrame.getGuiRoots().add(saveDialog);
    saveDialog.setLayout(new BorderLayout());
    SliderPanel sliderPanel = new SliderPanel(termbank, "save", true, null);
    saveDialog.add(sliderPanel, BorderLayout.CENTER);

    JPanel chooserPanel = new JPanel();
    chooserPanel.setLayout(new BoxLayout(chooserPanel, BoxLayout.Y_AXIS));
    chooserPanel.add(new JSeparator());

    JFileChooser chooser = new JFileChooser();
    FileNameExtensionFilter filter =
        new FileNameExtensionFilter("CSV files", Utilities.EXTENSION_CSV);
    chooser.setFileFilter(filter);
    chooser.setApproveButtonText("Save");
    chooser.addActionListener(
        new CsvFileSelectionActionListener(chooser, termbank, sliderPanel, saveDialog, Mode.SAVE));
    chooserPanel.add(chooser);
    saveDialog.add(chooserPanel, BorderLayout.SOUTH);
    saveDialog.pack();
    saveDialog.setLocationRelativeTo(saveDialog.getOwner());
    saveDialog.setVisible(true);
  }