Skip to content

Commit

Permalink
Closes #382
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhorridge committed Apr 27, 2016
1 parent 9e8678b commit a5fd784
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.protege.editor.owl.ui.editor;

import org.protege.editor.core.ui.util.AugmentedJTextField;
import org.protege.editor.core.ui.util.InputVerificationStatusChangedListener;
import org.protege.editor.core.ui.util.VerifiedInputEditor;
import org.protege.editor.owl.OWLEditorKit;
import org.protege.editor.owl.model.OWLModelManager;
import org.protege.editor.owl.model.classexpression.OWLExpressionParserException;
Expand All @@ -11,6 +13,8 @@
import org.semanticweb.owlapi.model.OWLObjectProperty;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.*;
import java.util.Collections;

Expand All @@ -19,21 +23,61 @@
* Stanford Center for Biomedical Informatics Research
* 22/09/15
*/
public class OWLObjectPropertyIndividualPairEditor2 extends AbstractOWLObjectEditor<OWLObjectPropertyIndividualPair> {
public class OWLObjectPropertyIndividualPairEditor2 extends AbstractOWLObjectEditor<OWLObjectPropertyIndividualPair> implements VerifiedInputEditor {

private JTextField objectPropertyField;

private JTextField individualField;

private JPanel panelHolder;

private JPanel panel;

private OWLModelManager modelManager;

private JLabel errorLabel = new JLabel(" ");

private InputVerificationStatusChangedListener verificationStatusChangedListener = newState -> {};

public OWLObjectPropertyIndividualPairEditor2(OWLEditorKit editorKit) {
this.modelManager = editorKit.getOWLModelManager();
panelHolder = new JPanel(new BorderLayout());
panel = new JPanel(new GridBagLayout());
panelHolder.add(panel, BorderLayout.NORTH);
objectPropertyField = new AugmentedJTextField("", 20, "Enter object property name");
objectPropertyField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
validateInput();
}

@Override
public void removeUpdate(DocumentEvent e) {
validateInput();
}

@Override
public void changedUpdate(DocumentEvent e) {

}
});
individualField = new AugmentedJTextField("", 20, "Enter individual name");
individualField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
validateInput();
}

@Override
public void removeUpdate(DocumentEvent e) {
validateInput();
}

@Override
public void changedUpdate(DocumentEvent e) {

}
});
Insets insets = new Insets(2, 2, 2, 2);
panel.add(objectPropertyField,
new GridBagConstraints(
Expand All @@ -53,12 +97,25 @@ public OWLObjectPropertyIndividualPairEditor2(OWLEditorKit editorKit) {
GridBagConstraints.HORIZONTAL,
insets,
0, 0));

errorLabel.setForeground(Color.RED);
panel.add(errorLabel,
new GridBagConstraints(
0, 1,
2, 1,
100, 0,
GridBagConstraints.BASELINE_TRAILING,
GridBagConstraints.HORIZONTAL,
insets,
0, 0
));

JLabel tipLabel = new JLabel("(Tip: Use CTRL+Space to auto-complete names)");
tipLabel.setForeground(Color.GRAY);
tipLabel.setHorizontalAlignment(SwingConstants.RIGHT);
panel.add(tipLabel,
new GridBagConstraints(
0, 1,
0, 2,
2, 1,
100, 0,
GridBagConstraints.BASELINE_TRAILING,
Expand Down Expand Up @@ -92,6 +149,36 @@ public Object createObject(String text) throws OWLExpressionParserException {
return modelManager.getOWLEntityFinder().getOWLIndividual(text);
}
});
validateInput();
}

private void validateInput() {
objectPropertyField.setToolTipText(null);
individualField.setToolTipText(null);
errorLabel.setText(" ");

String objectPropertyName = objectPropertyField.getText().trim();
if(!objectPropertyName.isEmpty() && modelManager.getOWLEntityFinder().getOWLObjectProperty(objectPropertyName) == null) {
objectPropertyField.setToolTipText("Invalid object property");
errorLabel.setText("Invalid property name");
verificationStatusChangedListener.verifiedStatusChanged(false);
return;
}

String individualName = individualField.getText().trim();
if(!individualName.isEmpty() && modelManager.getOWLEntityFinder().getOWLIndividual(individualName) == null) {
individualField.setToolTipText("Invalid individual name");
errorLabel.setText("Invalid individual name");
verificationStatusChangedListener.verifiedStatusChanged(false);
return;
}
if (objectPropertyName.isEmpty() || individualName.isEmpty()) {
verificationStatusChangedListener.verifiedStatusChanged(false);
return;
}
verificationStatusChangedListener.verifiedStatusChanged(true);


}

@Override
Expand All @@ -106,7 +193,7 @@ public boolean canEdit(Object object) {

@Override
public JComponent getEditorComponent() {
return panel;
return panelHolder;
}

@Override
Expand Down Expand Up @@ -139,4 +226,20 @@ public boolean setEditedObject(OWLObjectPropertyIndividualPair editedObject) {
public void dispose() {

}

@Override
public void addStatusChangedListener(InputVerificationStatusChangedListener listener) {
if (listener != null) {
this.verificationStatusChangedListener = listener;
}
else {
verificationStatusChangedListener = (newState) -> {};
}
validateInput();
}

@Override
public void removeStatusChangedListener(InputVerificationStatusChangedListener listener) {
this.verificationStatusChangedListener = (newState) -> {};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ public void visit(OWLTransitiveObjectPropertyAxiom axiom) {


public void visit(SWRLRule rule) {

}
}

Expand Down

0 comments on commit a5fd784

Please sign in to comment.