All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.officefloor.eclipse.section.ExternalManagedObjectItem Maven / Gradle / Ivy

/*
 * OfficeFloor - http://www.officefloor.net
 * Copyright (C) 2005-2018 Daniel Sagenschneider
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see .
 */
package net.officefloor.eclipse.section;

import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import net.officefloor.eclipse.configurer.ValueValidator;
import net.officefloor.eclipse.editor.AdaptedModelVisualFactoryContext;
import net.officefloor.eclipse.editor.DefaultConnectors;
import net.officefloor.eclipse.ide.editor.AbstractConfigurableItem;
import net.officefloor.model.section.ExternalManagedObjectModel;
import net.officefloor.model.section.ExternalManagedObjectModel.ExternalManagedObjectEvent;
import net.officefloor.model.section.ManagedFunctionObjectToExternalManagedObjectModel;
import net.officefloor.model.section.SectionChanges;
import net.officefloor.model.section.SectionManagedObjectDependencyToExternalManagedObjectModel;
import net.officefloor.model.section.SectionModel;
import net.officefloor.model.section.SectionModel.SectionEvent;

/**
 * Configuration for {@link ExternalManagedObjectModel}.
 * 
 * @author Daniel Sagenschneider
 */
public class ExternalManagedObjectItem extends
		AbstractConfigurableItem {

	/**
	 * Test configuration.
	 * 
	 * @param args
	 *            Command line arguments.
	 */
	public static void main(String[] args) {
		SectionEditor.launchConfigurer(new ExternalManagedObjectItem(), (object) -> {
			object.setObjectType(String.class.getName());
		});
	}

	/**
	 * Name.
	 */
	private String name;

	/**
	 * Argument type.
	 */
	private String argumentType;

	/*
	 * ================= AbstractParentConfigurableItem ============
	 */

	@Override
	public ExternalManagedObjectModel prototype() {
		return new ExternalManagedObjectModel("External Object", null);
	}

	@Override
	public IdeExtractor extract() {
		return new IdeExtractor((parent) -> parent.getExternalManagedObjects(),
				SectionEvent.ADD_EXTERNAL_MANAGED_OBJECT, SectionEvent.REMOVE_EXTERNAL_MANAGED_OBJECT);
	}

	@Override
	public void loadToParent(SectionModel parentModel, ExternalManagedObjectModel itemModel) {
		parentModel.addExternalManagedObject(itemModel);
	}

	@Override
	public Pane visual(ExternalManagedObjectModel model,
			AdaptedModelVisualFactoryContext context) {
		HBox container = new HBox();
		context.addNode(container,
				context.connector(DefaultConnectors.OBJECT,
						SectionManagedObjectDependencyToExternalManagedObjectModel.class,
						ManagedFunctionObjectToExternalManagedObjectModel.class).getNode());
		context.label(container);
		return container;
	}

	@Override
	public IdeLabeller label() {
		return new IdeLabeller((model) -> model.getExternalManagedObjectName(),
				ExternalManagedObjectEvent.CHANGE_EXTERNAL_MANAGED_OBJECT_NAME);
	}

	@Override
	public String style() {
		return new IdeStyle().rule("-fx-background-color", "yellowgreen").toString();
	}

	@Override
	protected ExternalManagedObjectItem item(ExternalManagedObjectModel model) {
		ExternalManagedObjectItem item = new ExternalManagedObjectItem();
		if (model != null) {
			item.name = model.getExternalManagedObjectName();
			item.argumentType = model.getObjectType();
		}
		return item;
	}

	@Override
	public IdeConfigurer configure() {
		return new IdeConfigurer().addAndRefactor((builder, context) -> {
			builder.title("External Object");
			builder.text("Name").init((model) -> model.name).setValue((model, value) -> model.name = value)
					.validate(ValueValidator.notEmptyString("Must specify name"));
			builder.clazz("Argument").init((model) -> model.argumentType)
					.setValue((model, value) -> model.argumentType = value);
		}).add((builder, context) -> {
			builder.apply("Add", (item) -> context
					.execute(context.getOperations().addExternalManagedObject(item.name, item.argumentType)));
		}).refactor((builder, context) -> {
			builder.apply("Refactor", (item) -> {
				// TODO implement refactor of external object
				throw new UnsupportedOperationException(
						"TODO renameExternalManagedObject to be refactorExternalManagedObject");
			});
		}).delete((context) -> {
			context.execute(context.getOperations().removeExternalManagedObject(context.getModel()));
		});
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy