diff --git a/kview/src/main/java/dev/ikm/komet/kview/mvvm/model/DescriptionFormType.java b/kview/src/main/java/dev/ikm/komet/kview/mvvm/model/DescriptionFormType.java new file mode 100644 index 000000000..66c8d90cc --- /dev/null +++ b/kview/src/main/java/dev/ikm/komet/kview/mvvm/model/DescriptionFormType.java @@ -0,0 +1,24 @@ +package dev.ikm.komet.kview.mvvm.model; + +public enum DescriptionFormType { + ADD_FQN("Add Description: Fully Qualified Name", "Fully Qualified Name", true), + ADD_OTHER_NAME("Add New Description: Other Name", "Other Name", true), + EDIT_FQN("Edit Description: Fully Qualified Name", "Fully Qualified Name", false), + EDIT_OTHER_NAME("Edit Description: Other Name", "Other Name", false); + + private final String title; + private final String typePrompt; + private final boolean isAddMode; + + DescriptionFormType(String title, String typePrompt, boolean isAddMode) { + this.title = title; + this.typePrompt = typePrompt; + this.isAddMode = isAddMode; + } + + public String getTitle() { return title; } + public String getTypePrompt() { return typePrompt; } + public boolean isAddMode() { return isAddMode; } + public boolean isEditMode() { return !isAddMode; } + public boolean isFqnType() { return this == ADD_FQN || this == EDIT_FQN; } +} diff --git a/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/AddFullyQualifiedNameController.java b/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/AddFullyQualifiedNameController.java deleted file mode 100644 index a2b35f6e0..000000000 --- a/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/AddFullyQualifiedNameController.java +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Copyright © 2015 Integrated Knowledge Management (support@ikm.dev) - * - * 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. - */ -package dev.ikm.komet.kview.mvvm.view.properties; - -import dev.ikm.komet.kview.mvvm.view.AbstractBasicController; -import dev.ikm.komet.kview.events.ClosePropertiesPanelEvent; -import dev.ikm.komet.kview.events.CreateConceptEvent; -import dev.ikm.komet.kview.mvvm.model.DescrName; -import dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel; -import dev.ikm.tinkar.events.EvtBus; -import dev.ikm.tinkar.events.EvtBusFactory; -import dev.ikm.komet.framework.view.ViewProperties; -import dev.ikm.tinkar.common.id.PublicId; -import dev.ikm.tinkar.entity.ConceptEntity; -import dev.ikm.tinkar.entity.Entity; -import dev.ikm.tinkar.terms.EntityFacade; -import dev.ikm.tinkar.terms.State; -import dev.ikm.tinkar.terms.TinkarTerm; -import javafx.beans.InvalidationListener; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.scene.control.*; -import javafx.util.Callback; -import javafx.util.StringConverter; -import org.carlfx.cognitive.loader.InjectViewModel; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Collection; -import java.util.Optional; -import java.util.UUID; - -import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.*; - -public class AddFullyQualifiedNameController extends AbstractBasicController { - - private static final Logger LOG = LoggerFactory.getLogger(AddFullyQualifiedNameController.class); - - private UUID conceptTopic; - - @FXML - private Label addFqnTitleLabel; - - @FXML - private ComboBox moduleComboBox; - - @FXML - private TextField fullyQualifiedNameTextField; - - @FXML - private ComboBox statusComboBox; - - @FXML - private ComboBox caseSignificanceComboBox; - - @FXML - private ComboBox languageComboBox; - - @FXML - private Button submitButton; - - private EvtBus eventBus; - - private ViewProperties viewProperties; - - private PublicId publicId; - - @InjectViewModel - private DescrNameViewModel fqnViewModel; - - public AddFullyQualifiedNameController(UUID conceptTopic) { - this.conceptTopic = conceptTopic; - } - - @FXML - public void initialize() { - eventBus = EvtBusFactory.getDefaultEvtBus(); - clearView(); - submitButton.setDisable(true); - - - // Initialize the fqnViewModel - fqnViewModel - .setPropertyValue(NAME_TYPE, TinkarTerm.FULLY_QUALIFIED_NAME_DESCRIPTION_TYPE) - .setPropertyValue(STATUS, TinkarTerm.ACTIVE_STATE); - - // register listeners - InvalidationListener formValid = (obs) -> { - boolean isFormValid = isFormPopulated(); - if (isFormValid) { - copyUIToViewModelProperties(); - } - submitButton.setDisable(!isFormValid); - }; - - fullyQualifiedNameTextField.textProperty().addListener(formValid); - setupComboBox(moduleComboBox, formValid); - setupComboBox(statusComboBox, formValid); - setupComboBox(caseSignificanceComboBox, formValid); - setupComboBox(languageComboBox, formValid); - } - - /** - * TODO: This is appropriate. A better solution is binding properties on the view model. If so, we'd need to unbind. - * This copies form values into the ViewModel's property values. It does not save or validate. - */ - private void copyUIToViewModelProperties() { - if (fqnViewModel != null) { - fqnViewModel.setPropertyValue(NAME_TEXT, fullyQualifiedNameTextField.getText()) - .setPropertyValue(NAME_TYPE, TinkarTerm.FULLY_QUALIFIED_NAME_DESCRIPTION_TYPE) - .setPropertyValue(CASE_SIGNIFICANCE, caseSignificanceComboBox.getSelectionModel().getSelectedItem()) - .setPropertyValue(STATUS, statusComboBox.getSelectionModel().getSelectedItem()) - .setPropertyValue(MODULE, moduleComboBox.getSelectionModel().getSelectedItem()) - .setPropertyValue(LANGUAGE, languageComboBox.getSelectionModel().getSelectedItem()); - } - } - - public void populate(ComboBox comboBox, Collection entities) { - comboBox.getItems().setAll(entities); - } - - @Override - public void updateView() { - - // populate form combo fields module, status, case significance, lang. - populate(moduleComboBox, fqnViewModel.findAllModules(getViewProperties())); - populate(statusComboBox, fqnViewModel.findAllStatuses(getViewProperties())); - populate(caseSignificanceComboBox, fqnViewModel.findAllCaseSignificants(getViewProperties())); - populate(languageComboBox, fqnViewModel.findAllLanguages(getViewProperties())); - - // Set UI to default values - caseSignificanceComboBox.setValue(TinkarTerm.DESCRIPTION_NOT_CASE_SENSITIVE); - statusComboBox.setValue(Entity.getFast(State.ACTIVE.nid())); - moduleComboBox.setValue(TinkarTerm.DEVELOPMENT_MODULE); - languageComboBox.setValue(TinkarTerm.ENGLISH_LANGUAGE); - } - - @Override - public void clearView() { - fullyQualifiedNameTextField.setText(""); - moduleComboBox.setValue(null); - statusComboBox.setValue(null); - caseSignificanceComboBox.setValue(null); - languageComboBox.setValue(null); -// if (fqnViewModel != null) { -// copyUIToViewModelProperties(); -// fqnViewModel.save(true); // make UI properties as model values -// } - moduleComboBox.getItems().clear(); - statusComboBox.getItems().clear(); - caseSignificanceComboBox.getItems().clear(); - languageComboBox.getItems().clear(); - } - - @Override - public void cleanup() { - - } - - private boolean isFormPopulated() { - return (fullyQualifiedNameTextField.getText() != null && !fullyQualifiedNameTextField.getText().toString().isEmpty()) - && (moduleComboBox.getSelectionModel().getSelectedItem() != null) - && (statusComboBox.getSelectionModel().getSelectedItem() != null) - && (caseSignificanceComboBox.getSelectionModel().getSelectedItem() != null) - && (languageComboBox.getSelectionModel().getSelectedItem() != null); - } - - private String getDisplayText(ConceptEntity conceptEntity) { - Optional stringOptional = getViewProperties().calculator().getRegularDescriptionText(conceptEntity.nid()); - return stringOptional.orElse(""); - } - - private void setupComboBox(ComboBox comboBox, InvalidationListener listener) { - comboBox.setConverter(new StringConverter() { - - @Override - public String toString(ConceptEntity conceptEntity) { - return getDisplayText(conceptEntity); - } - - @Override - public ConceptEntity fromString(String string) { - return null; - } - }); - - comboBox.setCellFactory(new Callback<>() { - - /** - * @param param The single argument upon which the returned value should be - * determined. - * @return - */ - @Override - public ListCell call(Object param) { - return new ListCell<>(){ - @Override - protected void updateItem(ConceptEntity conceptEntity, boolean b) { - super.updateItem(conceptEntity, b); - if (conceptEntity != null) { - setText(getDisplayText(conceptEntity)); - } else { - setText(null); - } - - } - }; - } - }); - - // register invalidation listener - comboBox.getSelectionModel().selectedItemProperty().addListener(listener); - } - - @FXML - private void saveFullQualifiedName(ActionEvent actionEvent) { - actionEvent.consume(); - - // TODO assuming it's valid save() check for errors and publish event - - fqnViewModel.save(); - if (fqnViewModel.getValidationMessages().size() == 0) { - // publish event with the fqnViewModel. - // ... This property may not be needed. - fqnViewModel.setPropertyValue(IS_SUBMITTED, true); - } - - LOG.info("Ready to add to the concept view model: " + fqnViewModel); - - ////////////////////////////////////////////////////////////////////////////////////////// - // event received in Details Controller that will call conceptViewModel.createConcept() - ////////////////////////////////////////////////////////////////////////////////////////// - DescrName fqnDescrName = fqnViewModel.create(); - eventBus.publish(conceptTopic, new CreateConceptEvent(this, CreateConceptEvent.ADD_FQN, fqnDescrName)); - - // clear the form after saving. otherwise when you navigate back to Add Other Name - // you would have the previous form values still there - clearView(); - close(); - } - - @FXML - public void cancel() { - close(); - } - - private void close() { - // close the properties bump out - eventBus.publish(conceptTopic, new ClosePropertiesPanelEvent(submitButton, - ClosePropertiesPanelEvent.CLOSE_PROPERTIES)); - } - - @Override - public DescrNameViewModel getViewModel() { - return fqnViewModel; - } -} diff --git a/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/AddOtherNameController.java b/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/AddOtherNameController.java deleted file mode 100644 index ef7008e35..000000000 --- a/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/AddOtherNameController.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright © 2015 Integrated Knowledge Management (support@ikm.dev) - * - * 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. - */ -package dev.ikm.komet.kview.mvvm.view.properties; - -import dev.ikm.komet.kview.mvvm.view.AbstractBasicController; -import dev.ikm.komet.kview.events.ClosePropertiesPanelEvent; -import dev.ikm.komet.kview.events.CreateConceptEvent; -import dev.ikm.komet.kview.mvvm.viewmodel.OtherNameViewModel; -import dev.ikm.tinkar.entity.Entity; -import dev.ikm.tinkar.events.EvtBus; -import dev.ikm.tinkar.events.EvtBusFactory; -import dev.ikm.komet.framework.view.ViewProperties; -import dev.ikm.tinkar.entity.ConceptEntity; -import dev.ikm.tinkar.terms.EntityFacade; -import dev.ikm.tinkar.terms.State; -import dev.ikm.tinkar.terms.TinkarTerm; -import javafx.beans.InvalidationListener; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.scene.control.*; -import javafx.util.Callback; -import javafx.util.StringConverter; -import org.carlfx.cognitive.loader.InjectViewModel; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Collection; -import java.util.Optional; -import java.util.UUID; - -import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.*; -import static dev.ikm.komet.kview.mvvm.viewmodel.OtherNameViewModel.OtherNameProperties.FQN_CASE_SIGNIFICANCE; -import static dev.ikm.komet.kview.mvvm.viewmodel.OtherNameViewModel.OtherNameProperties.FQN_LANGUAGE; -import static dev.ikm.komet.kview.mvvm.viewmodel.OtherNameViewModel.OtherNameProperties.HAS_OTHER_NAME; - -public class AddOtherNameController extends AbstractBasicController { - - private static final Logger LOG = LoggerFactory.getLogger(AddOtherNameController.class); - - private UUID conceptTopic; - - @FXML - private Label addOtherNameTitleLabel; - - @FXML - private ComboBox moduleComboBox; - - @FXML - private TextField otherNameTextField; - - @FXML - private ComboBox statusComboBox; - - @FXML - private ComboBox caseSignificanceComboBox; - - @FXML - private ComboBox languageComboBox; - - @FXML - private Button submitButton; - - private EvtBus eventBus; - - private ViewProperties viewProperties; - - private EntityFacade entityFacade; - - @InjectViewModel - private OtherNameViewModel otherNameViewModel; - - - public AddOtherNameController() { } - - public AddOtherNameController(UUID conceptTopic) { - this.conceptTopic = conceptTopic; - } - - @FXML - public void initialize() { - eventBus = EvtBusFactory.getDefaultEvtBus(); - clearView(); - submitButton.setDisable(true); - setAddOtherNameTitleLabel("Add New Description: Other Name"); - // Initialize view models - otherNameViewModel - .setPropertyValue(NAME_TYPE, TinkarTerm.REGULAR_NAME_DESCRIPTION_TYPE) - .setPropertyValue(STATUS, TinkarTerm.ACTIVE_STATE); - // register listeners - InvalidationListener formValid = (obs) -> { - boolean isFormValid = isFormPopulated(); - if (isFormValid) { - copyUIToViewModelProperties(); - } - submitButton.setDisable(!isFormValid); - }; - - otherNameTextField.textProperty().addListener(formValid); - setupComboBox(moduleComboBox, formValid); - setupComboBox(statusComboBox, formValid); - setupComboBox(caseSignificanceComboBox, formValid); - setupComboBox(languageComboBox, formValid); - } - - /** - * TODO: This is appropriate. A better solution is binding properties on the view model. If so, we'd need to unbind. - * This copies form values into the ViewModel's property values. It does not save or validate. - */ - private void copyUIToViewModelProperties() { - if (otherNameViewModel != null) { - otherNameViewModel.setPropertyValue(NAME_TEXT, otherNameTextField.getText()) - .setPropertyValue(NAME_TYPE, TinkarTerm.REGULAR_NAME_DESCRIPTION_TYPE) - .setPropertyValue(CASE_SIGNIFICANCE, caseSignificanceComboBox.getSelectionModel().getSelectedItem()) - .setPropertyValue(STATUS, statusComboBox.getSelectionModel().getSelectedItem()) - .setPropertyValue(MODULE, moduleComboBox.getSelectionModel().getSelectedItem()) - .setPropertyValue(LANGUAGE, languageComboBox.getSelectionModel().getSelectedItem()); - } - } - - public void updateModel(final ViewProperties viewProperties) { - this.viewProperties = viewProperties; - } - - public void populate(ComboBox comboBox, Collection entities) { - comboBox.getItems().addAll(entities); - } - - - @Override - public OtherNameViewModel getViewModel() { - return otherNameViewModel; - } - - - private String getDisplayText(ConceptEntity conceptEntity) { - Optional stringOptional = getViewProperties().calculator().languageCalculator().getRegularDescriptionText(conceptEntity.nid()); - return stringOptional.orElse(""); - } - - private void setupComboBox(ComboBox comboBox, InvalidationListener listener) { - comboBox.setConverter(new StringConverter() { - - @Override - public String toString(ConceptEntity conceptEntity) { - return getDisplayText(conceptEntity); - } - - @Override - public ConceptEntity fromString(String string) { - return null; - } - }); - - comboBox.setCellFactory(new Callback<>() { - - /** - * @param param The single argument upon which the returned value should be - * determined. - * @return - */ - @Override - public ListCell call(Object param) { - return new ListCell<>(){ - @Override - protected void updateItem(ConceptEntity conceptEntity, boolean b) { - super.updateItem(conceptEntity, b); - if (conceptEntity != null) { - setText(getDisplayText(conceptEntity)); - } else { - setText(null); - } - - } - }; - } - }); - - // register invalidation listener - comboBox.getSelectionModel().selectedItemProperty().addListener(listener); - } - - private boolean isFormPopulated() { - return (otherNameTextField.getText() != null && !otherNameTextField.getText().toString().isEmpty()) - && (moduleComboBox.getSelectionModel().getSelectedItem() != null) - && (statusComboBox.getSelectionModel().getSelectedItem() != null) - && (caseSignificanceComboBox.getSelectionModel().getSelectedItem() != null) - && (languageComboBox.getSelectionModel().getSelectedItem() != null); - } - - public void setAddOtherNameTitleLabel(String addDescriptionTitleLabelText) { - this.addOtherNameTitleLabel.setText(addDescriptionTitleLabelText); - } - - @FXML - private void saveOtherName(ActionEvent actionEvent) { - actionEvent.consume(); - - // TODO assuming it's valid save() check for errors and publish event - otherNameViewModel.setPropertyValue(IS_SUBMITTED, true); - otherNameViewModel.save(); - if (otherNameViewModel.hasNoErrorMsgs()) { - // publish event with the otherNameViewModel. - // ... - LOG.info("Ready to add to the concept view model: " + otherNameViewModel); - eventBus.publish(conceptTopic, new CreateConceptEvent(this, CreateConceptEvent.ADD_OTHER_NAME, - otherNameViewModel.create())); - clearView(); - close(); - } - - } - - - @Override - public void updateView() { - // populate form combo fields module, status, case significance, lang. - populate(moduleComboBox, otherNameViewModel.findAllModules(getViewProperties())); - populate(statusComboBox, otherNameViewModel.findAllStatuses(getViewProperties())); - populate(caseSignificanceComboBox, otherNameViewModel.findAllCaseSignificants(getViewProperties())); - populate(languageComboBox, otherNameViewModel.findAllLanguages(getViewProperties())); - - boolean hasOtherName = getViewModel().getValue(HAS_OTHER_NAME); - - if (hasOtherName) { - caseSignificanceComboBox.setValue(getViewModel().getValue(FQN_CASE_SIGNIFICANCE)); - } else { - caseSignificanceComboBox.setValue(TinkarTerm.DESCRIPTION_NOT_CASE_SENSITIVE); - } - statusComboBox.setValue(Entity.getFast(State.ACTIVE.nid())); - moduleComboBox.setValue(TinkarTerm.DEVELOPMENT_MODULE); - if (hasOtherName) { - languageComboBox.setValue(getViewModel().getValue(FQN_LANGUAGE)); - } else { - languageComboBox.setValue(TinkarTerm.ENGLISH_LANGUAGE); - } - } - - - @Override - public void clearView() { - otherNameTextField.setText(""); - moduleComboBox.setValue(null); - statusComboBox.setValue(null); - caseSignificanceComboBox.setValue(null); - languageComboBox.setValue(null); - moduleComboBox.getItems().clear(); - statusComboBox.getItems().clear(); - caseSignificanceComboBox.getItems().clear(); - languageComboBox.getItems().clear(); - } - - @FXML - public void cancel() { - close(); - } - - private void close() { - // close the properties bump out - eventBus.publish(conceptTopic, new ClosePropertiesPanelEvent(submitButton, - ClosePropertiesPanelEvent.CLOSE_PROPERTIES)); - } - - @Override - public void cleanup() { - } -} diff --git a/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/DescriptionAddFqnController.java b/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/DescriptionAddFqnController.java new file mode 100644 index 000000000..2f8c3ba64 --- /dev/null +++ b/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/DescriptionAddFqnController.java @@ -0,0 +1,160 @@ +package dev.ikm.komet.kview.mvvm.view.properties; + +import dev.ikm.komet.kview.events.ClosePropertiesPanelEvent; +import dev.ikm.komet.kview.events.CreateConceptEvent; +import dev.ikm.komet.kview.mvvm.model.DescrName; +import dev.ikm.komet.kview.mvvm.model.DescriptionFormType; +import dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel; +import dev.ikm.tinkar.entity.ConceptEntity; +import dev.ikm.tinkar.entity.Entity; +import dev.ikm.tinkar.terms.EntityFacade; +import dev.ikm.tinkar.terms.State; +import dev.ikm.tinkar.terms.TinkarTerm; +import javafx.beans.InvalidationListener; +import javafx.scene.control.ComboBox; +import javafx.scene.control.ListCell; +import javafx.util.Callback; +import javafx.util.StringConverter; +import org.carlfx.cognitive.loader.InjectViewModel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Collection; +import java.util.Optional; +import java.util.UUID; + +import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.*; +import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.CASE_SIGNIFICANCE; +import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.LANGUAGE; +import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.MODULE; + +public class DescriptionAddFqnController extends DescriptionBaseController{ + private static final Logger LOG = LoggerFactory.getLogger(DescriptionAddFqnController.class); + @InjectViewModel + private DescrNameViewModel fqnViewModel; + + public DescriptionAddFqnController(UUID conceptTopic) { + super(DescriptionFormType.ADD_FQN, conceptTopic); + } + + @Override + protected void initializeData() { + configureDialectVisibility(false); + + submitButton.setDisable(true); + + // Initialize the fqnViewModel + fqnViewModel + .setPropertyValue(NAME_TYPE, TinkarTerm.FULLY_QUALIFIED_NAME_DESCRIPTION_TYPE) + .setPropertyValue(STATUS, TinkarTerm.ACTIVE_STATE); + + // register listeners + InvalidationListener formValid = (obs) -> { + boolean isFormValid = isFormPopulated(); + if (isFormValid) { + copyUIToViewModelProperties(); + } + submitButton.setDisable(!isFormValid); + }; + + // Initialize combo boxes with appropriate data for FQN add mode + nameTextField.textProperty().addListener(formValid); + setupComboBoxAdd(moduleComboBox, formValid); + setupComboBoxAdd(statusComboBox, formValid); + setupComboBoxAdd(caseSignificanceComboBox, formValid); + setupComboBoxAdd(languageComboBox, formValid); + + + } + + @Override + protected void onCancel() { + close(cancelButton); + } + + @Override + protected void onSubmit() { + // TODO assuming it's valid save() check for errors and publish event + + fqnViewModel.save(); + if (fqnViewModel.getValidationMessages().isEmpty()) { + // publish event with the fqnViewModel. + // ... This property may not be needed. + fqnViewModel.setPropertyValue(IS_SUBMITTED, true); + } + + LOG.info("Ready to add to the concept view model: " + fqnViewModel); + + ////////////////////////////////////////////////////////////////////////////////////////// + // event received in Details Controller that will call conceptViewModel.createConcept() + ////////////////////////////////////////////////////////////////////////////////////////// + DescrName fqnDescrName = fqnViewModel.create(); + eventBus.publish(conceptTopic, new CreateConceptEvent(this, CreateConceptEvent.ADD_FQN, fqnDescrName)); + + // clear the form after saving. otherwise when you navigate back to Add Other Name + // you would have the previous form values still there + clearView(); + close(submitButton); + } + + + private void populate(ComboBox comboBox, Collection entities) { + comboBox.getItems().setAll(entities); + } + + @Override + public void updateView() { + + // populate form combo fields module, status, case significance, lang. + populate(moduleComboBox, fqnViewModel.findAllModules(getViewProperties())); + populate(statusComboBox, fqnViewModel.findAllStatuses(getViewProperties())); + populate(caseSignificanceComboBox, fqnViewModel.findAllCaseSignificants(getViewProperties())); + populate(languageComboBox, fqnViewModel.findAllLanguages(getViewProperties())); + + // Set UI to default values + caseSignificanceComboBox.setValue(TinkarTerm.DESCRIPTION_NOT_CASE_SENSITIVE); + statusComboBox.setValue(Entity.getFast(State.ACTIVE.nid())); + moduleComboBox.setValue(TinkarTerm.DEVELOPMENT_MODULE); + languageComboBox.setValue(TinkarTerm.ENGLISH_LANGUAGE); + } + + @Override + public void clearView() { + nameTextField.setText(""); + moduleComboBox.setValue(null); + statusComboBox.setValue(null); + caseSignificanceComboBox.setValue(null); + languageComboBox.setValue(null); +// if (fqnViewModel != null) { +// copyUIToViewModelProperties(); +// fqnViewModel.save(true); // make UI properties as model values +// } + moduleComboBox.getItems().clear(); + statusComboBox.getItems().clear(); + caseSignificanceComboBox.getItems().clear(); + languageComboBox.getItems().clear(); + } + + /** + * TODO: This is appropriate. A better solution is binding properties on the view model. If so, we'd need to unbind. + * This copies form values into the ViewModel's property values. It does not save or validate. + */ + private void copyUIToViewModelProperties() { + if (fqnViewModel != null) { + fqnViewModel.setPropertyValue(NAME_TEXT, nameTextField.getText()) + .setPropertyValue(NAME_TYPE, TinkarTerm.FULLY_QUALIFIED_NAME_DESCRIPTION_TYPE) + .setPropertyValue(CASE_SIGNIFICANCE, caseSignificanceComboBox.getSelectionModel().getSelectedItem()) + .setPropertyValue(STATUS, statusComboBox.getSelectionModel().getSelectedItem()) + .setPropertyValue(MODULE, moduleComboBox.getSelectionModel().getSelectedItem()) + .setPropertyValue(LANGUAGE, languageComboBox.getSelectionModel().getSelectedItem()); + } + } + + + @Override + public DescrNameViewModel getViewModel() { + return fqnViewModel; + } + + +} diff --git a/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/DescriptionAddOtherController.java b/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/DescriptionAddOtherController.java new file mode 100644 index 000000000..3b5deabdb --- /dev/null +++ b/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/DescriptionAddOtherController.java @@ -0,0 +1,165 @@ +package dev.ikm.komet.kview.mvvm.view.properties; + +import dev.ikm.komet.framework.view.ViewProperties; +import dev.ikm.komet.kview.events.CreateConceptEvent; +import dev.ikm.komet.kview.mvvm.model.DescriptionFormType; +import dev.ikm.komet.kview.mvvm.viewmodel.OtherNameViewModel; +import dev.ikm.tinkar.entity.ConceptEntity; +import dev.ikm.tinkar.entity.Entity; +import dev.ikm.tinkar.terms.EntityFacade; +import dev.ikm.tinkar.terms.State; +import dev.ikm.tinkar.terms.TinkarTerm; +import javafx.beans.InvalidationListener; +import javafx.scene.control.ComboBox; +import org.carlfx.cognitive.loader.InjectViewModel; +import org.carlfx.cognitive.viewmodel.ViewModel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Collection; +import java.util.UUID; + +import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.*; +import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.CASE_SIGNIFICANCE; +import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.LANGUAGE; +import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.MODULE; +import static dev.ikm.komet.kview.mvvm.viewmodel.OtherNameViewModel.OtherNameProperties.*; + +public class DescriptionAddOtherController extends DescriptionBaseController{ + private static final Logger LOG = LoggerFactory.getLogger(DescriptionAddOtherController.class); + @InjectViewModel + private OtherNameViewModel otherNameViewModel; // TODO why we need that wrapper only for this class but can get away in all 3 others + + + // TODO: how does it work with no UUID + //public DescriptionAddOtherController() { + // super(DescriptionFormType.ADD_OTHER_NAME, conceptTopic); + //} + + public DescriptionAddOtherController(UUID conceptTopic) { + super(DescriptionFormType.ADD_OTHER_NAME, conceptTopic); + } + + + @Override + protected void initializeData() { + configureDialectVisibility(false); + + submitButton.setDisable(true); + + titleLabel.setText("Add New Description: Other Name"); // TODO: check if needed ? + otherNameViewModel + .setPropertyValue(NAME_TYPE, TinkarTerm.REGULAR_NAME_DESCRIPTION_TYPE) + .setPropertyValue(STATUS, TinkarTerm.ACTIVE_STATE); + // register listeners + InvalidationListener formValid = (obs) -> { + boolean isFormValid = isFormPopulated(); + if (isFormValid) { + copyUIToViewModelProperties(); + } + submitButton.setDisable(!isFormValid); + }; + + nameTextField.textProperty().addListener(formValid); + setupComboBoxAdd(moduleComboBox, formValid); + setupComboBoxAdd(statusComboBox, formValid); + setupComboBoxAdd(caseSignificanceComboBox, formValid); + setupComboBoxAdd(languageComboBox, formValid); + } + + @Override + public void updateView() { + // populate form combo fields module, status, case significance, lang. + populate(moduleComboBox, otherNameViewModel.findAllModules(getViewProperties())); + populate(statusComboBox, otherNameViewModel.findAllStatuses(getViewProperties())); + populate(caseSignificanceComboBox, otherNameViewModel.findAllCaseSignificants(getViewProperties())); + populate(languageComboBox, otherNameViewModel.findAllLanguages(getViewProperties())); + + boolean hasOtherName = getViewModel().getValue(HAS_OTHER_NAME); + + if (hasOtherName) { + caseSignificanceComboBox.setValue(getViewModel().getValue(FQN_CASE_SIGNIFICANCE)); + } else { + caseSignificanceComboBox.setValue(TinkarTerm.DESCRIPTION_NOT_CASE_SENSITIVE); + } + statusComboBox.setValue(Entity.getFast(State.ACTIVE.nid())); + moduleComboBox.setValue(TinkarTerm.DEVELOPMENT_MODULE); + if (hasOtherName) { + languageComboBox.setValue(getViewModel().getValue(FQN_LANGUAGE)); + } else { + languageComboBox.setValue(TinkarTerm.ENGLISH_LANGUAGE); + } + } + + public void updateModel(final ViewProperties viewProperties) { + this.viewProperties = viewProperties; + } + + @Override + public void clearView() { + nameTextField.setText(""); + moduleComboBox.setValue(null); + statusComboBox.setValue(null); + caseSignificanceComboBox.setValue(null); + languageComboBox.setValue(null); + moduleComboBox.getItems().clear(); + statusComboBox.getItems().clear(); + caseSignificanceComboBox.getItems().clear(); + languageComboBox.getItems().clear(); + } + + @Override + protected void onCancel() { + close(cancelButton); + } + + @Override + protected void onSubmit() { + // TODO assuming it's valid save() check for errors and publish event + otherNameViewModel.setPropertyValue(IS_SUBMITTED, true); + otherNameViewModel.save(); + if (otherNameViewModel.hasNoErrorMsgs()) { + // publish event with the otherNameViewModel. + // ... + LOG.info("Ready to add to the concept view model: " + otherNameViewModel); + eventBus.publish(conceptTopic, new CreateConceptEvent(this, CreateConceptEvent.ADD_OTHER_NAME, + otherNameViewModel.create())); + clearView(); + close(submitButton); + } + } + + @Override + public OtherNameViewModel getViewModel() { + return otherNameViewModel; + } + + /** + * TODO: This is appropriate. A better solution is binding properties on the view model. If so, we'd need to unbind. + * This copies form values into the ViewModel's property values. It does not save or validate. + */ + private void copyUIToViewModelProperties() { + if (otherNameViewModel != null) { + otherNameViewModel.setPropertyValue(NAME_TEXT, nameTextField.getText()) + .setPropertyValue(NAME_TYPE, TinkarTerm.REGULAR_NAME_DESCRIPTION_TYPE) + .setPropertyValue(CASE_SIGNIFICANCE, caseSignificanceComboBox.getSelectionModel().getSelectedItem()) + .setPropertyValue(STATUS, statusComboBox.getSelectionModel().getSelectedItem()) + .setPropertyValue(MODULE, moduleComboBox.getSelectionModel().getSelectedItem()) + .setPropertyValue(LANGUAGE, languageComboBox.getSelectionModel().getSelectedItem()); + } + } + + public void setAddOtherNameTitleLabel(String addDescriptionTitleLabelText) { + this.titleLabel.setText(addDescriptionTitleLabelText); + } + + public void populate(ComboBox comboBox, Collection entities) { + comboBox.getItems().addAll(entities); + } + + public void hideNonUsed() { + dialect1.setVisible(false); + dialectComboBox1.setVisible(false); + + } +} diff --git a/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/DescriptionBaseController.java b/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/DescriptionBaseController.java new file mode 100644 index 000000000..40cb0a29c --- /dev/null +++ b/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/DescriptionBaseController.java @@ -0,0 +1,330 @@ +package dev.ikm.komet.kview.mvvm.view.properties; + +import dev.ikm.komet.framework.view.ViewProperties; +import dev.ikm.komet.kview.events.ClosePropertiesPanelEvent; +import dev.ikm.komet.kview.mvvm.model.DescriptionFormType; +import dev.ikm.komet.kview.mvvm.view.AbstractBasicController; +import dev.ikm.komet.kview.mvvm.view.BasicController; +import dev.ikm.tinkar.common.id.PublicId; +import dev.ikm.tinkar.entity.ConceptEntity; +import dev.ikm.tinkar.entity.Entity; +import dev.ikm.tinkar.entity.EntityService; +import dev.ikm.tinkar.entity.EntityVersion; +import dev.ikm.tinkar.events.EvtBus; +import dev.ikm.tinkar.events.EvtBusFactory; +import dev.ikm.tinkar.terms.EntityFacade; +import dev.ikm.tinkar.terms.TinkarTerm; +import javafx.beans.InvalidationListener; +import javafx.fxml.FXML; +import javafx.scene.control.*; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.Region; +import javafx.scene.layout.RowConstraints; +import javafx.scene.layout.VBox; +import javafx.util.Callback; +import javafx.util.StringConverter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.*; + + +public abstract class DescriptionBaseController extends AbstractBasicController { + + private static final Logger LOG = LoggerFactory.getLogger(DescriptionBaseController.class); + + protected UUID conceptTopic; + + protected ViewProperties viewProperties; + + protected EntityFacade entityFacade; + + protected PublicId publicId; + + @FXML + protected Label titleLabel; + + @FXML + protected TextField nameTextField; // TODO more descriptive name + + @FXML + protected ComboBox typeComboBox; + + @FXML + protected ComboBox moduleComboBox; + + @FXML + protected ComboBox statusComboBox; + + @FXML + protected ComboBox caseSignificanceComboBox; + + @FXML + protected ComboBox languageComboBox; + + + @FXML + protected RowConstraints dialectCommentsRowConstraints; // shared constrain in edit/add mode + + @FXML + protected Label commentsLabel; // label shown in add mode only + + + // Dialects (only visible in edit mode) + @FXML + protected VBox dialectsContainer; + + @FXML + protected Label dialect1; + + @FXML + protected Label dialect2; + + @FXML + protected Label dialect3; + + @FXML + protected ComboBox dialectComboBox1; + + @FXML + protected ComboBox dialectComboBox2; + + @FXML + protected ComboBox dialectComboBox3; + + + // + @FXML + protected Button submitButton; + + @FXML + protected Button cancelButton; + + protected EvtBus eventBus; + + protected final DescriptionFormType formType; + + public DescriptionBaseController(DescriptionFormType formType, UUID conceptTopic) { + this.formType = formType; + this.conceptTopic = conceptTopic; + } + + @FXML + public final void initialize() { + // Common initialization that ALWAYS runs + eventBus = EvtBusFactory.getDefaultEvtBus(); + clearView(); + + // Let subclasses do their specific initialization + initializeData(); + + } + + protected abstract void initializeData(); + + @Override + public void clearView() { + // Common view clearing logic + if (nameTextField != null) { + nameTextField.clear(); + } + //if (commentsTextArea != null) { + // commentsTextArea.clear(); + //} + // Clear combo boxes + if (caseSignificanceComboBox != null) { + caseSignificanceComboBox.getSelectionModel().clearSelection(); + } + if (statusComboBox != null) { + statusComboBox.getSelectionModel().clearSelection(); + } + if (moduleComboBox != null) { + moduleComboBox.getSelectionModel().clearSelection(); + } + if (languageComboBox != null) { + languageComboBox.getSelectionModel().clearSelection(); + } + } + + @Override + public void cleanup() { + + } + + @FXML + protected void handleCancel() { + onCancel(); + } + + @FXML + protected void handleSubmit() { + onSubmit(); + } + + protected abstract void onCancel(); + protected abstract void onSubmit(); + + private String getDisplayText(ConceptEntity conceptEntity) { + Optional stringOptional = getViewProperties().calculator().getRegularDescriptionText(conceptEntity.nid()); + return stringOptional.orElse(""); + } + + protected void setupComboBoxAdd(ComboBox comboBox, InvalidationListener listener) { + comboBox.setConverter(new StringConverter() { + + @Override + public String toString(ConceptEntity conceptEntity) { + return getDisplayText(conceptEntity); + } + + @Override + public ConceptEntity fromString(String string) { + return null; + } + }); + + comboBox.setCellFactory(new Callback<>() { + + /** + * @param param The single argument upon which the returned value should be + * determined. + * @return + */ + @Override + public ListCell call(Object param) { + return new ListCell<>(){ + @Override + protected void updateItem(ConceptEntity conceptEntity, boolean b) { + super.updateItem(conceptEntity, b); + if (conceptEntity != null) { + setText(getDisplayText(conceptEntity)); + } else { + setText(null); + } + + } + }; + } + }); + // register invalidation listener + comboBox.getSelectionModel().selectedItemProperty().addListener(listener); + + } + + protected void setupComboBoxEdit(ComboBox comboBox, Collection conceptEntities) { + + comboBox.getItems().clear(); + comboBox.setConverter(new StringConverter() { + + @Override + public String toString(ConceptEntity conceptEntity) { + return getDisplayText(conceptEntity); + } + + @Override + public ConceptEntity fromString(String string) { + return null; + } + }); + + comboBox.setCellFactory(new Callback<>() { + + /** + * @param param The single argument upon which the returned value should be + * determined. + * @return + */ + @Override + public ListCell call(Object param) { + return new ListCell<>(){ + @Override + protected void updateItem(ConceptEntity conceptEntity, boolean b) { + super.updateItem(conceptEntity, b); + if (conceptEntity != null) { + setText(getDisplayText(conceptEntity)); + } else { + setText(null); + } + + } + }; + } + }); + comboBox.getItems().addAll(conceptEntities); + } + + boolean isFormPopulated() { // 1 AddOther used + return (nameTextField.getText() != null && !nameTextField.getText().isEmpty()) + && (moduleComboBox.getSelectionModel().getSelectedItem() != null) + && (statusComboBox.getSelectionModel().getSelectedItem() != null) + && (caseSignificanceComboBox.getSelectionModel().getSelectedItem() != null) + && (languageComboBox.getSelectionModel().getSelectedItem() != null); + } + + protected void populateDialectComboBoxes() { + // currently no UNACCEPTABLE in TinkarTerm + Entity acceptable = EntityService.get().getEntityFast(TinkarTerm.ACCEPTABLE); + Entity preferred = EntityService.get().getEntityFast(TinkarTerm.PREFERRED); + + // each combo box has a separate list instance + setupComboBoxEdit(dialectComboBox1, Arrays.asList(Entity.getFast(acceptable.nid()), Entity.getFast(preferred.nid()))); + dialectComboBox1.getSelectionModel().select(Entity.getFast(acceptable.nid())); + setupComboBoxEdit(dialectComboBox2, Arrays.asList(Entity.getFast(acceptable.nid()), Entity.getFast(preferred.nid()))); + dialectComboBox2.getSelectionModel().select(Entity.getFast(preferred.nid())); + setupComboBoxEdit(dialectComboBox3, Arrays.asList(Entity.getFast(acceptable.nid()), Entity.getFast(preferred.nid()))); + dialectComboBox3.getSelectionModel().select(Entity.getFast(preferred.nid())); + } + + protected void validateForm() { + boolean isFqnTextEmpty = nameTextField.getText().trim().isEmpty(); + boolean isModuleComboBoxSelected = moduleComboBox.getValue() != null; + boolean isCaseSignificanceComboBoxSelected = caseSignificanceComboBox.getValue() != null; + boolean isStatusComboBoxComboBoxSelected = statusComboBox.getValue() != null; + boolean isLanguageComboBoxComboBoxSelected = languageComboBox.getValue() != null; + + submitButton.setDisable( + isFqnTextEmpty || !isModuleComboBoxSelected + || !isCaseSignificanceComboBoxSelected || !isLanguageComboBoxComboBoxSelected + || !isStatusComboBoxComboBoxSelected); + } + + + protected void close(Button button) { + // close the properties bump out + eventBus.publish(conceptTopic, new ClosePropertiesPanelEvent(button, + ClosePropertiesPanelEvent.CLOSE_PROPERTIES)); + } + + protected void configureDialectVisibility(boolean showDialects) { + + + if (commentsLabel != null) { + commentsLabel.setVisible(!showDialects); + commentsLabel.setManaged(!showDialects); + } + + if (dialectsContainer != null) { + dialectsContainer.setVisible(showDialects); + dialectsContainer.setManaged(showDialects); + + } + + // Sets the correct minHeight constraint depending on add/edit mode + if (dialectCommentsRowConstraints != null) { + // a alternative solution would be to introduce a duplicated description-form.fxml for add / edit mode + if (showDialects) { + dialectCommentsRowConstraints.setMaxHeight(200.0); + dialectCommentsRowConstraints.setMinHeight(200.0); + dialectCommentsRowConstraints.setPrefHeight(200.0); + } else { + dialectCommentsRowConstraints.setMaxHeight(40.0); + dialectCommentsRowConstraints.setMinHeight(40.0); + dialectCommentsRowConstraints.setPrefHeight(40.0); + } + } + + } + + + +} diff --git a/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/EditFullyQualifiedNameController.java b/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/DescriptionEditFqnController.java similarity index 54% rename from kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/EditFullyQualifiedNameController.java rename to kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/DescriptionEditFqnController.java index eecffb98f..e58cb4f32 100644 --- a/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/EditFullyQualifiedNameController.java +++ b/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/DescriptionEditFqnController.java @@ -1,28 +1,11 @@ -/* - * Copyright © 2015 Integrated Knowledge Management (support@ikm.dev) - * - * 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. - */ package dev.ikm.komet.kview.mvvm.view.properties; -import dev.ikm.tinkar.events.EvtBus; -import dev.ikm.tinkar.events.EvtBusFactory; import dev.ikm.komet.framework.view.ViewProperties; import dev.ikm.komet.kview.events.ClosePropertiesPanelEvent; import dev.ikm.komet.kview.events.CreateConceptEvent; import dev.ikm.komet.kview.events.EditConceptEvent; import dev.ikm.komet.kview.mvvm.model.DescrName; -import dev.ikm.komet.kview.mvvm.view.BasicController; +import dev.ikm.komet.kview.mvvm.model.DescriptionFormType; import dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel; import dev.ikm.tinkar.common.id.IntIdSet; import dev.ikm.tinkar.common.id.PublicId; @@ -33,99 +16,48 @@ import dev.ikm.tinkar.terms.EntityFacade; import dev.ikm.tinkar.terms.TinkarTerm; import javafx.beans.InvalidationListener; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.scene.control.*; -import javafx.util.Callback; -import javafx.util.StringConverter; import org.carlfx.cognitive.loader.InjectViewModel; +import org.carlfx.cognitive.viewmodel.ViewModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.*; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; import java.util.stream.Collectors; import static dev.ikm.komet.kview.mvvm.model.DataModelHelper.fetchDescendentsOfConcept; import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.*; +import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.CASE_SIGNIFICANCE; +import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.LANGUAGE; +import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.STATUS; import static dev.ikm.tinkar.terms.TinkarTerm.DESCRIPTION_CASE_SIGNIFICANCE; import static dev.ikm.tinkar.terms.TinkarTerm.LANGUAGE_CONCEPT_NID_FOR_DESCRIPTION; -public class EditFullyQualifiedNameController implements BasicController { +public class DescriptionEditFqnController extends DescriptionBaseController{ - private static final Logger LOG = LoggerFactory.getLogger(EditFullyQualifiedNameController.class); + private static final Logger LOG = LoggerFactory.getLogger(DescriptionEditFqnController.class); - private UUID conceptTopic; - - private ViewProperties viewProperties; - - private EntityFacade entityFacade; - - private PublicId publicId; - - @FXML - private Label editFullyQualifiedNameTitleLabel; - - @FXML - private TextField fqnText; - - @FXML - private ComboBox moduleComboBox; - - @FXML - private ComboBox statusComboBox; - - @FXML - private ComboBox caseSignificanceComboBox; - - @FXML - private ComboBox languageComboBox; - - @FXML - private Label dialect1; - - @FXML - private Label dialect2; - - @FXML - private Label dialect3; - - @FXML - private ComboBox dialectComboBox1; - - @FXML - private ComboBox dialectComboBox2; - - @FXML - private ComboBox dialectComboBox3; - - @FXML - private Button submitButton; - - @FXML - private Button cancelButton; - - private EvtBus eventBus; @InjectViewModel private DescrNameViewModel fqnViewModel; - public EditFullyQualifiedNameController() { } - - public EditFullyQualifiedNameController(UUID conceptTopic) { - this.conceptTopic = conceptTopic; + public DescriptionEditFqnController(UUID conceptTopic) { + super(DescriptionFormType.EDIT_FQN, conceptTopic); } - @FXML - public void initialize() { - eventBus = EvtBusFactory.getDefaultEvtBus(); - clearView(); - setEditFullyQualifiedNameTitleLabel("Edit Description: Fully Qualified Name"); + + @Override + protected void initializeData() { + titleLabel.setText("Edit Description: Fully Qualified Name"); + configureDialectVisibility(true); populateDialectComboBoxes(); fqnViewModel.setPropertyValue(NAME_TYPE, TinkarTerm.FULLY_QUALIFIED_NAME_DESCRIPTION_TYPE); // bind with viewmodel. - fqnText.textProperty().bindBidirectional(fqnViewModel.getProperty(NAME_TEXT)); + nameTextField.textProperty().bindBidirectional(fqnViewModel.getProperty(NAME_TEXT)); moduleComboBox.valueProperty().bindBidirectional(fqnViewModel.getProperty(MODULE)); caseSignificanceComboBox.valueProperty().bindBidirectional(fqnViewModel.getProperty(CASE_SIGNIFICANCE)); statusComboBox.valueProperty().bindBidirectional(fqnViewModel.getProperty(STATUS)); @@ -133,111 +65,88 @@ public void initialize() { InvalidationListener invalidationListener = obs -> validateForm(); - fqnText.textProperty().addListener(invalidationListener); + nameTextField.textProperty().addListener(invalidationListener); moduleComboBox.valueProperty().addListener(invalidationListener); caseSignificanceComboBox.valueProperty().addListener(invalidationListener); statusComboBox.valueProperty().addListener(invalidationListener); languageComboBox.valueProperty().addListener(invalidationListener); validateForm(); - submitButton.setOnAction(this::updateFQN); + // submitButton.setOnAction(onSubmit); // this is already linked in the fxml not sure why ? } - @FXML - private void handleCancelButtonEvent() { - eventBus.publish(conceptTopic, new ClosePropertiesPanelEvent(cancelButton, - ClosePropertiesPanelEvent.CLOSE_PROPERTIES)); + @Override + protected void onCancel() { + close(cancelButton); } - private void validateForm() { - boolean isFqnTextEmpty = fqnText.getText().trim().isEmpty(); - boolean isModuleComboBoxSelected = moduleComboBox.getValue() != null; - boolean isCaseSignificanceComboBoxSelected = caseSignificanceComboBox.getValue() != null; - boolean isStatusComboBoxComboBoxSelected = statusComboBox.getValue() != null; - boolean isLanguageComboBoxComboBoxSelected = languageComboBox.getValue() != null; - - submitButton.setDisable( - isFqnTextEmpty || !isModuleComboBoxSelected - || !isCaseSignificanceComboBoxSelected || !isLanguageComboBoxComboBoxSelected - || !isStatusComboBoxComboBoxSelected); - } + @Override + protected void onSubmit() { + fqnViewModel.save(); + // validate + if (fqnViewModel.hasErrorMsgs()) { + fqnViewModel.getValidationMessages().stream().forEach(msg -> LOG.error("Validation error " + msg)); + return; + } + fqnViewModel.setPropertyValue(IS_SUBMITTED, true); - private void populateDialectComboBoxes() { - // currently no UNACCEPTABLE in TinkarTerm - Entity acceptable = EntityService.get().getEntityFast(TinkarTerm.ACCEPTABLE); - Entity preferred = EntityService.get().getEntityFast(TinkarTerm.PREFERRED); - - // each combo box has a separate list instance - setupComboBox(dialectComboBox1, Arrays.asList(Entity.getFast(acceptable.nid()), Entity.getFast(preferred.nid()))); - dialectComboBox1.getSelectionModel().select(Entity.getFast(acceptable.nid())); - setupComboBox(dialectComboBox2, Arrays.asList(Entity.getFast(acceptable.nid()), Entity.getFast(preferred.nid()))); - dialectComboBox2.getSelectionModel().select(Entity.getFast(preferred.nid())); - setupComboBox(dialectComboBox3, Arrays.asList(Entity.getFast(acceptable.nid()), Entity.getFast(preferred.nid()))); - dialectComboBox3.getSelectionModel().select(Entity.getFast(preferred.nid())); - } + DescrName fqnDescrName = fqnViewModel.create(); - public void setEditFullyQualifiedNameTitleLabel(String editFullyQualifiedNameTitleLabel) { - this.editFullyQualifiedNameTitleLabel.setText(editFullyQualifiedNameTitleLabel); - } - public void updateModel(final ViewProperties viewProperties, EntityFacade entityFacade) { - this.viewProperties = viewProperties; - this.entityFacade = entityFacade; - } + if(this.publicId != null) { + // delegate the transaction logic to the view model + fqnViewModel.updateFullyQualifiedName(this.publicId); + }else{ + // Concept is edited before the transaction is saved. Hence the pubicId would not be generated. + eventBus.publish(conceptTopic, new CreateConceptEvent(this, CreateConceptEvent.ADD_FQN, fqnDescrName)); + } + + LOG.info("transaction complete"); + clearView(); + + // publish the event of the updated FQN + eventBus.publish(conceptTopic, new EditConceptEvent(submitButton, + EditConceptEvent.EDIT_FQN, fqnDescrName)); - private ViewProperties getViewProperties() { - return this.viewProperties; + // close the property bump out panel + eventBus.publish(conceptTopic, new ClosePropertiesPanelEvent(submitButton, + ClosePropertiesPanelEvent.CLOSE_PROPERTIES)); } - private String getDisplayText(ConceptEntity conceptEntity) { - if (conceptEntity != null) { - Optional stringOptional = getViewProperties().calculator().languageCalculator().getRegularDescriptionText(conceptEntity.nid()); - return stringOptional.orElse(""); - } else { - return ""; - } + @Override + public DescrNameViewModel getViewModel() { + return fqnViewModel; } - private void setupComboBox(ComboBox comboBox, Collection conceptEntities) { - comboBox.getItems().clear(); - comboBox.setConverter(new StringConverter() { + @Override + public void updateView() { - @Override - public String toString(ConceptEntity conceptEntity) { - return getDisplayText(conceptEntity); - } + } - @Override - public ConceptEntity fromString(String string) { - return null; - } - }); + @Override + public void clearView() { + nameTextField.setText(""); + caseSignificanceComboBox.getSelectionModel().clearSelection(); + statusComboBox.getSelectionModel().clearSelection(); + moduleComboBox.getSelectionModel().clearSelection(); + languageComboBox.getSelectionModel().clearSelection(); + } - comboBox.setCellFactory(new Callback<>() { - - /** - * @param param The single argument upon which the returned value should be - * determined. - * @return - */ - @Override - public ListCell call(Object param) { - return new ListCell<>(){ - @Override - protected void updateItem(ConceptEntity conceptEntity, boolean b) { - super.updateItem(conceptEntity, b); - if (conceptEntity != null) { - setText(getDisplayText(conceptEntity)); - } else { - setText(null); - } - - } - }; - } - }); - comboBox.getItems().addAll(conceptEntities); + /** + * This method prepopulates and sets up the form in edit mode. + * @param descrName model values that need to be prepopulated. + */ + public void setConceptAndPopulateForm(DescrName descrName) { + setupComboBoxEdit(moduleComboBox, fetchDescendentsOfConcept(getViewProperties(), TinkarTerm.MODULE.publicId())); + setupComboBoxEdit(statusComboBox, fetchDescendentsOfConcept(getViewProperties(), TinkarTerm.STATUS_VALUE.publicId())); + setupComboBoxEdit(caseSignificanceComboBox, fqnViewModel.findAllCaseSignificants(getViewProperties())); + setupComboBoxEdit(languageComboBox, fetchDescendentsOfConcept(getViewProperties(), TinkarTerm.LANGUAGE.publicId())); + fqnViewModel.setPropertyValue(NAME_TEXT, descrName.getNameText()) + .setPropertyValue(CASE_SIGNIFICANCE, descrName.getCaseSignificance()) + .setPropertyValue(STATUS, descrName.getStatus()) + .setPropertyValue(MODULE, descrName.getModule()) + .setPropertyValue(LANGUAGE, descrName.getLanguage()); } public void setConceptAndPopulateForm(PublicId publicId) { @@ -252,7 +161,7 @@ public void setConceptAndPopulateForm(PublicId publicId) { latestEntityVersion.ifPresent(semanticEntityVersion -> { StampEntity stampEntity = latestEntityVersion.get().stamp(); String otherName = viewCalculator.getDescriptionText(nid).get(); - this.fqnText.setText(otherName); + this.nameTextField.setText(otherName); // get all descendant modules IntIdSet moduleDescendents = viewProperties.parentView().calculator().descendentsOf(TinkarTerm.MODULE.nid()); @@ -260,7 +169,7 @@ public void setConceptAndPopulateForm(PublicId publicId) { moduleDescendents.intStream() .mapToObj(moduleNid -> (ConceptEntity) Entity.getFast(moduleNid)) .collect(Collectors.toSet()); - setupComboBox(moduleComboBox, allModules); + setupComboBoxEdit(moduleComboBox, allModules); // populate the current module and select it (e.g. 'SNOMED CT core module') findByNid(moduleComboBox.getItems(), stampEntity.moduleNid()) @@ -271,7 +180,7 @@ public void setConceptAndPopulateForm(PublicId publicId) { Set allStatuses = statusDescendents.intStream() .mapToObj(statusNid -> (ConceptEntity) Entity.getFast(statusNid)) .collect(Collectors.toSet()); - setupComboBox(statusComboBox, allStatuses); + setupComboBoxEdit(statusComboBox, allStatuses); // populate the current status (ACTIVE | INACTIVE) and select it findByNid(statusComboBox.getItems(), stampEntity.stateNid()) @@ -283,7 +192,7 @@ public void setConceptAndPopulateForm(PublicId publicId) { Set allCaseDescendents = caseSenseDescendents.intStream() .mapToObj(caseNid -> (ConceptEntity) Entity.getFast(caseNid)) .collect(Collectors.toSet()); - setupComboBox(caseSignificanceComboBox, allCaseDescendents); + setupComboBoxEdit(caseSignificanceComboBox, allCaseDescendents); // get case concept's case sensitivity (e.g. 'Case insensitive') PatternEntity patternEntity = latestEntityVersion.get().pattern(); @@ -299,7 +208,7 @@ public void setConceptAndPopulateForm(PublicId publicId) { Set allLangs = languageDescendents.intStream() .mapToObj(langNid -> (ConceptEntity) Entity.getFast(langNid)) .collect(Collectors.toSet()); - setupComboBox(languageComboBox, allLangs); + setupComboBoxEdit(languageComboBox, allLangs); // get the language (e.g. 'English language') int indexLang = patternEntityVersion.indexForMeaning(LANGUAGE_CONCEPT_NID_FOR_DESCRIPTION); @@ -316,57 +225,6 @@ public void setConceptAndPopulateForm(PublicId publicId) { }); } - @FXML - private void updateFQN(ActionEvent actionEvent) { - actionEvent.consume(); - - fqnViewModel.save(); - // validate - if (fqnViewModel.hasErrorMsgs()) { - fqnViewModel.getValidationMessages().stream().forEach(msg -> LOG.error("Validation error " + msg)); - return; - } - fqnViewModel.setPropertyValue(IS_SUBMITTED, true); - - DescrName fqnDescrName = fqnViewModel.create(); - - - if(this.publicId != null) { - // delegate the transaction logic to the view model - fqnViewModel.updateFullyQualifiedName(this.publicId); - }else{ - // Concept is edited before the transaction is saved. Hence the pubicId would not be generated. - eventBus.publish(conceptTopic, new CreateConceptEvent(this, CreateConceptEvent.ADD_FQN, fqnDescrName)); - } - - LOG.info("transaction complete"); - clearView(); - - // publish the event of the updated FQN - eventBus.publish(conceptTopic, new EditConceptEvent(submitButton, - EditConceptEvent.EDIT_FQN, fqnDescrName)); - - // close the property bump out panel - eventBus.publish(conceptTopic, new ClosePropertiesPanelEvent(submitButton, - ClosePropertiesPanelEvent.CLOSE_PROPERTIES)); - } - - - @Override - public void updateView() { } - - @Override - public void clearView() { - fqnText.setText(""); - caseSignificanceComboBox.getSelectionModel().clearSelection(); - statusComboBox.getSelectionModel().clearSelection(); - moduleComboBox.getSelectionModel().clearSelection(); - languageComboBox.getSelectionModel().clearSelection(); - } - - @Override - public void cleanup() { } - private Optional findByNid(List items, int nid) { Optional conceptOption = items.stream().parallel() @@ -375,19 +233,11 @@ private Optional findByNid(List items, int nid) { return conceptOption; } - /** - * This method prepopulates and sets up the form in edit mode. - * @param descrName model values that need to be prepopulated. - */ - public void setConceptAndPopulateForm(DescrName descrName) { - setupComboBox(moduleComboBox, fetchDescendentsOfConcept(getViewProperties(), TinkarTerm.MODULE.publicId())); - setupComboBox(statusComboBox, fetchDescendentsOfConcept(getViewProperties(), TinkarTerm.STATUS_VALUE.publicId())); - setupComboBox(caseSignificanceComboBox, fqnViewModel.findAllCaseSignificants(getViewProperties())); - setupComboBox(languageComboBox, fetchDescendentsOfConcept(getViewProperties(), TinkarTerm.LANGUAGE.publicId())); - fqnViewModel.setPropertyValue(NAME_TEXT, descrName.getNameText()) - .setPropertyValue(CASE_SIGNIFICANCE, descrName.getCaseSignificance()) - .setPropertyValue(STATUS, descrName.getStatus()) - .setPropertyValue(MODULE, descrName.getModule()) - .setPropertyValue(LANGUAGE, descrName.getLanguage()); + public void updateModel(final ViewProperties viewProperties, EntityFacade entityFacade) { + this.viewProperties = viewProperties; + this.entityFacade = entityFacade; } + + + } diff --git a/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/EditDescriptionFormController.java b/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/DescriptionEditOtherController.java similarity index 51% rename from kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/EditDescriptionFormController.java rename to kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/DescriptionEditOtherController.java index f2d08ff25..f868bffa4 100644 --- a/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/EditDescriptionFormController.java +++ b/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/DescriptionEditOtherController.java @@ -1,153 +1,56 @@ -/* - * Copyright © 2015 Integrated Knowledge Management (support@ikm.dev) - * - * 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. - */ package dev.ikm.komet.kview.mvvm.view.properties; -import static dev.ikm.komet.kview.mvvm.model.DataModelHelper.fetchDescendentsOfConcept; -import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.CASE_SIGNIFICANCE; -import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.IS_SUBMITTED; -import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.LANGUAGE; -import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.MODULE; -import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.NAME_TEXT; -import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.NAME_TYPE; -import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.STATUS; -import static dev.ikm.tinkar.terms.TinkarTerm.DESCRIPTION_CASE_SIGNIFICANCE; -import static dev.ikm.tinkar.terms.TinkarTerm.LANGUAGE_CONCEPT_NID_FOR_DESCRIPTION; -import dev.ikm.tinkar.events.EvtBus; -import dev.ikm.tinkar.events.EvtBusFactory; import dev.ikm.komet.framework.view.ViewProperties; import dev.ikm.komet.kview.events.ClosePropertiesPanelEvent; import dev.ikm.komet.kview.events.CreateConceptEvent; import dev.ikm.komet.kview.mvvm.model.DescrName; -import dev.ikm.komet.kview.mvvm.model.ViewCoordinateHelper; -import dev.ikm.komet.kview.mvvm.view.BasicController; +import dev.ikm.komet.kview.mvvm.model.DescriptionFormType; import dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel; +import dev.ikm.komet.kview.mvvm.viewmodel.OtherNameViewModel; import dev.ikm.tinkar.common.id.IntIdSet; import dev.ikm.tinkar.common.id.PublicId; import dev.ikm.tinkar.coordinate.stamp.calculator.Latest; import dev.ikm.tinkar.coordinate.view.calculator.ViewCalculator; -import dev.ikm.tinkar.entity.ConceptEntity; -import dev.ikm.tinkar.entity.Entity; -import dev.ikm.tinkar.entity.EntityService; -import dev.ikm.tinkar.entity.EntityVersion; -import dev.ikm.tinkar.entity.PatternEntity; -import dev.ikm.tinkar.entity.PatternEntityVersion; -import dev.ikm.tinkar.entity.SemanticEntityVersion; -import dev.ikm.tinkar.entity.StampEntity; +import dev.ikm.tinkar.entity.*; import dev.ikm.tinkar.terms.ConceptFacade; import dev.ikm.tinkar.terms.EntityFacade; import dev.ikm.tinkar.terms.TinkarTerm; import javafx.beans.InvalidationListener; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.scene.control.Button; -import javafx.scene.control.ComboBox; -import javafx.scene.control.Label; -import javafx.scene.control.ListCell; -import javafx.scene.control.TextField; -import javafx.util.Callback; -import javafx.util.StringConverter; import org.carlfx.cognitive.loader.InjectViewModel; +import org.carlfx.cognitive.viewmodel.ViewModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Arrays; -import java.util.Collection; import java.util.List; -import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; -public class EditDescriptionFormController implements BasicController { - - private static final Logger LOG = LoggerFactory.getLogger(EditDescriptionFormController.class); - - private UUID conceptTopic; - - private EntityFacade entityFacade; - - private Map> descriptionSemanticsMap; - - private ViewProperties viewProperties; - - @FXML - private TextField otherNameTextField; - - @FXML - private ComboBox comboBox; - - @FXML - private ComboBox moduleComboBox; - - @FXML - private ComboBox statusComboBox; - - @FXML - private ComboBox caseSignificanceComboBox; - - @FXML - private ComboBox languageComboBox; - - @FXML - private Label editDescriptionTitleLabel; - - @FXML - private Label dialect1; - - @FXML - private Label dialect2; - - @FXML - private Label dialect3; - - @FXML - private ComboBox dialectComboBox1; - - @FXML - private ComboBox dialectComboBox2; - - @FXML - private ComboBox dialectComboBox3; - - @FXML - private Button submitButton; - - @FXML - private Button cancelButton; - - private PublicId publicId; +import static dev.ikm.komet.kview.mvvm.model.DataModelHelper.fetchDescendentsOfConcept; +import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.*; +import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.CASE_SIGNIFICANCE; +import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.LANGUAGE; +import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.MODULE; +import static dev.ikm.komet.kview.mvvm.viewmodel.DescrNameViewModel.STATUS; +import static dev.ikm.tinkar.terms.TinkarTerm.DESCRIPTION_CASE_SIGNIFICANCE; +import static dev.ikm.tinkar.terms.TinkarTerm.LANGUAGE_CONCEPT_NID_FOR_DESCRIPTION; - private EvtBus eventBus; +public class DescriptionEditOtherController extends DescriptionBaseController{ + private static final Logger LOG = LoggerFactory.getLogger(DescriptionEditOtherController.class); @InjectViewModel private DescrNameViewModel otherNameViewModel; - public EditDescriptionFormController() { } + private DescrName editDescrName; - public EditDescriptionFormController(UUID conceptTopic) { - this.conceptTopic = conceptTopic; + public DescriptionEditOtherController(UUID conceptTopic) { + super(DescriptionFormType.EDIT_OTHER_NAME, conceptTopic); } - @Override - @FXML - public void initialize() { - eventBus = EvtBusFactory.getDefaultEvtBus(); - clearView(); - setEditDescriptionTitleLabel("Edit Description: Other Name"); + protected void initializeData() { + + configureDialectVisibility(true); otherNameViewModel .setPropertyValue(NAME_TYPE, TinkarTerm.REGULAR_NAME_DESCRIPTION_TYPE) @@ -156,7 +59,7 @@ public void initialize() { populateDialectComboBoxes(); // bind with viewmodel. - otherNameTextField.textProperty().bindBidirectional(otherNameViewModel.getProperty(NAME_TEXT)); + nameTextField.textProperty().bindBidirectional(otherNameViewModel.getProperty(NAME_TEXT)); moduleComboBox.valueProperty().bindBidirectional(otherNameViewModel.getProperty(MODULE)); caseSignificanceComboBox.valueProperty().bindBidirectional(otherNameViewModel.getProperty(CASE_SIGNIFICANCE)); statusComboBox.valueProperty().bindBidirectional(otherNameViewModel.getProperty(STATUS)); @@ -164,57 +67,48 @@ public void initialize() { InvalidationListener invalidationListener = obs -> validateForm(); - otherNameTextField.textProperty().addListener(invalidationListener); + nameTextField.textProperty().addListener(invalidationListener); moduleComboBox.valueProperty().addListener(invalidationListener); caseSignificanceComboBox.valueProperty().addListener(invalidationListener); statusComboBox.valueProperty().addListener(invalidationListener); languageComboBox.valueProperty().addListener(invalidationListener); validateForm(); - } - @FXML - private void handleCancelButtonEvent() { - eventBus.publish(conceptTopic, new ClosePropertiesPanelEvent(cancelButton, - ClosePropertiesPanelEvent.CLOSE_PROPERTIES)); } - private boolean isFormPopulated() { - return (otherNameTextField.getText() != null && !otherNameTextField.getText().toString().isEmpty()) - && (moduleComboBox.getSelectionModel().getSelectedItem() != null) - && (statusComboBox.getSelectionModel().getSelectedItem() != null) - && (caseSignificanceComboBox.getSelectionModel().getSelectedItem() != null) - && (languageComboBox.getSelectionModel().getSelectedItem() != null); + @Override + protected void onCancel() { + close(cancelButton); } - private void validateForm() { - boolean isOtherNameTextFieldEmpty = otherNameTextField.getText().trim().isEmpty(); - boolean isModuleComboBoxSelected = moduleComboBox.getValue() != null; - boolean isCaseSignificanceComboBoxSelected = caseSignificanceComboBox.getValue() != null; - boolean isStatusComboBoxComboBoxSelected = statusComboBox.getValue() != null; - boolean isLanguageComboBoxComboBoxSelected = languageComboBox.getValue() != null; - - submitButton.setDisable( - isOtherNameTextFieldEmpty || !isModuleComboBoxSelected - || !isCaseSignificanceComboBoxSelected || !isLanguageComboBoxComboBoxSelected - || !isStatusComboBoxComboBoxSelected); - } + @Override + protected void onSubmit() { + otherNameViewModel.save(); + + if (!otherNameViewModel.hasNoErrorMsgs()) { + otherNameViewModel.getValidationMessages().stream().forEach(msg -> LOG.error("Validation error " + msg)); + return; + } + + otherNameViewModel.setPropertyValue(IS_SUBMITTED, true); - private void populateDialectComboBoxes() { - // currently no UNACCEPTABLE in TinkarTerm - Entity acceptable = EntityService.get().getEntityFast(TinkarTerm.ACCEPTABLE); - Entity preferred = EntityService.get().getEntityFast(TinkarTerm.PREFERRED); - - // each combo box has a separate list instance - setupComboBox(dialectComboBox1, Arrays.asList(Entity.getFast(acceptable.nid()), Entity.getFast(preferred.nid()))); - dialectComboBox1.getSelectionModel().select(Entity.getFast(acceptable.nid())); - setupComboBox(dialectComboBox2, Arrays.asList(Entity.getFast(acceptable.nid()), Entity.getFast(preferred.nid()))); - dialectComboBox2.getSelectionModel().select(Entity.getFast(preferred.nid())); - setupComboBox(dialectComboBox3, Arrays.asList(Entity.getFast(acceptable.nid()), Entity.getFast(preferred.nid()))); - dialectComboBox3.getSelectionModel().select(Entity.getFast(preferred.nid())); + + LOG.info("Ready to update to the concept view model: " + otherNameViewModel); + + if(this.publicId != null) { //This if blocked is called when editing the exiting concept. + otherNameViewModel.updateOtherName(this.publicId); + }else{ // This block is called when editing the while creating the concept. + otherNameViewModel.updateData(editDescrName); + eventBus.publish(conceptTopic, new CreateConceptEvent(this, + CreateConceptEvent.EDIT_OTHER_NAME, editDescrName)); + } + eventBus.publish(conceptTopic, new ClosePropertiesPanelEvent(submitButton, + ClosePropertiesPanelEvent.CLOSE_PROPERTIES)); } - public void setEditDescriptionTitleLabel(String addAxiomTitleLabelText) { - this.editDescriptionTitleLabel.setText(addAxiomTitleLabelText); + @Override + public DescrNameViewModel getViewModel() { // TODO why diverge here from DescriptionAddOtherController with return type + return otherNameViewModel; } @Override @@ -230,76 +124,26 @@ public void clearView() { languageComboBox.getItems().clear(); } - @Override - public void cleanup() { - - } - public void updateModel(final ViewProperties viewProperties, EntityFacade entityFacade) { this.viewProperties = viewProperties; this.entityFacade = entityFacade; } - private ViewProperties getViewProperties() { - return this.viewProperties; - } - - private String getDisplayText(ConceptEntity conceptEntity) { - if (conceptEntity != null) { - Optional stringOptional = getViewProperties().calculator().getRegularDescriptionText(conceptEntity.nid()); - return stringOptional.orElse(""); - } else { - return ""; - } - } - - private void setupComboBox(ComboBox comboBox, Collection conceptEntities) { - comboBox.getItems().clear(); - comboBox.setConverter(new StringConverter() { - - @Override - public String toString(ConceptEntity conceptEntity) { - return getDisplayText(conceptEntity); - } - - @Override - public ConceptEntity fromString(String string) { - return null; - } - }); - - comboBox.setCellFactory(new Callback<>() { - - /** - * @param param The single argument upon which the returned value should be - * determined. - * @return - */ - @Override - public ListCell call(Object param) { - return new ListCell<>(){ - @Override - protected void updateItem(ConceptEntity conceptEntity, boolean b) { - super.updateItem(conceptEntity, b); - if (conceptEntity != null) { - setText(getDisplayText(conceptEntity)); - } else { - setText(null); - } - - } - }; - } - }); - comboBox.getItems().addAll(conceptEntities); - } - - private Optional findByNid(List items, int nid) { - - Optional conceptOption = items.stream().parallel() - .filter(item -> (item.nid() == nid)).findAny(); - - return conceptOption; + /** + * This method prepopulates and sets up the form in edit mode. + * @param descrName model values that need to be prepopulated. + */ + public void setConceptAndPopulateForm(DescrName descrName) { + editDescrName = descrName; + setupComboBoxEdit(moduleComboBox, fetchDescendentsOfConcept(getViewProperties(), TinkarTerm.MODULE.publicId())); + setupComboBoxEdit(statusComboBox, fetchDescendentsOfConcept(getViewProperties(), TinkarTerm.STATUS_VALUE.publicId())); + setupComboBoxEdit(caseSignificanceComboBox, otherNameViewModel.findAllCaseSignificants(getViewProperties())); + setupComboBoxEdit(languageComboBox, fetchDescendentsOfConcept(getViewProperties(), TinkarTerm.LANGUAGE.publicId())); + otherNameViewModel.setPropertyValue(NAME_TEXT, descrName.getNameText()) + .setPropertyValue(CASE_SIGNIFICANCE, descrName.getCaseSignificance()) + .setPropertyValue(STATUS, descrName.getStatus()) + .setPropertyValue(MODULE, descrName.getModule()) + .setPropertyValue(LANGUAGE, descrName.getLanguage()); } public void setConceptAndPopulateForm(PublicId publicId) { @@ -315,7 +159,7 @@ public void setConceptAndPopulateForm(PublicId publicId) { // populate the other name text field (e.g. 'Chronic lung disease') String otherName = viewCalculator.getDescriptionText(nid).get(); - this.otherNameTextField.setText(otherName); + this.nameTextField.setText(otherName); Entity moduleEntity = EntityService.get().getEntityFast(TinkarTerm.MODULE); IntIdSet moduleDescendents = viewProperties.parentView().calculator().descendentsOf(moduleEntity.nid()); @@ -325,7 +169,7 @@ public void setConceptAndPopulateForm(PublicId publicId) { moduleDescendents.intStream() .mapToObj(moduleNid -> (ConceptEntity) Entity.getFast(moduleNid)) .collect(Collectors.toSet()); - setupComboBox(moduleComboBox, allModules); + setupComboBoxEdit(moduleComboBox, allModules); // populate the current module and select it (e.g. 'SNOMED CT core module') findByNid(moduleComboBox.getItems(), stampEntity.moduleNid()) @@ -336,7 +180,7 @@ public void setConceptAndPopulateForm(PublicId publicId) { Set allStatuses = statusDescendents.intStream() .mapToObj(statusNid -> (ConceptEntity) Entity.getFast(statusNid)) .collect(Collectors.toSet()); - setupComboBox(statusComboBox, allStatuses); + setupComboBoxEdit(statusComboBox, allStatuses); // populate the current status (ACTIVE | INACTIVE) and select it findByNid(statusComboBox.getItems(), stampEntity.stateNid()) @@ -347,7 +191,7 @@ public void setConceptAndPopulateForm(PublicId publicId) { Set allCaseDescendents = caseSenseDescendents.intStream() .mapToObj(caseNid -> (ConceptEntity) Entity.getFast(caseNid)) .collect(Collectors.toSet()); - setupComboBox(caseSignificanceComboBox, allCaseDescendents); + setupComboBoxEdit(caseSignificanceComboBox, allCaseDescendents); // get case concept's case sensitivity (e.g. 'Case insensitive') PatternEntity patternEntity = latestEntityVersion.get().pattern(); @@ -362,7 +206,7 @@ public void setConceptAndPopulateForm(PublicId publicId) { Set allLangs = languageDescendents.intStream() .mapToObj(langNid -> (ConceptEntity) Entity.getFast(langNid)) .collect(Collectors.toSet()); - setupComboBox(languageComboBox, allLangs); + setupComboBoxEdit(languageComboBox, allLangs); // get the language (e.g. 'English language') int indexLang = patternEntityVersion.indexForMeaning(LANGUAGE_CONCEPT_NID_FOR_DESCRIPTION); @@ -377,49 +221,11 @@ public void setConceptAndPopulateForm(PublicId publicId) { }); } - @FXML - private void updateOtherName(ActionEvent actionEvent) { - actionEvent.consume(); - otherNameViewModel.save(); - - if (!otherNameViewModel.hasNoErrorMsgs()) { - otherNameViewModel.getValidationMessages().stream().forEach(msg -> LOG.error("Validation error " + msg)); - return; - } - - otherNameViewModel.setPropertyValue(IS_SUBMITTED, true); - - - LOG.info("Ready to update to the concept view model: " + otherNameViewModel); - - if(this.publicId != null) { //This if blocked is called when editing the exiting concept. - otherNameViewModel.updateOtherName(this.publicId); - }else{ // This block is called when editing the while creating the concept. - otherNameViewModel.updateData(editDescrName); - eventBus.publish(conceptTopic, new CreateConceptEvent(this, - CreateConceptEvent.EDIT_OTHER_NAME, editDescrName)); - } - eventBus.publish(conceptTopic, new ClosePropertiesPanelEvent(submitButton, - ClosePropertiesPanelEvent.CLOSE_PROPERTIES)); - } + private Optional findByNid(List items, int nid) { - private DescrName editDescrName; + Optional conceptOption = items.stream().parallel() + .filter(item -> (item.nid() == nid)).findAny(); - /** - * This method prepopulates and sets up the form in edit mode. - * @param descrName model values that need to be prepopulated. - */ - public void setConceptAndPopulateForm(DescrName descrName) { - editDescrName = descrName; - setupComboBox(moduleComboBox, fetchDescendentsOfConcept(getViewProperties(), TinkarTerm.MODULE.publicId())); - setupComboBox(statusComboBox, fetchDescendentsOfConcept(getViewProperties(), TinkarTerm.STATUS_VALUE.publicId())); - setupComboBox(caseSignificanceComboBox, otherNameViewModel.findAllCaseSignificants(getViewProperties())); - setupComboBox(languageComboBox, fetchDescendentsOfConcept(getViewProperties(), TinkarTerm.LANGUAGE.publicId())); - otherNameViewModel.setPropertyValue(NAME_TEXT, descrName.getNameText()) - .setPropertyValue(CASE_SIGNIFICANCE, descrName.getCaseSignificance()) - .setPropertyValue(STATUS, descrName.getStatus()) - .setPropertyValue(MODULE, descrName.getModule()) - .setPropertyValue(LANGUAGE, descrName.getLanguage()); + return conceptOption; } - } diff --git a/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/PropertiesController.java b/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/PropertiesController.java index 3c5dc53e2..cc15fd3c8 100644 --- a/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/PropertiesController.java +++ b/kview/src/main/java/dev/ikm/komet/kview/mvvm/view/properties/PropertiesController.java @@ -59,13 +59,8 @@ public class PropertiesController implements Serializable { protected static final String EDIT_DESCRIPTIONS_FXML_FILE = "edit-descriptions.fxml"; - protected static final String ADD_OTHER_NAME_FXML_FILE = "add-other-name.fxml"; - - protected static final String EDIT_OTHER_NAME_FXML_FILE = "edit-other-name-form.fxml"; - - protected static final String EDIT_FQN_FXML_FILE = "edit-fully-qualified-name.fxml"; - - protected static final String ADD_FQN_FXML_FILE = "add-fully-qualified-name.fxml"; + // used in conjunction with all child's of DescriptionBaseController + protected static final String DESCRIPTION_FORM_FXML_FILE = "description-form.fxml"; @FXML private SVGPath commentsButton; @@ -109,15 +104,16 @@ public class PropertiesController implements Serializable { private EditConceptController editConceptController; - private AddOtherNameController addOtherNameController; + private EditDescriptionsController editDescriptionsController; + + private DescriptionAddOtherController addOtherNameController; - private EditDescriptionFormController editDescriptionFormController; + private DescriptionEditOtherController editDescriptionFormController; - private EditDescriptionsController editDescriptionsController; + private DescriptionEditFqnController editFullyQualifiedNameController; - private EditFullyQualifiedNameController editFullyQualifiedNameController; + private DescriptionAddFqnController addFullyQualifiedNameController; - private AddFullyQualifiedNameController addFullyQualifiedNameController; private Pane commentsPane = new StackPane(genText("Comments Pane")); private ViewProperties viewProperties; @@ -192,34 +188,38 @@ public void initialize() throws IOException { editDescriptionsController = loaderEditDescriptions.getController(); // NOTE: New way of using injected View Models inside of Controllers. - JFXNode addOtherNameControllerNode = FXMLMvvmLoader.make( - getClass().getResource(ADD_OTHER_NAME_FXML_FILE), - new AddOtherNameController(conceptTopic)); + JFXNode addOtherNameControllerNode = FXMLMvvmLoader.make( + getClass().getResource(DESCRIPTION_FORM_FXML_FILE), + new DescriptionAddOtherController(conceptTopic)); addOtherNamePane = addOtherNameControllerNode.node(); addOtherNameController = addOtherNameControllerNode.controller(); - JFXNode editDescriptionFormControllerNode = FXMLMvvmLoader.make( - getClass().getResource(EDIT_OTHER_NAME_FXML_FILE), - new EditDescriptionFormController(conceptTopic)); + + + JFXNode editDescriptionFormControllerNode = FXMLMvvmLoader.make( + getClass().getResource(DESCRIPTION_FORM_FXML_FILE), + new DescriptionEditOtherController(conceptTopic)); editOtherNamePane = editDescriptionFormControllerNode.node(); editDescriptionFormController = editDescriptionFormControllerNode.controller(); //TODO for future there will be an edit axiom form - JFXNode editFqnControllerNode = FXMLMvvmLoader.make( - getClass().getResource(EDIT_FQN_FXML_FILE), - new EditFullyQualifiedNameController(conceptTopic) + JFXNode addFqnControllerNode = FXMLMvvmLoader.make( + getClass().getResource(DESCRIPTION_FORM_FXML_FILE), + new DescriptionAddFqnController(conceptTopic)); + addFqnPane = addFqnControllerNode.node(); + addFullyQualifiedNameController = addFqnControllerNode.controller(); + + + + JFXNode editFqnControllerNode = FXMLMvvmLoader.make( + getClass().getResource(DESCRIPTION_FORM_FXML_FILE), + new DescriptionEditFqnController(conceptTopic) ); editFqnPane = editFqnControllerNode.node(); editFullyQualifiedNameController = editFqnControllerNode.controller(); - // NOTE: New way of using injected View Models inside of Controllers. - JFXNode addFqnControllerNode = FXMLMvvmLoader.make( - getClass().getResource(ADD_FQN_FXML_FILE), - new AddFullyQualifiedNameController(conceptTopic)); - addFqnPane = addFqnControllerNode.node(); - addFullyQualifiedNameController = addFqnControllerNode.controller(); // initially a default selected tab and view is shown updateDefaultSelectedViews(); @@ -300,7 +300,7 @@ public void initialize() throws IOException { } // check if the center pane is already showing, we don't want duplicate entries in the dropdowns if (!contentBorderPane.getCenter().equals(editFqnPane)) { - editFullyQualifiedNameController.updateModel(getViewProperties(), null); + editFullyQualifiedNameController.updateModel(getViewProperties()); // TODO check if this change was correct contentBorderPane.setCenter(editFqnPane); editButton.setSelected(true); editButton.setText("EDIT"); diff --git a/kview/src/main/resources/dev/ikm/komet/kview/mvvm/view/properties/add-fully-qualified-name.fxml b/kview/src/main/resources/dev/ikm/komet/kview/mvvm/view/properties/add-fully-qualified-name.fxml deleted file mode 100644 index 1d08f6fc5..000000000 --- a/kview/src/main/resources/dev/ikm/komet/kview/mvvm/view/properties/add-fully-qualified-name.fxml +++ /dev/null @@ -1,115 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -