Compare commits
8 Commits
vyu/TDI-32
...
rmannibuca
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bbc9138df4 | ||
|
|
e4ce5474e7 | ||
|
|
e6b5bb727b | ||
|
|
5456e94376 | ||
|
|
fc35459dab | ||
|
|
6ac0ebe3f3 | ||
|
|
1b5413ae7e | ||
|
|
95ebcd4f86 |
@@ -24,7 +24,7 @@ import java.util.Objects;
|
||||
import org.talend.sdk.component.studio.Lookups;
|
||||
import org.talend.sdk.component.studio.websocket.WebSocketClient.V1Action;
|
||||
|
||||
public class Action {
|
||||
public class Action<T> {
|
||||
|
||||
public static final String STATUS = "status";
|
||||
|
||||
@@ -70,7 +70,7 @@ public class Action {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, String> callback() {
|
||||
public Map<String, T> callback() {
|
||||
return actionClient().execute(Map.class, family, type, actionName, payload());
|
||||
}
|
||||
|
||||
@@ -100,8 +100,9 @@ public class Action {
|
||||
public enum Type {
|
||||
HEALTHCHECK,
|
||||
SUGGESTIONS,
|
||||
VALIDATION;
|
||||
|
||||
VALIDATION,
|
||||
UPDATE;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString().toLowerCase();
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.Map;
|
||||
/**
|
||||
* It should be Thread-safe as it is used in a Job launched by {@link TaCoKitValueSelectionController}
|
||||
*/
|
||||
public class SuggestionsAction extends Action {
|
||||
public class SuggestionsAction extends Action<String> {
|
||||
|
||||
/**
|
||||
* Cached previously used payload and corresponding response
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright (C) 2006-2018 Talend Inc. - www.talend.com
|
||||
*
|
||||
* 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 org.talend.sdk.component.studio.model.action;
|
||||
|
||||
public class UpdateAction extends Action<Object> {
|
||||
public UpdateAction(final String actionName, final String family, final Type type) {
|
||||
super(actionName, family, type);
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,12 @@ public final class Metadatas {
|
||||
|
||||
public static final String ACTION_VALIDATION_PARAMETERS = "action::validation::parameters";
|
||||
|
||||
public static final String ACTION_UPDATABLE_VALUE = "action::update";
|
||||
|
||||
public static final String ACTION_UPDATABLE_PARAMETERS = "action::update::parameters";
|
||||
|
||||
public static final String ACTION_UPDATABLE_AFTER = "action::update::after";
|
||||
|
||||
public static final String CONDITION_IF_VALUE = "condition::if::value";
|
||||
|
||||
public static final String CONDITION_IF_TARGET = "condition::if::target";
|
||||
|
||||
@@ -15,12 +15,17 @@
|
||||
*/
|
||||
package org.talend.sdk.component.studio.model.parameter;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Optional.ofNullable;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
import static org.talend.sdk.component.studio.model.parameter.Metadatas.ACTION_HEALTHCHECK;
|
||||
import static org.talend.sdk.component.studio.model.parameter.Metadatas.ACTION_SUGGESTIONS_NAME;
|
||||
import static org.talend.sdk.component.studio.model.parameter.Metadatas.ACTION_SUGGESTIONS_PARAMETERS;
|
||||
import static org.talend.sdk.component.studio.model.parameter.Metadatas.ACTION_UPDATABLE_AFTER;
|
||||
import static org.talend.sdk.component.studio.model.parameter.Metadatas.ACTION_UPDATABLE_PARAMETERS;
|
||||
import static org.talend.sdk.component.studio.model.parameter.Metadatas.ACTION_UPDATABLE_VALUE;
|
||||
import static org.talend.sdk.component.studio.model.parameter.Metadatas.ACTION_VALIDATION_NAME;
|
||||
import static org.talend.sdk.component.studio.model.parameter.Metadatas.ACTION_VALIDATION_PARAMETERS;
|
||||
import static org.talend.sdk.component.studio.model.parameter.Metadatas.CONDITION_IF_EVALUTIONSTRATEGY;
|
||||
@@ -50,14 +55,14 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.json.bind.annotation.JsonbCreator;
|
||||
import javax.json.bind.annotation.JsonbProperty;
|
||||
|
||||
import org.talend.sdk.component.server.front.model.PropertyValidation;
|
||||
import org.talend.sdk.component.server.front.model.SimplePropertyDefinition;
|
||||
import org.talend.sdk.component.studio.model.parameter.condition.ConditionGroup;
|
||||
import org.talend.sdk.component.studio.model.parameter.resolver.AbsolutePathResolver;
|
||||
|
||||
import javax.json.bind.annotation.JsonbCreator;
|
||||
import javax.json.bind.annotation.JsonbProperty;
|
||||
|
||||
/**
|
||||
* Extends functionality of {@link SimplePropertyDefinition}
|
||||
* It doesn't allow to change <code>delegate</code> state
|
||||
@@ -461,6 +466,12 @@ public class PropertyDefinitionDecorator extends SimplePropertyDefinition {
|
||||
return Arrays.asList(parametersValue.split(VALUE_SEPARATOR));
|
||||
}
|
||||
|
||||
// TODO: all these trigger specific methods are quit duplicating the same code,
|
||||
// we should try to align it since all trigger use the same kind of API
|
||||
public List<String> getParameters(final String actionType) {
|
||||
return Arrays.asList(delegate.getMetadata().get("action::" + actionType + "::parameters").split(VALUE_SEPARATOR));
|
||||
}
|
||||
|
||||
boolean isCheckable() {
|
||||
return delegate.getMetadata().containsKey(ACTION_HEALTHCHECK);
|
||||
}
|
||||
@@ -585,6 +596,20 @@ public class PropertyDefinitionDecorator extends SimplePropertyDefinition {
|
||||
final List<String> parameters = Arrays.asList(parametersValue.split(VALUE_SEPARATOR));
|
||||
return new Suggestions(name, parameters);
|
||||
}
|
||||
|
||||
public Optional<Updatable> getUpdatable() {
|
||||
final String name = delegate.getMetadata().get(ACTION_UPDATABLE_VALUE);
|
||||
final String parameters = delegate.getMetadata().get(ACTION_UPDATABLE_PARAMETERS);
|
||||
final String after = delegate.getMetadata().get(ACTION_UPDATABLE_AFTER);
|
||||
if (name != null) {
|
||||
return Optional.of(new Updatable(
|
||||
name, parameters != null && !parameters.trim().isEmpty() ?
|
||||
asList(parameters.split(VALUE_SEPARATOR)): emptyList(),
|
||||
after));
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
public Parameter getParameter() {
|
||||
return ofNullable(delegate.getMetadata().get(PARAMETER_INDEX))
|
||||
@@ -665,6 +690,30 @@ public class PropertyDefinitionDecorator extends SimplePropertyDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Updatable {
|
||||
private final String actionName;
|
||||
private final Collection<String> parameters;
|
||||
private final String previousProperty;
|
||||
|
||||
private Updatable(final String actionName, final Collection<String> parameters, final String previousProperty) {
|
||||
this.actionName = actionName;
|
||||
this.parameters = parameters;
|
||||
this.previousProperty = previousProperty;
|
||||
}
|
||||
|
||||
public Collection<String> getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public String getPreviousProperty() {
|
||||
return previousProperty;
|
||||
}
|
||||
|
||||
public String getActionName() {
|
||||
return actionName;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Connection {
|
||||
|
||||
private final Type type;
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -33,7 +34,9 @@ import javax.json.bind.annotation.JsonbCreator;
|
||||
import javax.json.bind.annotation.JsonbProperty;
|
||||
|
||||
public class PropertyNode {
|
||||
|
||||
|
||||
public static final String UPDATE_BUTTON = ".update";
|
||||
|
||||
static final String CONNECTION_BUTTON = ".testConnection";
|
||||
|
||||
static final String VALIDATION = "Validation";
|
||||
@@ -101,9 +104,10 @@ public class PropertyNode {
|
||||
*
|
||||
* @param visitor the property visitor to use to traverse the nodes.
|
||||
*/
|
||||
public void accept(final PropertyVisitor visitor) {
|
||||
public <T extends PropertyVisitor> T accept(final T visitor) {
|
||||
children.forEach(child -> child.accept(visitor));
|
||||
visitor.visit(this);
|
||||
return visitor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -258,7 +262,7 @@ public class PropertyNode {
|
||||
}
|
||||
|
||||
private void createLayout() {
|
||||
Layout layout = null;
|
||||
final Layout layout;
|
||||
if (current.getFieldType() == EParameterFieldType.SCHEMA_TYPE) {
|
||||
layout = new Layout(current.getProperty().getSchemaName());
|
||||
} else {
|
||||
@@ -266,18 +270,21 @@ public class PropertyNode {
|
||||
}
|
||||
if (!current.isLeaf()) {
|
||||
if (current.getProperty().hasGridLayout(form)) {
|
||||
fillGridLayout(layout);
|
||||
fillGridLayout(layout, current.getProperty().getUpdatable());
|
||||
} else {
|
||||
fillSimpleLayout(layout);
|
||||
fillSimpleLayout(layout, current.getProperty().getUpdatable());
|
||||
}
|
||||
if (current.getProperty().isCheckable()) {
|
||||
addButton(layout);
|
||||
addButton(layout, CONNECTION_BUTTON);
|
||||
}
|
||||
if (current.getProperty().getUpdatable().map(v -> v.getPreviousProperty() == null).orElse(false)) {
|
||||
addButton(layout, UPDATE_BUTTON);
|
||||
}
|
||||
}
|
||||
current.addLayout(form, layout);
|
||||
}
|
||||
|
||||
private void fillGridLayout(final Layout layout) {
|
||||
private void fillGridLayout(final Layout layout, final Optional<PropertyDefinitionDecorator.Updatable> updatable) {
|
||||
final String gridLayout = current.getProperty().getGridLayout(form);
|
||||
final String[] rows = gridLayout.split("\\|");
|
||||
// create Level for each row
|
||||
@@ -289,12 +296,15 @@ public class PropertyNode {
|
||||
if (child.getProperty().hasConstraint() || child.getProperty().hasValidation()) {
|
||||
addValidationLevel(child, layout);
|
||||
}
|
||||
if (matches(updatable, column)) {
|
||||
addButton(layout, UPDATE_BUTTON);
|
||||
}
|
||||
level.getColumns().add(child.getLayout(form));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void fillSimpleLayout(final Layout layout) {
|
||||
private void fillSimpleLayout(final Layout layout, final Optional<PropertyDefinitionDecorator.Updatable> updatable) {
|
||||
final List<PropertyNode> children = current.sortChildren(current.getChildren(form), form);
|
||||
children.forEach(child -> {
|
||||
final Level level = new Level();
|
||||
@@ -304,9 +314,16 @@ public class PropertyNode {
|
||||
if (child.getProperty().hasConstraint() || child.getProperty().hasValidation()) {
|
||||
addValidationLevel(child, layout);
|
||||
}
|
||||
if (matches(updatable, child.getProperty().getName())) {
|
||||
addButton(layout, UPDATE_BUTTON);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean matches(final Optional<PropertyDefinitionDecorator.Updatable> updatable, final String name) {
|
||||
return updatable.map(v -> name.equals(v.getPreviousProperty())).orElse(false);
|
||||
}
|
||||
|
||||
private void addValidationLevel(final PropertyNode node, final Layout layout) {
|
||||
final Level level = new Level();
|
||||
Layout validationLayout = new Layout(node.getProperty().getPath() + VALIDATION);
|
||||
@@ -319,8 +336,8 @@ public class PropertyNode {
|
||||
*
|
||||
* @param layout parent node layout
|
||||
*/
|
||||
private void addButton(final Layout layout) {
|
||||
final Layout buttonLayout = new Layout(layout.getPath() + CONNECTION_BUTTON);
|
||||
private void addButton(final Layout layout, final String buttonName) {
|
||||
final Layout buttonLayout = new Layout(layout.getPath() + buttonName);
|
||||
buttonLayout.setHeight(1);
|
||||
final Level level = new Level();
|
||||
level.getColumns().add(buttonLayout);
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.talend.sdk.component.studio.Lookups;
|
||||
import org.talend.sdk.component.studio.i18n.Messages;
|
||||
import org.talend.sdk.component.studio.model.action.Action;
|
||||
import org.talend.sdk.component.studio.model.action.SuggestionsAction;
|
||||
import org.talend.sdk.component.studio.model.action.UpdateAction;
|
||||
import org.talend.sdk.component.studio.model.parameter.condition.ConditionGroup;
|
||||
import org.talend.sdk.component.studio.model.parameter.listener.ActiveIfListener;
|
||||
import org.talend.sdk.component.studio.model.parameter.listener.ValidationListener;
|
||||
@@ -40,6 +41,7 @@ import org.talend.sdk.component.studio.model.parameter.listener.ValidatorFactory
|
||||
import org.talend.sdk.component.studio.model.parameter.resolver.HealthCheckResolver;
|
||||
import org.talend.sdk.component.studio.model.parameter.resolver.ParameterResolver;
|
||||
import org.talend.sdk.component.studio.model.parameter.resolver.SuggestionsResolver;
|
||||
import org.talend.sdk.component.studio.model.parameter.resolver.UpdateResolver;
|
||||
import org.talend.sdk.component.studio.model.parameter.resolver.ValidationResolver;
|
||||
import org.talend.sdk.component.studio.util.TaCoKitConst;
|
||||
import org.talend.sdk.component.studio.util.TaCoKitUtil;
|
||||
@@ -157,6 +159,7 @@ public class SettingVisitor implements PropertyVisitor {
|
||||
}
|
||||
|
||||
buildActivationCondition(node.getParent(), origin);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -502,17 +505,25 @@ public class SettingVisitor implements PropertyVisitor {
|
||||
defaultValue = node.getProperty().getMetadata().get("ui::defaultvalue::value");
|
||||
}
|
||||
|
||||
parameter.setRequired(node.getProperty().isRequired());
|
||||
if (TaCoKitElementParameter.class.isInstance(parameter)) {
|
||||
TaCoKitElementParameter.class.cast(parameter).updateValueOnly(defaultValue);
|
||||
final TaCoKitElementParameter taCoKitElementParameter = TaCoKitElementParameter.class.cast(parameter);
|
||||
taCoKitElementParameter.updateValueOnly(defaultValue);
|
||||
if (node.getProperty().hasConstraint() || node.getProperty().hasValidation()) {
|
||||
createValidationLabel(node, taCoKitElementParameter);
|
||||
}
|
||||
buildActivationCondition(node, node);
|
||||
buildUpdateListener(node, );
|
||||
} else {
|
||||
parameter.setValue(defaultValue);
|
||||
}
|
||||
parameter.setRequired(node.getProperty().isRequired());
|
||||
if (node.getProperty().hasConstraint() || node.getProperty().hasValidation()) {
|
||||
createValidationLabel(node, (TaCoKitElementParameter) parameter);
|
||||
}
|
||||
}
|
||||
|
||||
buildActivationCondition(node, node);
|
||||
private void buildUpdateListener(final PropertyNode node, final Layout layout) {
|
||||
node.getProperty().getUpdatable().ifPresent(updatable -> new UpdateResolver(
|
||||
element, category, layout.getChildLayout(layout.getPath() + PropertyNode.UPDATE_BUTTON).getPosition(),
|
||||
new UpdateAction(updatable.getActionName(), family, Action.Type.UPDATE), node, actions)
|
||||
.resolveParameters(settings));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,44 +15,30 @@
|
||||
*/
|
||||
package org.talend.sdk.component.studio.model.parameter.command;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import static org.talend.sdk.component.studio.model.action.Action.MESSAGE;
|
||||
import static org.talend.sdk.component.studio.model.action.Action.OK;
|
||||
import static org.talend.sdk.component.studio.model.action.Action.STATUS;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.talend.commons.ui.gmf.util.DisplayUtils;
|
||||
import org.talend.sdk.component.studio.i18n.Messages;
|
||||
import org.talend.sdk.component.studio.model.action.Action;
|
||||
import org.talend.sdk.component.studio.model.action.IActionParameter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.talend.sdk.component.studio.model.action.Action.MESSAGE;
|
||||
import static org.talend.sdk.component.studio.model.action.Action.OK;
|
||||
import static org.talend.sdk.component.studio.model.action.Action.STATUS;
|
||||
|
||||
/**
|
||||
* Asynchronous Action
|
||||
*/
|
||||
public class AsyncAction extends Job implements TacokitCommand {
|
||||
public class AsyncAction extends BaseAsyncAction<String> {
|
||||
|
||||
private final Action action;
|
||||
|
||||
public AsyncAction(final Action action) {
|
||||
super(Messages.getString("action.execution.progress"));
|
||||
this.action = action;
|
||||
setUser(true);
|
||||
public AsyncAction(final Action<String> action) {
|
||||
super(action);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected IStatus run(final IProgressMonitor iProgressMonitor) {
|
||||
final Map<String, String> result = action.callback();
|
||||
refreshUi(result);
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
private void refreshUi(final Map<String, String> result) {
|
||||
protected void onResult(final Map<String, String> result) {
|
||||
Display.getDefault().asyncExec(() -> {
|
||||
final String dialogTitle = Messages.getString("action.result.title");
|
||||
if (OK.equals(result.get(STATUS))) {
|
||||
@@ -61,16 +47,5 @@ public class AsyncAction extends Job implements TacokitCommand {
|
||||
MessageDialog.openError(DisplayUtils.getDefaultShell(), dialogTitle, result.get(MESSAGE));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exec() {
|
||||
this.schedule();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addParameter(final IActionParameter parameter) {
|
||||
action.addParameter(parameter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Copyright (C) 2006-2018 Talend Inc. - www.talend.com
|
||||
*
|
||||
* 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 org.talend.sdk.component.studio.model.parameter.command;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.talend.sdk.component.studio.i18n.Messages;
|
||||
import org.talend.sdk.component.studio.model.action.Action;
|
||||
import org.talend.sdk.component.studio.model.action.IActionParameter;
|
||||
|
||||
/**
|
||||
* Asynchronous Action
|
||||
*/
|
||||
public abstract class BaseAsyncAction<T> extends Job implements TacokitCommand {
|
||||
|
||||
private final Action<T> action;
|
||||
|
||||
public BaseAsyncAction(final Action<T> action) {
|
||||
super(Messages.getString("action.execution.progress"));
|
||||
this.action = action;
|
||||
setUser(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IStatus run(final IProgressMonitor iProgressMonitor) {
|
||||
onResult(action.callback());
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
protected abstract void onResult(Map<String, T> result);
|
||||
|
||||
@Override
|
||||
public void exec() {
|
||||
this.schedule();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addParameter(final IActionParameter parameter) {
|
||||
action.addParameter(parameter);
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import java.beans.PropertyChangeListener;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class ValidationListener extends Action implements PropertyChangeListener {
|
||||
public class ValidationListener extends Action<String> implements PropertyChangeListener {
|
||||
|
||||
private final ValidationLabel label;
|
||||
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
package org.talend.sdk.component.studio.model.parameter.resolver;
|
||||
|
||||
import static java.util.Comparator.comparing;
|
||||
import static java.util.Locale.ROOT;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.talend.core.model.process.IElementParameter;
|
||||
import org.talend.designer.core.model.components.ElementParameter;
|
||||
import org.talend.sdk.component.server.front.model.ActionReference;
|
||||
@@ -10,14 +20,6 @@ import org.talend.sdk.component.studio.model.parameter.PropertyDefinitionDecorat
|
||||
import org.talend.sdk.component.studio.model.parameter.PropertyNode;
|
||||
import org.talend.sdk.component.studio.model.parameter.TaCoKitElementParameter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Comparator.comparing;
|
||||
|
||||
/**
|
||||
* Common super class for ParameterResolvers. It contains common state and functionality
|
||||
*/
|
||||
@@ -47,6 +49,15 @@ abstract class AbstractParameterResolver implements ParameterResolver {
|
||||
this.redrawParameter = redrawParameter;
|
||||
}
|
||||
|
||||
protected static ActionReference getActionRef(final Collection<ActionReference> actions, final String name, final Action.Type type) {
|
||||
return actions
|
||||
.stream()
|
||||
.filter(a -> type.toString().equals(a.getType()))
|
||||
.filter(a -> a.getName().equals(name))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new IllegalArgumentException("Action with name " + name + " wasn't found"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds ElementParameters needed for action call by their relative path.
|
||||
* Registers PropertyChangeListener to each ElementParameter needed for action call
|
||||
@@ -65,9 +76,8 @@ abstract class AbstractParameterResolver implements ParameterResolver {
|
||||
relativePaths.forEach(relativePath -> {
|
||||
if (expectedParameters.hasNext()) {
|
||||
final String absolutePath = pathResolver.resolvePath(getOwnerPath(), relativePath);
|
||||
final List<TaCoKitElementParameter> parameters = findParameters(absolutePath, settings);
|
||||
final SimplePropertyDefinition parameterRoot = expectedParameters.next();
|
||||
parameters.forEach(parameter -> {
|
||||
findParameters(absolutePath, settings).forEach(parameter -> {
|
||||
if (redrawParameter != null) {
|
||||
parameter.setRedrawParameter(redrawParameter);
|
||||
}
|
||||
@@ -79,7 +89,9 @@ abstract class AbstractParameterResolver implements ParameterResolver {
|
||||
});
|
||||
}
|
||||
|
||||
protected abstract List<String> getRelativePaths();
|
||||
protected final List<String> getRelativePaths() {
|
||||
return actionOwner.getProperty().getParameters(actionRef.getType().toLowerCase(ROOT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and returns all child ElementParameters of node with {@code absolutePath}. {@code absolutePath} may point at "leaf" Configuration option and
|
||||
|
||||
@@ -98,5 +98,4 @@ public class HealthCheckResolver {
|
||||
final PropertyNode root = new PropertyTreeCreator(new WidgetTypeMapper()).createPropertyTree(properties);
|
||||
return root.getProperty().getPath();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,33 +15,16 @@
|
||||
*/
|
||||
package org.talend.sdk.component.studio.model.parameter.resolver;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.talend.sdk.component.server.front.model.ActionReference;
|
||||
import org.talend.sdk.component.studio.model.action.Action;
|
||||
import org.talend.sdk.component.studio.model.action.SuggestionsAction;
|
||||
import org.talend.sdk.component.studio.model.parameter.PropertyNode;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class SuggestionsResolver extends AbstractParameterResolver {
|
||||
|
||||
public SuggestionsResolver(final SuggestionsAction action, final PropertyNode actionOwner, final Collection<ActionReference> actions) {
|
||||
super(action, actionOwner, getActionRef(actionOwner, actions));
|
||||
super(action, actionOwner, getActionRef(actions, actionOwner.getProperty().getSuggestions().getName(), Action.Type.SUGGESTIONS));
|
||||
}
|
||||
|
||||
private static ActionReference getActionRef(final PropertyNode actionOwner, final Collection<ActionReference> actions) {
|
||||
final String actionName = actionOwner.getProperty().getSuggestions().getName();
|
||||
return actions
|
||||
.stream()
|
||||
.filter(a -> Action.Type.SUGGESTIONS.toString().equals(a.getType()))
|
||||
.filter(a -> a.getName().equals(actionName))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new IllegalArgumentException("Action with name " + actionName + " wasn't found"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final List<String> getRelativePaths() {
|
||||
return actionOwner.getProperty().getSuggestions().getParameters();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Copyright (C) 2006-2018 Talend Inc. - www.talend.com
|
||||
*
|
||||
* 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 org.talend.sdk.component.studio.model.parameter.resolver;
|
||||
|
||||
import static java.util.Locale.ROOT;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.talend.core.model.process.EComponentCategory;
|
||||
import org.talend.core.model.process.IElement;
|
||||
import org.talend.core.model.process.IElementParameter;
|
||||
import org.talend.sdk.component.server.front.model.ActionReference;
|
||||
import org.talend.sdk.component.studio.model.action.Action;
|
||||
import org.talend.sdk.component.studio.model.action.SettingsActionParameter;
|
||||
import org.talend.sdk.component.studio.model.action.UpdateAction;
|
||||
import org.talend.sdk.component.studio.model.parameter.ButtonParameter;
|
||||
import org.talend.sdk.component.studio.model.parameter.PathCollector;
|
||||
import org.talend.sdk.component.studio.model.parameter.PropertyNode;
|
||||
import org.talend.sdk.component.studio.model.parameter.TaCoKitElementParameter;
|
||||
import org.talend.sdk.component.studio.model.parameter.command.AsyncAction;
|
||||
import org.talend.sdk.component.studio.model.parameter.command.BaseAsyncAction;
|
||||
|
||||
public class UpdateResolver extends AbstractParameterResolver {
|
||||
|
||||
private final IElement element;
|
||||
|
||||
private final EComponentCategory category;
|
||||
|
||||
private final int rowNumber;
|
||||
|
||||
public UpdateResolver(final IElement element, final EComponentCategory category, final int rowNumber,
|
||||
final UpdateAction action, final PropertyNode actionOwner, final Collection<ActionReference> actions) {
|
||||
super(action, actionOwner,
|
||||
getActionRef(actions,
|
||||
actionOwner.getProperty().getUpdatable().orElseThrow(IllegalStateException::new).getActionName(),
|
||||
Action.Type.UPDATE));
|
||||
this.element = element;
|
||||
this.category = category;
|
||||
this.rowNumber = rowNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveParameters(final Map<String, IElementParameter> settings) {
|
||||
super.resolveParameters(settings);
|
||||
|
||||
final ButtonParameter button = new ButtonParameter(element);
|
||||
button.setCategory(category);
|
||||
button.setDisplayName(actionRef.getDisplayName());
|
||||
button.setName(actionOwner.getProperty().getPath() + PropertyNode.UPDATE_BUTTON);
|
||||
button.setNumRow(rowNumber);
|
||||
button.setShow(true);
|
||||
button.setCommand(new BaseAsyncAction<Object>(new Action<>(actionRef.getName(), actionRef.getFamily(),
|
||||
Action.Type.valueOf(actionRef.getType().toUpperCase(ROOT)))) {
|
||||
|
||||
@Override
|
||||
protected void onResult(final Map<String, Object> result) {
|
||||
actionOwner.accept(new PathCollector()).getPaths().stream()
|
||||
.map(settings::get).filter(Objects::nonNull)
|
||||
.map(TaCoKitElementParameter.class::cast)
|
||||
.forEach(elt -> {
|
||||
// todo: update each element recursively since an object can contain an object
|
||||
});
|
||||
}
|
||||
});
|
||||
settings.put(button.getName(), button);
|
||||
}
|
||||
}
|
||||
@@ -15,36 +15,18 @@
|
||||
*/
|
||||
package org.talend.sdk.component.studio.model.parameter.resolver;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.talend.designer.core.model.components.ElementParameter;
|
||||
import org.talend.sdk.component.server.front.model.ActionReference;
|
||||
import org.talend.sdk.component.studio.model.action.Action;
|
||||
import org.talend.sdk.component.studio.model.parameter.PropertyNode;
|
||||
import org.talend.sdk.component.studio.model.parameter.listener.ValidationListener;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class ValidationResolver extends AbstractParameterResolver {
|
||||
|
||||
public ValidationResolver(final PropertyNode actionOwner, final Collection<ActionReference> actions,
|
||||
final ValidationListener listener, final ElementParameter redrawParameter) {
|
||||
super(listener, actionOwner, getActionRef(actionOwner, actions), redrawParameter);
|
||||
}
|
||||
|
||||
private static ActionReference getActionRef(final PropertyNode actionOwner, final Collection<ActionReference> actions) {
|
||||
if (!actionOwner.getProperty().hasValidation()) {
|
||||
throw new IllegalArgumentException("property has no validation");
|
||||
}
|
||||
final String actionName = actionOwner.getProperty().getValidationName();
|
||||
return actions
|
||||
.stream()
|
||||
.filter(a -> Action.Type.VALIDATION.toString().equals(a.getType()))
|
||||
.filter(a -> a.getName().equals(actionName))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new IllegalArgumentException("Action with name " + actionName + " wasn't found"));
|
||||
}
|
||||
|
||||
protected final List<String> getRelativePaths() {
|
||||
return actionOwner.getProperty().getValidationParameters();
|
||||
super(listener, actionOwner, getActionRef(actions, actionOwner.getProperty().getValidationName(), Action.Type.VALIDATION), redrawParameter);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user