io.fabric8.forge.camel.commands.project.CamelAddEndpointXmlCommand Maven / Gradle / Ivy
/**
* Copyright 2005-2015 Red Hat, Inc.
*
* Red Hat licenses this file to you 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 io.fabric8.forge.camel.commands.project;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import io.fabric8.forge.camel.commands.project.dto.ComponentDto;
import io.fabric8.forge.camel.commands.project.dto.NodeDto;
import io.fabric8.forge.camel.commands.project.helper.PoorMansLogger;
import io.fabric8.forge.camel.commands.project.model.InputOptionByGroup;
import org.jboss.forge.addon.projects.Project;
import org.jboss.forge.addon.projects.dependencies.DependencyInstaller;
import org.jboss.forge.addon.ui.context.UIBuilder;
import org.jboss.forge.addon.ui.context.UIContext;
import org.jboss.forge.addon.ui.context.UIExecutionContext;
import org.jboss.forge.addon.ui.context.UINavigationContext;
import org.jboss.forge.addon.ui.input.InputComponent;
import org.jboss.forge.addon.ui.input.InputComponentFactory;
import org.jboss.forge.addon.ui.input.UISelectOne;
import org.jboss.forge.addon.ui.metadata.UICommandMetadata;
import org.jboss.forge.addon.ui.metadata.WithAttributes;
import org.jboss.forge.addon.ui.result.NavigationResult;
import org.jboss.forge.addon.ui.result.Result;
import org.jboss.forge.addon.ui.result.Results;
import org.jboss.forge.addon.ui.result.navigation.NavigationResultBuilder;
import org.jboss.forge.addon.ui.util.Categories;
import org.jboss.forge.addon.ui.util.Metadata;
import org.jboss.forge.addon.ui.wizard.UIWizard;
import static io.fabric8.forge.camel.commands.project.helper.CamelCommandsHelper.createUIInputsForCamelEndpoint;
/**
* Adds a from/to endpoint into chosen node in the route
*/
public class CamelAddEndpointXmlCommand extends AbstractCamelProjectCommand implements UIWizard {
private static final PoorMansLogger LOG = new PoorMansLogger(false);
@Inject
@WithAttributes(label = "XML File", required = true, description = "The XML file to use (either Spring or Blueprint)")
private UISelectOne xml;
@Inject
@WithAttributes(label = "Node", required = true, description = "Parent node (where to add the endpoint)")
private UISelectOne node;
private transient List nodes;
@Inject
@WithAttributes(label = "Name", required = true, description = "Name of component to use for the endpoint")
private UISelectOne componentName;
@Inject
private InputComponentFactory componentFactory;
@Inject
private DependencyInstaller dependencyInstaller;
@Override
public UICommandMetadata getMetadata(UIContext context) {
return Metadata.forCommand(CamelAddEndpointXmlCommand.class).name(
"Camel: Add Endpoint XML").category(Categories.create(CATEGORY))
.description("Adds an Endpoint to an existing route in an XML file");
}
@Override
public boolean isEnabled(UIContext context) {
boolean enabled = super.isEnabled(context);
if (enabled) {
// we should only be enabled in non gui
boolean gui = isRunningInGui(context);
enabled = !gui;
}
if (enabled) {
// must have xml files with camel routes to be enabled
Project project = getSelectedProject(context);
String currentFile = getSelectedFile(context);
String selected = configureXml(project, xml, currentFile);
return selected != null;
}
return false;
}
@Override
public void initializeUI(UIBuilder builder) throws Exception {
UIContext context = builder.getUIContext();
Map © 2015 - 2025 Weber Informatics LLC | Privacy Policy