01 /*
02 * Copyright (c) 1995-2010, The University of Sheffield. See the file
03 * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
04 *
05 * This file is part of GATE (see http://gate.ac.uk/), and is free
06 * software, licenced under the GNU Library General Public License,
07 * Version 2, June 1991 (in the distribution as file licence.html,
08 * and also available at http://gate.ac.uk/gate/licence.html).
09 *
10 * Niraj Aswani, 09/March/07
11 *
12 * $Id: TopClassAction.html,v 1.0 2007/03/09 16:13:01 niraj Exp $
13 */
14 package gate.gui.ontology;
15
16 import gate.creole.ontology.*;
17 import gate.gui.MainFrame;
18
19 import java.awt.*;
20 import java.awt.event.ActionEvent;
21 import javax.swing.*;
22
23 /**
24 * Action to create a new Top Class.
25 */
26 public class TopClassAction extends AbstractAction {
27 private static final long serialVersionUID = 3258409543049359926L;
28
29 public TopClassAction(String s, Icon icon) {
30 super(s, icon);
31 mainPanel = new JPanel(new GridBagLayout());
32 GridBagConstraints gbc = new GridBagConstraints();
33 gbc.insets = new Insets(3, 3, 3, 3);
34 gbc.anchor = GridBagConstraints.WEST;
35
36 mainPanel.add(new JLabel("Name Space:"), gbc);
37 mainPanel.add(nameSpace = new JTextField(30), gbc);
38
39 gbc.gridy = 1;
40 mainPanel.add(new JLabel("Class Name:"), gbc);
41 mainPanel.add(className = new JTextField(30), gbc);
42 }
43
44 public void actionPerformed(ActionEvent actionevent) {
45 nameSpace.setText(ontology.getDefaultNameSpace() == null ?
46 "http://gate.ac.uk/example#" : ontology.getDefaultNameSpace());
47 JOptionPane pane = new JOptionPane(mainPanel, JOptionPane.QUESTION_MESSAGE,
48 JOptionPane.OK_CANCEL_OPTION, MainFrame.getIcon("ontology-topclass")) {
49 public void selectInitialValue() {
50 className.requestFocusInWindow();
51 className.selectAll();
52 }
53 };
54 pane.createDialog(MainFrame.getInstance(),"New Top Class").setVisible(true);
55 Object selectedValue = pane.getValue();
56 if (selectedValue != null
57 && selectedValue instanceof Integer
58 && (Integer) selectedValue == JOptionPane.OK_OPTION) {
59 String s = nameSpace.getText();
60 if (!Utils.isValidNameSpace(s)) {
61 JOptionPane.showMessageDialog(MainFrame.getInstance(),
62 "Invalid Name Space: " + s + "\nExample: http://gate.ac.uk/example#");
63 return;
64 }
65 if(!Utils.isValidOntologyResourceName(className.getText())) {
66 JOptionPane.showMessageDialog(MainFrame.getInstance(),
67 "Invalid Class Name: " + className.getText());
68 return;
69 }
70 if(ontology.getOResourceFromMap(s + className.getText()) != null) {
71 JOptionPane.showMessageDialog(MainFrame.getInstance(),"<html>" +
72 "Resource <b>" + s+className.getText() + "</b> already exists.");
73 return;
74 }
75 ontology.addOClass(new URI(nameSpace.getText() + className.getText(),
76 false), OConstants.OWL_CLASS);
77 }
78 }
79
80 public Ontology getOntology() {
81 return ontology;
82 }
83
84 public void setOntology(Ontology ontology) {
85 this.ontology = ontology;
86 }
87
88 protected JTextField nameSpace;
89 protected JTextField className;
90 protected JPanel mainPanel;
91 protected Ontology ontology;
92 }
|