Skip to content

Commit

Permalink
#103 - github- Delete current annotation if layer is changed
Browse files Browse the repository at this point in the history
NO ISSUES - show feature selection only when an annotation is
selected/edited
  • Loading branch information
seyyaw committed Sep 8, 2015
1 parent 959898b commit 48e5db3
Show file tree
Hide file tree
Showing 4 changed files with 238 additions and 49 deletions.
Expand Up @@ -49,6 +49,7 @@
<body>
<wicket:panel>
<form class="annotationFeatureForm" wicket:id="annotationFeatureForm">
<div wicket:id=yesNoModal></div>
<fieldset>
<legend>Actions</legend>
<table>
Expand All @@ -72,7 +73,8 @@
</table>
</fieldset>
<fieldset>
<legend>Features</legend>
<legend>Features</legend>
<div wicket:id="featureEditorsContainer">
<table>
<tr>
<td><label wicket:id="layerName"></label></td>
Expand All @@ -83,7 +85,6 @@
<td><span wicket:id="selectedText" style="color: red"></span></td>
</tr>
</table>
<div wicket:id="featureEditorsContainer">
<table class="hfill">
<tr wicket:id="featureValues">
<td wicket:id="editor"></td>
Expand Down
Expand Up @@ -28,6 +28,7 @@
import static de.tudarmstadt.ukp.clarin.webanno.brat.controller.BratAjaxCasUtil.selectSentenceAt;
import static de.tudarmstadt.ukp.clarin.webanno.brat.controller.BratAjaxCasUtil.setFeature;
import static de.tudarmstadt.ukp.clarin.webanno.brat.controller.TypeUtil.getAdapter;

import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
Expand Down Expand Up @@ -58,6 +59,7 @@
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.AbstractTextComponent;
Expand Down Expand Up @@ -137,6 +139,7 @@ public class AnnotationDetailEditorPanel

private LayerSelector layer;
private Label selectedAnnotationLayer;
private ModalWindow deleteModal;

private List<AnnotationLayer> annotationLayers = new ArrayList<AnnotationLayer>();

Expand Down Expand Up @@ -175,36 +178,7 @@ public AnnotationFeatureForm(String id, BratAnnotatorModel aBModel)
{
super(id, new CompoundPropertyModel<BratAnnotatorModel>(aBModel));

featureModels = new ArrayList<>();

selectedTextLabel = new Label("selectedText", PropertyModel.of(getModelObject(),
"selection.text"));
selectedTextLabel.setOutputMarkupId(true);
add(selectedTextLabel);
add(new Label("layerName","Layer"){
private static final long serialVersionUID = 6084341323607243784L;
@Override
protected void onConfigure()
{
super.onConfigure();
setVisible(bModel.getPreferences().isDefaultLayer());
}

});

add(selectedAnnotationLayer = new Label("selectedAnnotationLayer", new Model<String>())
{
private static final long serialVersionUID = 4059460390544343324L;

@Override
protected void onConfigure()
{
super.onConfigure();
setOutputMarkupId(true);
setVisible(bModel.getPreferences().isDefaultLayer());
}

});
featureModels = new ArrayList<>();
// TODO: to be done soon
/*add(forwardAnnotation = new CheckBox("forwardAnnotation")
{
Expand Down Expand Up @@ -311,7 +285,7 @@ public void onSubmit(AjaxRequestTarget aTarget, Form<?> aForm)
});
reverseButton.setOutputMarkupPlaceholderTag(true);

add(layer = new LayerSelector("defaultAnnotationLayer", annotationLayers, false));
add(layer = new LayerSelector("defaultAnnotationLayer", annotationLayers));

RefreshingView<FeatureModel> featureValues = new FeatureEditorPanelContent(
"featureValues");
Expand All @@ -325,15 +299,60 @@ protected void onConfigure()
{
super.onConfigure();

setVisible(!featureModels.isEmpty());
setVisible(!featureModels.isEmpty()
&& bModel.getSelection().getAnnotation().isSet());
}
};
// Add placeholder since wmc might start out invisible. Without the placeholder we
// cannot make it visible in an AJAX call
featureEditorsContainer.setOutputMarkupPlaceholderTag(true);
featureEditorsContainer.setOutputMarkupId(true);
featureEditorsContainer.add(featureValues);

// the selected text for annotation
selectedTextLabel = new Label("selectedText", PropertyModel.of(getModelObject(),
"selection.text"));
selectedTextLabel.setOutputMarkupId(true);
featureEditorsContainer.add(selectedTextLabel);

featureEditorsContainer.add(new Label("layerName","Layer"){
private static final long serialVersionUID = 6084341323607243784L;
@Override
protected void onConfigure()
{
super.onConfigure();
setVisible(bModel.getPreferences().isDefaultLayer());
}

});

// the annotation layer for the selected annotation
selectedAnnotationLayer = new Label("selectedAnnotationLayer", new Model<String>())
{
private static final long serialVersionUID = 4059460390544343324L;

@Override
protected void onConfigure()
{
super.onConfigure();
setOutputMarkupId(true);
setVisible(bModel.getPreferences().isDefaultLayer());
}

};
featureEditorsContainer.add(selectedAnnotationLayer);

add(featureEditorsContainer);

add(deleteModal = new ModalWindow("yesNoModal"));
deleteModal.setOutputMarkupId(true);

deleteModal.setInitialWidth(400);
deleteModal.setInitialHeight(50);
deleteModal.setResizable(true);
deleteModal.setWidthUnit("px");
deleteModal.setHeightUnit("px");
deleteModal.setTitle("Are you sure you want to delete the annotation?");
}
}

Expand Down Expand Up @@ -466,7 +485,7 @@ else if (adapter instanceof SpanAdapter) {
onAnnotate(aTarget, aBModel, selection.getBegin(), selection.getEnd());
}

private void actionDelete(AjaxRequestTarget aTarget, BratAnnotatorModel aBModel)
public void actionDelete(AjaxRequestTarget aTarget, BratAnnotatorModel aBModel)
throws IOException, UIMAException, ClassNotFoundException, CASRuntimeException,
BratAnnotationException
{
Expand Down Expand Up @@ -638,7 +657,6 @@ private void actionDelete(AjaxRequestTarget aTarget, BratAnnotatorModel aBModel)
// after delete will follow annotation
bModel.getSelection().setAnnotate(true);
aTarget.add(annotationFeatureForm);
// TODO aTarget.add(relationAnnotationFeatureForm.featureEditorsContainer);

aTarget.add(deleteButton);
aTarget.add(reverseButton);
Expand Down Expand Up @@ -1724,7 +1742,7 @@ public boolean isDropOrchoice()
}
};

private void populateFeatures(FeatureStructure aFS)
public void populateFeatures(FeatureStructure aFS)
{
featureModels = new ArrayList<>();

Expand Down Expand Up @@ -1808,8 +1826,7 @@ public class LayerSelector
{
private static final long serialVersionUID = 2233133653137312264L;

public LayerSelector(String aId, List<? extends AnnotationLayer> aChoices,
final boolean aIsRelation)
public LayerSelector(String aId, List<? extends AnnotationLayer> aChoices)
{
super(aId, aChoices);
setOutputMarkupId(true);
Expand All @@ -1821,16 +1838,33 @@ public LayerSelector(String aId, List<? extends AnnotationLayer> aChoices,
@Override
protected void onUpdate(AjaxRequestTarget aTarget)
{
// user like to annotate with different layer - //TODO - remove the
// annotation selection highlight color
bModel.getSelection().setAnnotate(true);
bModel.getSelection().setAnnotation(VID.NONE_ID);
bModel.setSelectedAnnotationLayer(getModelObject());
selectedAnnotationLayer.setDefaultModelObject(getModelObject().getUiName());
aTarget.add(selectedAnnotationLayer);
populateFeatures(null);
aTarget.add(annotationFeatureForm);
// aTarget.add(forwardAnnotation);
if (!bModel.getSelectedAnnotationLayer().equals(getModelObject())
&& bModel.getSelection().getAnnotation().isSet()) {
deleteModal.setContent(new YesNoDeleteModalPanel(deleteModal.getContentId(),
bModel, deleteModal, AnnotationDetailEditorPanel.this,
getModelObject()));

deleteModal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback()
{
private static final long serialVersionUID = 4364820331676014559L;

@Override
public void onClose(AjaxRequestTarget target)
{
System.out.println(bModel.getDefaultAnnotationLayer().getUiName());
target.add(annotationFeatureForm);

}
});
deleteModal.show(aTarget);
}
else {
bModel.setSelectedAnnotationLayer(getModelObject());
selectedAnnotationLayer.setDefaultModelObject(getModelObject().getUiName());
aTarget.add(selectedAnnotationLayer);
populateFeatures(null);
aTarget.add(annotationFeatureForm);
}
}
});
}
Expand Down Expand Up @@ -2038,6 +2072,19 @@ public void clearArmedSlotModel()
}
}




public AnnotationFeatureForm getAnnotationFeatureForm()
{
return annotationFeatureForm;
}

public Label getSelectedAnnotationLayer()
{
return selectedAnnotationLayer;
}

private boolean isFeatureModelChanged(AnnotationLayer aLayer){

for(FeatureModel fM: featureModels){
Expand Down
@@ -0,0 +1,38 @@
<!--
#Copyright 2012
#Ubiquitous Knowledge Processing (UKP) Lab and FG Language Technology
#Technische Universit盲t Darmstadt
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
-->
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<wicket:panel>
<table style=" margin-left:auto; margin-right:auto;">
<tr>
<td>
</td>
<td>
<form wicket:id="yesNoButtonsForm" >
<button wicket:id="yesButton">
Yes
</button>
<button wicket:id="noButton">
No
</button>
</form>
</td>
</tr>
</table>
</wicket:panel>
</html>

0 comments on commit 48e5db3

Please sign in to comment.