Skip to content

Commit

Permalink
Merge pull request #1 from digicademy/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
pdbro2k authored May 14, 2020
2 parents 471b16d + 7adcc58 commit ff597bf
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 7 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.2.0] - 2020-05-14

### Added
- added class org.adwmainz.da.extensions.askmore.operations.DisplayMessageOperation
- added param removeSelection to class org.adwmainz.da.extensions.askmore.operations.InsertOrReplaceAnnotatedFragmentOperation to offer a way of switching off this default behavior of its super class

### Fixed
- fixed method org.adwmainz.da.extensions.askmore.utils.APIAccessUtils#containsNode() to enable the class org.adwmainz.da.extensions.askmore.operations.InsertAnnotatedFragmentToSelectionOperation to handle incomplete selections
- fixed description of the params dialogTitle and message


## [1.1.0] - 2020-04-08

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public CopyToClipboardOperation() {
// init argument descriptions
arguments = new ArgumentDescriptor[] {
AskMoreArgumentProvider.getCopyElementLocationArgumentDescriptor(),
AskMoreArgumentProvider.getResultsViewMessageArgumentDescriptor(rb.getString("COPIED_TO_CLIPBOARD")),
AskMoreArgumentProvider.getMessageArgumentDescriptor(rb.getString("COPIED_TO_CLIPBOARD")),
AskMoreArgumentProvider.getNotifyUserWithMessageArgumentDescriptor()
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* DisplayMessageOperation.java - is an implementation of a ro.sync.ecss.extensions.api.AuthorOperation which adds a custom operation to the Oxygen XML
* editor that displays a message in a simple dialog. It is one of the main classes within the AskMoreXtension developed at the Digital Academy of the
* Academy of Sciences and Literature | Mainz.
* @author Patrick D. Brookshire
* @version 1.2.0
*/
package org.adwmainz.da.extensions.askmore.operations;

import javax.swing.JOptionPane;

import org.adwmainz.da.extensions.askmore.utils.ArgumentParser;
import org.adwmainz.da.extensions.askmore.utils.AskMoreArgumentProvider;
import org.adwmainz.da.extensions.askmore.utils.InputDialogUtils;

import ro.sync.ecss.extensions.api.ArgumentDescriptor;
import ro.sync.ecss.extensions.api.ArgumentsMap;
import ro.sync.ecss.extensions.api.AuthorAccess;
import ro.sync.ecss.extensions.api.AuthorOperation;
import ro.sync.ecss.extensions.api.AuthorOperationException;

public class DisplayMessageOperation implements AuthorOperation {

// field
protected ArgumentDescriptor[] arguments;

// constructor
/**
* Creates a new DisplayMessageOperation
*/
public DisplayMessageOperation() {
// set argument descriptions
arguments = new ArgumentDescriptor[] {
AskMoreArgumentProvider.getDialogTitleArgumentDescriptor(""),
AskMoreArgumentProvider.getMessageArgumentDescriptor(""),
AskMoreArgumentProvider.getSeverityArgumentDescriptor()
};
}

// overridden methods
@Override
public String getDescription() {
return "Displays a custom message to the user.";
}

@Override
public void doOperation(AuthorAccess authorAccess, ArgumentsMap args)
throws IllegalArgumentException, AuthorOperationException {
// get params
String title = ArgumentParser.getValidString(args, AskMoreArgumentProvider.ARGUMENT_DIALOG_TITLE);
String message = ArgumentParser.getValidString(args, AskMoreArgumentProvider.ARGUMENT_MESSAGE);
int messageType = InputDialogUtils.getMessageType(ArgumentParser.getValidString(args, AskMoreArgumentProvider.ARGUMENT_SEVERITY));

// display the message dialog
JOptionPane.showMessageDialog(null, message, title, messageType);
}

@Override
public ArgumentDescriptor[] getArguments() {
return arguments;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import ro.sync.ecss.extensions.api.ArgumentsMap;
import ro.sync.ecss.extensions.api.AuthorAccess;
import ro.sync.ecss.extensions.api.AuthorOperationException;
import ro.sync.ecss.extensions.api.access.AuthorEditorAccess;
import ro.sync.ecss.extensions.commons.operations.InsertOrReplaceFragmentOperation;

public class InsertOrReplaceAnnotatedFragmentOperation extends InsertOrReplaceFragmentOperation {
Expand All @@ -37,7 +38,7 @@ public InsertOrReplaceAnnotatedFragmentOperation() {

// derive arguments from arguments of super class
ArgumentDescriptor[] basicArguments = super.getArguments();
arguments = new ArgumentDescriptor[basicArguments.length];
arguments = new ArgumentDescriptor[basicArguments.length + 1];
for (int i=0; i<basicArguments.length; ++i) {
// get basic argument
ArgumentDescriptor basicArgument = basicArguments[i];
Expand All @@ -50,6 +51,9 @@ public InsertOrReplaceAnnotatedFragmentOperation() {
// set argument
arguments[i] = derivedArgument;
}

// add custom argument
arguments[basicArguments.length] = AskMoreArgumentProvider.getRemoveSelectionArgumentDescriptor();
}

// overridden methods
Expand All @@ -61,6 +65,7 @@ public String getDescription() {
@Override
public void doOperation(AuthorAccess authorAccess, ArgumentsMap args) throws IllegalArgumentException, AuthorOperationException {
// get all params using the argument descriptors
boolean removeSelection = ArgumentParser.getValidBoolean(args, AskMoreArgumentProvider.ARGUMENT_REMOVE_SELECTION);
HashedArgumentsMap parsedArgs = new HashedArgumentsMap(args, ArgumentDescriptorUtils.getArgumentNames(arguments));

try {
Expand All @@ -69,6 +74,14 @@ public void doOperation(AuthorAccess authorAccess, ArgumentsMap args) throws Ill
parsedArgs.put(AskMoreArgumentProvider.ARGUMENT_FRAGMENT, parsedFragment);

// invoke main operation from super class
if (!removeSelection) {
// prevent super class from removing all selections per default
String insertLocation = ArgumentParser.getValidString(args, AskMoreArgumentProvider.ARGUMENT_INSERT_LOCATION, "");
if (!insertLocation.isEmpty()) {
AuthorEditorAccess editorAccess = authorAccess.getEditorAccess();
editorAccess.setCaretPosition(editorAccess.getSelectionStart() + 1);
}
}
super.doOperation(authorAccess, parsedArgs);
} catch (InputDialogClosedException e) {
// abort action if user closes the dialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ public static String getSelection(AuthorEditorAccess editorAccess, AuthorDocumen
* @return <code>true</code> if the ContentInterval contains the target node
*/
public static boolean containsNode(ContentInterval interval, AuthorNode targetNode) {
int intermediaryOffset = (targetNode.getStartOffset() + targetNode.getEndOffset())/2;
if (intermediaryOffset < interval.getStartOffset())
if (interval.getStartOffset() > targetNode.getEndOffset())
return false;
if (intermediaryOffset > interval.getEndOffset())
if (interval.getEndOffset() < targetNode.getStartOffset())
return false;
return true;
}
Expand All @@ -78,7 +77,7 @@ public static String[] getSeverityNames() {
* <br />The allowed values are: <code>Info</code>, <code>Warning</code>, <code>Error</code> and <code>Fatal</code>
* @throws IllegalArgumentException if <code>severityName</code> is not one of the mentioned values
*/
public static int getSeverity(String severityName) {
public static int getSeverity(String severityName) throws IllegalArgumentException {
switch (severityName) {
case "Info":
return DocumentPositionedInfo.SEVERITY_INFO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class AskMoreArgumentProvider {
public static final String ARGUMENT_MESSAGE = "message";
public static final String ARGUMENT_NO_RESULT_MESSAGE = "noResultMessage";
public static final String ARGUMENT_NOTIFY_USER = "notifyUser";
public static final String ARGUMENT_REMOVE_SELECTION = "removeSelection";
public static final String ARGUMENT_RESULTS_TAB_NAME = "resultsTabName";
public static final String ARGUMENT_SCHEMA_AWARE = "schemaAware";
public static final String ARGUMENT_SCRIPT = "script";
Expand Down Expand Up @@ -64,7 +65,16 @@ public static ArgumentDescriptor getDialogTitleArgumentDescriptor(String default
return new ArgumentDescriptor(
ARGUMENT_DIALOG_TITLE,
ArgumentDescriptor.TYPE_STRING,
"The title of the dialog used to select an action.",
"The title of the generated dialog.",
defaultValue
);
}

public static ArgumentDescriptor getMessageArgumentDescriptor(String defaultValue) {
return new ArgumentDescriptor(
ARGUMENT_MESSAGE,
ArgumentDescriptor.TYPE_STRING,
"The Message displayed in a new dialog.",
defaultValue
);
}
Expand Down Expand Up @@ -97,6 +107,18 @@ public static ArgumentDescriptor getResultsViewMessageArgumentDescriptor(String
);
}

public static ArgumentDescriptor getRemoveSelectionArgumentDescriptor() {
return new ArgumentDescriptor(
ARGUMENT_REMOVE_SELECTION,
ArgumentDescriptor.TYPE_CONSTANT_LIST,
"Specifies whether all selections in the author mode should be removed or not.",
new String[] {
AuthorConstants.ARG_VALUE_TRUE,
AuthorConstants.ARG_VALUE_FALSE},
AuthorConstants.ARG_VALUE_TRUE
);
}

public static ArgumentDescriptor getSelectElementLocationArgumentDescriptor() {
return new ArgumentDescriptor(
ARGUMENT_ELEMENT_LOCATION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.ResourceBundle;
import java.util.Set;

import javax.swing.JOptionPane;
import javax.swing.WindowConstants;

import org.adwmainz.da.extensions.askmore.exceptions.InputDialogClosedException;
Expand Down Expand Up @@ -123,4 +124,23 @@ public static String replaceAnnotationsWithUserInput(String annotatedText) throw
return AskMoreAnnotationParser.replaceAnnotations(annotatedText, askMoreAnnotations, userInput);
}

/**
* Returns the int representation of the specified severity
* @param severityName the name of a severity
* <br />The allowed values are: <code>Info</code>, <code>Warning</code>, <code>Error</code> and <code>Fatal</code>
* @throws IllegalArgumentException if <code>severityName</code> is not one of the mentioned values
*/
public static int getMessageType(String severityName) throws IllegalArgumentException {
switch (severityName) {
case "Info":
return JOptionPane.INFORMATION_MESSAGE;
case "Warning":
return JOptionPane.WARNING_MESSAGE;
case "Error":
case "Fatal":
return JOptionPane.ERROR_MESSAGE;
default:
throw new IllegalArgumentException("Unknown severity "+severityName);
}
}
}

0 comments on commit ff597bf

Please sign in to comment.