Skip to content

Commit

Permalink
Fix #214 [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
hmiguim committed May 27, 2020
1 parent 88423c2 commit 797c021
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.databasepreservation.common.client.models.wizard.table;

import com.google.gwt.core.client.GWT;
import io.swagger.models.auth.In;

import java.io.Serializable;
Expand Down Expand Up @@ -57,6 +58,10 @@ public void setSelectedSchemas(List<String> schemas) {
this.selectedSchemas = schemas;
}

public boolean isSelectionEmpty() {
return tableAndColumnsParameterMap.isEmpty() && viewAndColumnsParameterMap.isEmpty();
}

public boolean isExternalLobConfigurationSet() {
return externalLobConfigurationSet;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.databasepreservation.common.client.tools;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import com.databasepreservation.common.client.common.lists.widgets.MultipleSelectionTablePanel;
import com.databasepreservation.common.client.models.structure.ViewerColumn;
import com.databasepreservation.common.client.models.structure.ViewerMetadata;
import com.databasepreservation.common.client.models.structure.ViewerSchema;
import com.databasepreservation.common.client.models.structure.ViewerTable;
import com.databasepreservation.common.client.models.structure.ViewerView;
import com.databasepreservation.common.client.models.wizard.table.ColumnParameter;
Expand All @@ -24,12 +24,10 @@ public static TableAndColumnsParameters getTableAndColumnsParameter(
Map<String, MultipleSelectionTablePanel<ViewerTable>> tables,
Map<String, MultipleSelectionTablePanel<ViewerView>> views,
Map<String, MultipleSelectionTablePanel<ViewerColumn>> columns,
Map<String, ExternalLobParameter> externalLobParameterMap,
Map<String, Boolean> viewMaterializationStatus,
Map<String, Boolean> merkleTreeColumnStatus) {
Map<String, ExternalLobParameter> externalLobParameterMap, Map<String, Boolean> viewMaterializationStatus,
Map<String, Boolean> merkleTreeColumnStatus, ViewerMetadata metadata) {

TableAndColumnsParameters tableAndColumnsParameters = new TableAndColumnsParameters();
Set<String> selectedSchemas = new HashSet<>();

tables.forEach((schemaUUID, value) -> {
value.getSelectionModel().getSelectedSet().forEach(table -> {
Expand All @@ -39,7 +37,6 @@ public static TableAndColumnsParameters getTableAndColumnsParameter(
getColumnParameter(columns, externalLobParameterMap, merkleTreeColumnStatus, parameter, table.getUuid());

tableAndColumnsParameters.getTableAndColumnsParameterMap().put(table.getUuid(), parameter);
selectedSchemas.add(table.getSchemaName());
});
});

Expand All @@ -53,21 +50,22 @@ public static TableAndColumnsParameters getTableAndColumnsParameter(
getColumnParameter(columns, externalLobParameterMap, merkleTreeColumnStatus, parameter, view.getUuid());

tableAndColumnsParameters.getViewAndColumnsParameterMap().put(view.getUuid(), parameter);
selectedSchemas.add(view.getSchemaName());
});
});

if (!externalLobParameterMap.isEmpty()) {
tableAndColumnsParameters.setExternalLobConfigurationSet(true);
}

tableAndColumnsParameters.setSelectedSchemas(new ArrayList<>(selectedSchemas));
tableAndColumnsParameters.setSelectedSchemas(
metadata.getSchemas().stream().distinct().map(ViewerSchema::getName).collect(Collectors.toList()));

return tableAndColumnsParameters;
}

