-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3817 - Support undo/redo for document metadata annotations
- Refactor undo support into an extension point
- Loading branch information
Showing
9 changed files
with
392 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...clarin/webanno/ui/annotation/actionbar/undo/actions/ChainAnnotationActionUndoSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to the Technische Universität Darmstadt under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The Technische Universität Darmstadt | ||
* licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. | ||
* | ||
* 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. | ||
*/ | ||
package de.tudarmstadt.ukp.clarin.webanno.ui.annotation.actionbar.undo.actions; | ||
|
||
import org.springframework.context.ApplicationEvent; | ||
|
||
import de.tudarmstadt.ukp.inception.annotation.layer.chain.ChainLinkCreatedEvent; | ||
import de.tudarmstadt.ukp.inception.annotation.layer.chain.ChainSpanCreatedEvent; | ||
import de.tudarmstadt.ukp.inception.annotation.layer.chain.ChainSpanEvent; | ||
import de.tudarmstadt.ukp.inception.schema.AnnotationSchemaService; | ||
|
||
public class ChainAnnotationActionUndoSupport | ||
implements UndoableAnnotationActionSupport | ||
{ | ||
private final AnnotationSchemaService schemaService; | ||
|
||
public ChainAnnotationActionUndoSupport(AnnotationSchemaService aSchemaService) | ||
{ | ||
schemaService = aSchemaService; | ||
} | ||
|
||
@Override | ||
public boolean accepts(ApplicationEvent aContext) | ||
{ | ||
return aContext instanceof ChainSpanEvent; | ||
} | ||
|
||
@Override | ||
public UndoableAnnotationAction actionForEvent(long aRequestId, ApplicationEvent aEvent) | ||
{ | ||
if (aEvent instanceof ChainSpanCreatedEvent) { | ||
return new CreateChainSpanAnnotationAction(aRequestId, schemaService, | ||
(ChainSpanCreatedEvent) aEvent); | ||
} | ||
|
||
if (aEvent instanceof ChainLinkCreatedEvent) { | ||
return new CreateChainLinkAnnotationAction(aRequestId, schemaService, | ||
(ChainLinkCreatedEvent) aEvent); | ||
} | ||
|
||
throw new IllegalArgumentException("Not an undoable action: [" + aEvent.getClass() + "]"); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...kp/clarin/webanno/ui/annotation/actionbar/undo/actions/FeatureValueActionUndoSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Licensed to the Technische Universität Darmstadt under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The Technische Universität Darmstadt | ||
* licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. | ||
* | ||
* 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. | ||
*/ | ||
package de.tudarmstadt.ukp.clarin.webanno.ui.annotation.actionbar.undo.actions; | ||
|
||
import org.springframework.context.ApplicationEvent; | ||
|
||
import de.tudarmstadt.ukp.inception.annotation.events.FeatureValueUpdatedEvent; | ||
import de.tudarmstadt.ukp.inception.schema.AnnotationSchemaService; | ||
|
||
public class FeatureValueActionUndoSupport | ||
implements UndoableAnnotationActionSupport | ||
{ | ||
private final AnnotationSchemaService schemaService; | ||
|
||
public FeatureValueActionUndoSupport(AnnotationSchemaService aSchemaService) | ||
{ | ||
schemaService = aSchemaService; | ||
} | ||
|
||
@Override | ||
public boolean accepts(ApplicationEvent aContext) | ||
{ | ||
return aContext instanceof FeatureValueUpdatedEvent; | ||
} | ||
|
||
@Override | ||
public UndoableAnnotationAction actionForEvent(long aRequestId, ApplicationEvent aEvent) | ||
{ | ||
if (aEvent instanceof FeatureValueUpdatedEvent) { | ||
return new UpdateFeatureValueAnnotationAction(aRequestId, schemaService, | ||
(FeatureValueUpdatedEvent) aEvent); | ||
} | ||
|
||
throw new IllegalArgumentException("Not an undoable action: [" + aEvent.getClass() + "]"); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...rin/webanno/ui/annotation/actionbar/undo/actions/RelationAnnotationActionUndoSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to the Technische Universität Darmstadt under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The Technische Universität Darmstadt | ||
* licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. | ||
* | ||
* 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. | ||
*/ | ||
package de.tudarmstadt.ukp.clarin.webanno.ui.annotation.actionbar.undo.actions; | ||
|
||
import org.springframework.context.ApplicationEvent; | ||
|
||
import de.tudarmstadt.ukp.inception.annotation.layer.relation.RelationCreatedEvent; | ||
import de.tudarmstadt.ukp.inception.annotation.layer.relation.RelationDeletedEvent; | ||
import de.tudarmstadt.ukp.inception.annotation.layer.relation.RelationEvent; | ||
import de.tudarmstadt.ukp.inception.schema.AnnotationSchemaService; | ||
|
||
public class RelationAnnotationActionUndoSupport | ||
implements UndoableAnnotationActionSupport | ||
{ | ||
private final AnnotationSchemaService schemaService; | ||
|
||
public RelationAnnotationActionUndoSupport(AnnotationSchemaService aSchemaService) | ||
{ | ||
schemaService = aSchemaService; | ||
} | ||
|
||
@Override | ||
public boolean accepts(ApplicationEvent aContext) | ||
{ | ||
return aContext instanceof RelationEvent; | ||
} | ||
|
||
@Override | ||
public UndoableAnnotationAction actionForEvent(long aRequestId, ApplicationEvent aEvent) | ||
{ | ||
if (aEvent instanceof RelationCreatedEvent) { | ||
return new CreateRelationAnnotationAction(aRequestId, schemaService, | ||
(RelationCreatedEvent) aEvent); | ||
} | ||
|
||
if (aEvent instanceof RelationDeletedEvent) { | ||
return new DeleteRelationAnnotationAction(aRequestId, schemaService, | ||
(RelationDeletedEvent) aEvent); | ||
} | ||
|
||
throw new IllegalArgumentException("Not an undoable action: [" + aEvent.getClass() + "]"); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
.../clarin/webanno/ui/annotation/actionbar/undo/actions/SpanAnnotationActionUndoSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Licensed to the Technische Universität Darmstadt under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The Technische Universität Darmstadt | ||
* licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. | ||
* | ||
* 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. | ||
*/ | ||
package de.tudarmstadt.ukp.clarin.webanno.ui.annotation.actionbar.undo.actions; | ||
|
||
import org.springframework.context.ApplicationEvent; | ||
|
||
import de.tudarmstadt.ukp.inception.annotation.layer.span.SpanCreatedEvent; | ||
import de.tudarmstadt.ukp.inception.annotation.layer.span.SpanDeletedEvent; | ||
import de.tudarmstadt.ukp.inception.annotation.layer.span.SpanEvent; | ||
import de.tudarmstadt.ukp.inception.annotation.layer.span.SpanMovedEvent; | ||
import de.tudarmstadt.ukp.inception.schema.AnnotationSchemaService; | ||
|
||
public class SpanAnnotationActionUndoSupport | ||
implements UndoableAnnotationActionSupport | ||
{ | ||
private final AnnotationSchemaService schemaService; | ||
|
||
public SpanAnnotationActionUndoSupport(AnnotationSchemaService aSchemaService) | ||
{ | ||
schemaService = aSchemaService; | ||
} | ||
|
||
@Override | ||
public boolean accepts(ApplicationEvent aContext) | ||
{ | ||
return aContext instanceof SpanEvent; | ||
} | ||
|
||
@Override | ||
public UndoableAnnotationAction actionForEvent(long aRequestId, ApplicationEvent aEvent) | ||
{ | ||
if (aEvent instanceof SpanCreatedEvent) { | ||
return new CreateSpanAnnotationAction(aRequestId, schemaService, | ||
(SpanCreatedEvent) aEvent); | ||
} | ||
|
||
if (aEvent instanceof SpanDeletedEvent) { | ||
return new DeleteSpanAnnotationAction(aRequestId, schemaService, | ||
(SpanDeletedEvent) aEvent); | ||
} | ||
|
||
if (aEvent instanceof SpanMovedEvent) { | ||
return new MoveSpanAnnotationAction(aRequestId, schemaService, (SpanMovedEvent) aEvent); | ||
} | ||
|
||
throw new IllegalArgumentException("Not an undoable action: [" + aEvent.getClass() + "]"); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...kp/clarin/webanno/ui/annotation/actionbar/undo/actions/UndoableActionSupportRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Licensed to the Technische Universität Darmstadt under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The Technische Universität Darmstadt | ||
* licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. | ||
* | ||
* 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. | ||
*/ | ||
package de.tudarmstadt.ukp.clarin.webanno.ui.annotation.actionbar.undo.actions; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.context.ApplicationEvent; | ||
|
||
import de.tudarmstadt.ukp.clarin.webanno.support.extensionpoint.ExtensionPoint; | ||
|
||
public interface UndoableActionSupportRegistry | ||
extends ExtensionPoint<ApplicationEvent, UndoableAnnotationActionSupport> | ||
{ | ||
default Optional<UndoableAnnotationActionSupport> getExtension(ApplicationEvent aEvent) | ||
{ | ||
return getExtensions(aEvent).stream().findFirst(); | ||
} | ||
} |
Oops, something went wrong.