Skip to content

Commit

Permalink
Initial support for a specific lang tag
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhorridge committed Jun 12, 2024
1 parent 540ce79 commit b34bb22
Show file tree
Hide file tree
Showing 17 changed files with 271 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ private static FormFieldDescriptor getDefaultFormFieldDescriptor(UuidV4Provider
FormFieldDeprecationStrategy.DELETE_VALUES,
new TextControlDescriptor(LanguageMap.empty(),
StringType.SIMPLE_STRING,
"",
LineMode.SINGLE_LINE,
"",
LanguageMap.empty()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Label;
import edu.stanford.bmir.protege.web.client.primitive.*;
import edu.stanford.bmir.protege.web.shared.PrimitiveType;
import edu.stanford.bmir.protege.web.shared.*;
import edu.stanford.bmir.protege.web.shared.entity.OWLLiteralData;
import edu.stanford.bmir.protege.web.shared.entity.OWLPrimitiveData;
import edu.stanford.bmir.protege.web.shared.form.ValidationStatus;
Expand Down Expand Up @@ -164,7 +164,7 @@ private void displayErrorBorder() {
}

private void setStringType(StringType stringType) {
if(stringType == StringType.SIMPLE_STRING) {
if(stringType == StringType.SIMPLE_STRING || stringType == StringType.SPECIFIC_LANG_STRING) {
languageEditor.setVisible(false);
}
else {
Expand Down Expand Up @@ -231,7 +231,8 @@ public Optional<FormControlData> getValue() {
return Optional.empty();
}
OWLLiteralData literalData = (OWLLiteralData) editedValue.get();
if(literalData.getLiteral().getLiteral().trim().isEmpty()) {
String lexicalValue = literalData.getLiteral().getLiteral().trim();
if(lexicalValue.isEmpty()) {
return Optional.empty();
}
if(stringType == StringType.SIMPLE_STRING) {
Expand All @@ -243,6 +244,11 @@ public Optional<FormControlData> getValue() {
return Optional.of(TextControlData.get(descriptor, literalData.getLiteral()));
}
}
else if(stringType == StringType.SPECIFIC_LANG_STRING) {
String specificLangTag = descriptor.getSpecificLangTag().trim();
OWLLiteral literalWithSepcificLang = DataFactory.getOWLLiteral(lexicalValue, specificLangTag);
return Optional.of(TextControlData.get(descriptor, literalWithSepcificLang));
}
else {
return Optional.of(TextControlData.get(descriptor, literalData.getLiteral()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import edu.stanford.bmir.protege.web.shared.form.field.LineMode;
import edu.stanford.bmir.protege.web.shared.form.field.StringType;
import edu.stanford.bmir.protege.web.shared.form.field.TextControlDescriptor;
import edu.stanford.bmir.protege.web.shared.lang.LanguageMap;
import edu.stanford.bmir.protege.web.shared.lang.*;

import javax.annotation.Nonnull;
import javax.inject.Inject;
Expand All @@ -32,6 +32,7 @@ public TextControlDescriptorPresenter(@Nonnull TextControlDescriptorView view) {
public FormControlDescriptor getFormFieldDescriptor() {
return new TextControlDescriptor(view.getPlaceholder(),
view.getStringType(),
view.getSpecificLangTag().map(LangTag::format).orElse(""),
view.getLineMode(),
view.getPattern(),
view.getPatternViolationMessage());
Expand All @@ -46,6 +47,7 @@ public void setFormFieldDescriptor(@Nonnull FormControlDescriptor formControlDes
TextControlDescriptor descriptor = (TextControlDescriptor) formControlDescriptor;
view.setStringType(descriptor.getStringType());
view.setLineMode(descriptor.getLineMode());
view.setSpecificLangTag(LangTag.get(descriptor.getSpecificLangTag()));
view.setPatternViolationMessage(descriptor.getPlaceholder());
view.setPattern(descriptor.getPattern());
view.setPatternViolationMessage(descriptor.getPatternViolationErrorMessage());
Expand All @@ -55,6 +57,7 @@ public void setFormFieldDescriptor(@Nonnull FormControlDescriptor formControlDes
public void clear() {
view.setLineMode(LineMode.SINGLE_LINE);
view.setStringType(StringType.SIMPLE_STRING);
view.setSpecificLangTag(LangTag.get(""));
view.setPattern("");
view.setPatternViolationMessage(LanguageMap.empty());
view.setPlaceholder(LanguageMap.empty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static TextControlDescriptor createDefault() {
return new TextControlDescriptor(
LanguageMap.empty(),
StringType.SIMPLE_STRING,
"",
LineMode.SINGLE_LINE,
"",
LanguageMap.empty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import com.google.gwt.user.client.ui.IsWidget;
import edu.stanford.bmir.protege.web.shared.form.field.LineMode;
import edu.stanford.bmir.protege.web.shared.form.field.StringType;
import edu.stanford.bmir.protege.web.shared.lang.LanguageMap;
import edu.stanford.bmir.protege.web.shared.lang.*;

import javax.annotation.Nonnull;
import java.util.Optional;

/**
* Matthew Horridge
Expand Down Expand Up @@ -39,4 +40,8 @@ public interface TextControlDescriptorView extends IsWidget {
@Nonnull
LanguageMap getPlaceholder();

@Nonnull
Optional<LangTag> getSpecificLangTag();

void setSpecificLangTag(LangTag langTag);
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package edu.stanford.bmir.protege.web.client.form;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.TextBox;
import edu.stanford.bmir.protege.web.client.primitive.LanguageEditor;
import edu.stanford.bmir.protege.web.client.ui.Counter;
import edu.stanford.bmir.protege.web.shared.form.field.LineMode;
import edu.stanford.bmir.protege.web.shared.form.field.StringType;
import edu.stanford.bmir.protege.web.shared.lang.LanguageMap;
import edu.stanford.bmir.protege.web.shared.lang.*;

import javax.annotation.Nonnull;
import javax.inject.Inject;

import java.util.Optional;

import static com.google.common.base.Preconditions.checkNotNull;

/**
Expand Down Expand Up @@ -52,26 +56,52 @@ interface TextControlDescriptorViewImplUiBinder extends UiBinder<HTMLPanel, Text
@UiField
RadioButton langString;

@UiField
RadioButton specificLangString;

@UiField(provided = true)
LanguageEditor specificLangTagEditor;

@UiField(provided = true)
protected static Counter counter = new Counter();

@UiField
HTMLPanel specificLangTagPanel;

@Inject
public TextControlDescriptorViewImpl(@Nonnull LanguageMapEditor placeholderEditor,
@Nonnull LanguageMapEditor patternViolationMessageEditor) {
@Nonnull LanguageMapEditor patternViolationMessageEditor,
@Nonnull LanguageEditor specificLangTagEditor) {
this.placeholderEditor = checkNotNull(placeholderEditor);
this.specificLangTagEditor = checkNotNull(specificLangTagEditor);
this.patternViolationMessageEditor = checkNotNull(patternViolationMessageEditor);
counter.increment();
initWidget(ourUiBinder.createAndBindUi(this));
specificLangString.addValueChangeHandler(this::handleSpecificLangStringChanged);
simpleString.addValueChangeHandler(this::handleSpecificLangStringChanged);
langString.addValueChangeHandler(this::handleSpecificLangStringChanged);
}

private void handleSpecificLangStringChanged(ValueChangeEvent<Boolean> event) {
updateVisibility();
}

private void updateVisibility() {
specificLangTagPanel.setVisible(specificLangString.getValue());
}

@Override
public void setStringType(@Nonnull StringType stringType) {
if(stringType == StringType.SIMPLE_STRING) {
simpleString.setValue(true);
}
else {
else if(stringType == StringType.LANG_STRING) {
langString.setValue(true);
}
else {
specificLangString.setValue(true);
}
updateVisibility();
}

@Nonnull
Expand All @@ -80,9 +110,12 @@ public StringType getStringType() {
if(simpleString.getValue()) {
return StringType.SIMPLE_STRING;
}
else {
else if(langString.getValue()) {
return StringType.LANG_STRING;
}
else {
return StringType.SPECIFIC_LANG_STRING;
}
}

@Override
Expand Down Expand Up @@ -138,4 +171,15 @@ public void setPlaceholder(@Nonnull LanguageMap languageMap) {
public LanguageMap getPlaceholder() {
return placeholderEditor.getValue().orElse(LanguageMap.empty());
}

@Nonnull
@Override
public Optional<LangTag> getSpecificLangTag() {
return specificLangTagEditor.getValue().map(LangTag::get);
}

@Override
public void setSpecificLangTag(LangTag langTag) {
specificLangTagEditor.setValue(langTag.format());
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
xmlns:form="urn:import:edu.stanford.bmir.protege.web.client.form">
xmlns:form="urn:import:edu.stanford.bmir.protege.web.client.form"
xmlns:primitive="urn:import:edu.stanford.bmir.protege.web.client.primitive">
<ui:with field="wp" type="edu.stanford.bmir.protege.web.resources.WebProtegeClientBundle"/>
<ui:with field="msg" type="edu.stanford.bmir.protege.web.client.FormsMessages"/>
<ui:with field="counter" type="edu.stanford.bmir.protege.web.client.ui.Counter"/>
<ui:style>
.specificLangTag {
margin-top: 1em;
margin-left: 2em;
}
.specificLangTag__help {
max-width: 150px;
}
</ui:style>
<g:HTMLPanel>

<g:HTMLPanel addStyleNames="{wp.style.formGroupRow}">
<g:HTMLPanel addStyleNames="{wp.style.formGroup}">
<g:Label addStyleNames="{wp.style.formLabel}" text="String type"/>
<g:RadioButton name="type-{counter.getValue}" text="Simple string" ui:field="simpleString"/>
<g:RadioButton name="type-{counter.getValue}" text="String with language tag" ui:field="langString"/>
<g:RadioButton name="type-{counter.getValue}" text="String with specific language tag" ui:field="specificLangString"/>
<g:HTMLPanel ui:field="specificLangTagPanel" addStyleNames="{style.specificLangTag} {wp.style.formGroupNarrow}">
<g:Label addStyleNames="{wp.style.formLabel}" text="Specific language tag"/>
<primitive:LanguageEditor ui:field="specificLangTagEditor" placeholder="Enter language tag"/>
</g:HTMLPanel>
</g:HTMLPanel>

<g:HTMLPanel addStyleNames="{wp.style.formGroup}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import edu.stanford.bmir.protege.web.client.dispatch.ProgressDisplay;
import edu.stanford.bmir.protege.web.client.library.msgbox.MessageBox;
import edu.stanford.bmir.protege.web.client.projectmanager.ProjectCreatedEvent;
import edu.stanford.bmir.protege.web.client.upload.FileUploadFileReader;
import edu.stanford.bmir.protege.web.client.upload.FileUploader;
import edu.stanford.bmir.protege.web.client.user.LoggedInUserManager;
import edu.stanford.bmir.protege.web.client.uuid.UuidV4;
import edu.stanford.bmir.protege.web.shared.csv.DocumentId;
import edu.stanford.bmir.protege.web.shared.dispatch.actions.GetUserInfoAction;
import edu.stanford.bmir.protege.web.shared.dispatch.actions.GetUserInfoResult;
import edu.stanford.bmir.protege.web.shared.permissions.PermissionDeniedException;
import edu.stanford.bmir.protege.web.shared.project.*;
import edu.stanford.bmir.protege.web.shared.upload.SubmitFileAction;
Expand Down Expand Up @@ -118,32 +120,35 @@ private void createEmptyProject(ProjectCreatedHandler projectCreatedHandler) {

private void uploadSourcesAndCreateProject(@Nonnull ProjectCreatedHandler projectCreatedHandler) {
checkNotNull(projectCreatedHandler);
String fileUploadElementId = view.getFileUploadElementId();
FileUploadFileReader fileUploadFileReader = new FileUploadFileReader();
progressDisplay.displayProgress("Uploading file", "Uploading file. Please wait.");
fileUploadFileReader.readFiles(fileUploadElementId, fileContent -> {
progressDisplay.hideProgress();
handleFileReadComplete(fileContent, projectCreatedHandler);
}, readError -> {
progressDisplay.hideProgress();
messageBox.showAlert("Upload Failed", "Your file could not be uploaded.");
});
dispatchServiceManager.execute(new GetUserInfoAction(),
info -> createProjectForUser(info, projectCreatedHandler));
}

private void handleFileReadComplete(@Nonnull String base64EncodedContent,
ProjectCreatedHandler projectCreatedHandler) {
private void createProjectForUser(GetUserInfoResult userInfo,
ProjectCreatedHandler projectCreatedHandler) {

dispatchServiceManager.execute(SubmitFileAction.create(base64EncodedContent),
busy -> {},
result -> {
handleCreateNewProjectFromUploadedSources(projectCreatedHandler, result);
});
String fileUploadElementId = view.getFileUploadElementId();
FileUploader fileUploader = new FileUploader();
fileUploader.uploadFile(fileUploadElementId,
userInfo.getToken(),
fileSubmissionId -> handleFileSubmissionSuccess(projectCreatedHandler, fileSubmissionId),
this::handleFileSubmissionError);
}

private void handleFileSubmissionError(int errorCode) {
messageBox.showMessage("Could not upload file", "Error code: " + errorCode);
progressDisplay.hideProgress();
}

private void handleFileSubmissionSuccess(CreateNewProjectPresenter.ProjectCreatedHandler projectCreatedHandler,
String fileSubmissionId) {
progressDisplay.hideProgress();
handleCreateNewProjectFromUploadedSources(projectCreatedHandler,
new DocumentId(fileSubmissionId));
}

private void handleCreateNewProjectFromUploadedSources(ProjectCreatedHandler projectCreatedHandler, SubmitFileResult result) {
DocumentId documentId = result.getFileSubmissionId();
private void handleCreateNewProjectFromUploadedSources(ProjectCreatedHandler projectCreatedHandler, DocumentId documentId) {
NewProjectSettings newProjectSettings = NewProjectSettings.get(loggedInUserManager.getLoggedInUserId(),
view.getProjectName(),
view.getProjectLanguage(),
Expand Down Expand Up @@ -199,8 +204,4 @@ else if (cause instanceof ProjectDocumentExistsException) {
}
});
}

public NewProjectInfo getNewProjectInfo() {
return new NewProjectInfo(view.getProjectName(), view.getProjectDescription());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package edu.stanford.bmir.protege.web.client.upload;

/**
* Matthew Horridge
* Stanford Center for Biomedical Informatics Research
* 2024-06-10
*/
public interface FileUploadErrorHandler {

void handleFileUploadError(int statusCode);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package edu.stanford.bmir.protege.web.client.upload;

/**
* Matthew Horridge
* Stanford Center for Biomedical Informatics Research
* 2024-06-10
*/
public interface FileUploadSuccessHandler {

void handleFileUploadSuccess(String fileSubmissionId);
}
Loading

0 comments on commit b34bb22

Please sign in to comment.