private static void getColumnParameter(Map<String, MultipleSelectionTablePanel<ViewerColumn>> columns,
Map<String, ExternalLobParameter> externalLobParameterMap, Map<String, Boolean> merkleTreeColumnStatus, TableAndColumnsParameter parameter, String uuid) {
Map<String, ExternalLobParameter> externalLobParameterMap, Map<String, Boolean> merkleTreeColumnStatus,
TableAndColumnsParameter parameter, String uuid) {
columns.get(uuid).getSelectionModel().getSelectedSet().forEach(column -> {
ColumnParameter columnParameter = new ColumnParameter();
columnParameter.setName(column.getDisplayName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private CreateWizardManager() {

if (wizardInstances.get(position) instanceof CustomViews) {
CustomViews customViews = (CustomViews) wizardInstances.get(position);
customViews.refreshCustomButtons();
customViews.refreshCustomButtons(tableAndColumnsParameters.isSelectionEmpty());
} else {
customButtons.clear();
}
Expand Down Expand Up @@ -202,8 +202,8 @@ private void handleTableAndColumnsPanel() {
wizardContent.clear();
position = 2;
CustomViews customViews = CustomViews.getInstance(tableAndColumnsParameters.getSelectedSchemas(), btnNext,
connectionParameters);
customViews.refreshCustomButtons();
connectionParameters, tableAndColumnsParameters.isSelectionEmpty());
customViews.refreshCustomButtons(tableAndColumnsParameters.isSelectionEmpty());
wizardInstances.add(position, customViews);
wizardContent.add(customViews);
updateButtons();
Expand Down Expand Up @@ -376,6 +376,7 @@ protected void updateButtons() {
btnBack.setEnabled(true);
if (position != 2) {
btnNext.setText(messages.basicActionNext());
btnNext.setEnabled(true);
}

if (position == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,21 @@ interface CustomViewsUiBinder extends UiBinder<Widget, CustomViews> {
private final ComboBoxField customViewSchemaName;
private final Button btnNext;
private final ConnectionParameters connectionParameters;
private boolean isSelectionEmpty;

public static CustomViews getInstance(List<String> schemas, Button btnNext, ConnectionParameters connectionParameters) {
public static CustomViews getInstance(List<String> schemas, Button btnNext, ConnectionParameters connectionParameters, boolean isSelectionEmpty) {
if (instance == null) {
instance = new CustomViews(schemas, btnNext, connectionParameters);
instance = new CustomViews(schemas, btnNext, connectionParameters, isSelectionEmpty);
}
return instance;
}

private CustomViews(List<String> schemas, Button btnNext, ConnectionParameters connectionParameters) {
private CustomViews(List<String> schemas, Button btnNext, ConnectionParameters connectionParameters, boolean isSelectionEmpty) {
initWidget(binder.createAndBindUi(this));

this.btnNext = btnNext;
this.connectionParameters = connectionParameters;
this.isSelectionEmpty = isSelectionEmpty;
customViewsSidebar = CustomViewsSidebar.getInstance();
customViewsList.add(customViewsSidebar);

Expand All @@ -115,10 +117,21 @@ private CustomViews(List<String> schemas, Button btnNext, ConnectionParameters c
}

void checkIfHaveCustomViews() {
GWT.log("is selection empty: " + isSelectionEmpty);
if (customViewsParameters.isEmpty()) {
btnNext.setText(messages.basicActionSkip());
if (isSelectionEmpty) {
btnNext.setText(messages.basicActionNext());
btnNext.setEnabled(false);
btnNext.setTitle(messages.customViewsPageHintForDisableNext());
} else {
btnNext.setText(messages.basicActionSkip());
btnNext.setEnabled(true);
btnNext.setTitle("");
}
} else {
btnNext.setText(messages.basicActionNext());
btnNext.setEnabled(true);
btnNext.setTitle("");
}
}

Expand Down Expand Up @@ -255,9 +268,10 @@ public void onSuccess(Boolean result) {
}
}

void refreshCustomButtons() {
void refreshCustomButtons(boolean isSelectionEmpty) {
customViewsButtons.clear();
customViewsButtons.add(createCustomViewButton());
this.isSelectionEmpty = isSelectionEmpty;
checkIfHaveCustomViews();
}

Expand All @@ -267,8 +281,9 @@ private int customViewFormValidator() {

boolean value = ViewerStringUtils.isBlank(viewNameText) || ViewerStringUtils.isBlank(viewQueryText);

if (value)
if (value) {
return 1;
}

boolean sameName = false;
for (CustomViewsParameter p : customViewsParameters.values()) {
Expand All @@ -277,8 +292,9 @@ private int customViewFormValidator() {
}
}

if (sameName)
if (sameName) {
return 2;
}

return -1;
}
Expand All @@ -289,8 +305,9 @@ private int customViewFormValidatorUpdate(final String customViewName) {

boolean value = ViewerStringUtils.isBlank(viewNameText) || ViewerStringUtils.isBlank(viewQueryText);

if (value)
if (value) {
return 1;
}

boolean sameName = false;
for (CustomViewsParameter p : customViewsParameters.values()) {
Expand All @@ -300,8 +317,9 @@ private int customViewFormValidatorUpdate(final String customViewName) {
}
}

if (sameName)
if (sameName) {
return 2;
}

return -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ public void clear() {

@Override
public boolean validate() {
boolean tablesEmpty = false;
return true;

/*boolean tablesEmpty = false;
boolean viewsEmpty = false;
for (MultipleSelectionTablePanel<ViewerTable> cellTable : tables.values()) {
Expand All @@ -219,13 +221,13 @@ public boolean validate() {
return !tablesEmpty;
}
return !tablesEmpty || !viewsEmpty;
return !tablesEmpty || !viewsEmpty;*/
}

@Override
public TableAndColumnsParameters getValues() {
return WizardUtils.getTableAndColumnsParameter(tables, views, columns, externalLOBsParameters,
viewMaterializationStatus, merkleColumnStatus);
viewMaterializationStatus, merkleColumnStatus, metadata);
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/config/i18n/client/ClientMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,8 @@ public interface ClientMessages extends Messages {

String customViewsPageTextForHelpViewQuery();

String customViewsPageHintForDisableNext();

/********************************************
* Create Wizard: Merkle Tree Filter
********************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ customViewsPageTextForHelpSchemaName=Schema where the custom view should be inte
customViewsPageTextForHelpViewName=Name of the custom view
customViewsPageTextForHelpViewDescription=Description of the custom view
customViewsPageTextForHelpViewQuery=SQL query to obtain the data to populate the custom view
customViewsPageHintForDisableNext=Please fill out a custom view or select any table or view
#############################################################################
# Create Wizard: Merkle Tree Filter #
#############################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ customViewsPageTextForHelpSchemaName=Esquema onde a vista customizada será inte
customViewsPageTextForHelpViewName=Nome da vista customizada
customViewsPageTextForHelpViewDescription=Descrição para a vista customizada
customViewsPageTextForHelpViewQuery=Interrogação em SQL para obter os dados para a criação da vista customizada
customViewsPageHintForDisableNext=Preencha os campos para a vista customizada ou selecione tabelas ou vistas
#############################################################################
# Export Options #
#############################################################################
Expand Down

0 comments on commit 797c021

Please sign in to comment.