Skip to content

Commit

Permalink
UI-CONTROLLER
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Dec 11, 2013
1 parent ad778ad commit d7cea86
Show file tree
Hide file tree
Showing 8 changed files with 388 additions and 0 deletions.
@@ -0,0 +1,62 @@
/**
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.addon.ui.controller;

import java.util.List;

import org.jboss.forge.addon.ui.UICommand;
import org.jboss.forge.addon.ui.result.Result;

/**
* A Controller for a specific {@link UICommand}
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
public interface CommandController
{
/**
* Returns the initial {@link UICommand}
*/
public UICommand getInitialCommand();

/**
* Launch the currrent wizard execution
*
* @throws Exception
*/
public void launch() throws Exception;

/**
* Is the wizard allowed to finish?
*/
public boolean canFinish();

/**
* Lets the controller know that some value in the Wizard was modified, so it should invalidate subsequent pages.
*/
public void valueChanged();

/**
* Finish clicked
*
* @throws Exception if anything wrong happens
*/
public Result finish() throws Exception;

/**
* Is the current wizard page valid ?
*
* @return true if valid, false otherwise
*/
public boolean isValid();

/**
* The validation errors for the current page
*/
public List<String> getErrorMessages();
}
@@ -0,0 +1,30 @@
/**
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.addon.ui.controller;

import org.jboss.forge.addon.ui.UICommand;
import org.jboss.forge.addon.ui.spi.UIContextFactory;
import org.jboss.forge.addon.ui.wizard.UIWizard;

/**
* Creates {@link CommandController} objects
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
public interface CommandControllerFactory
{
/**
* Create a {@link SingleCommandController}. Should be called when a single command execution must be performed.
*/
CommandController createSingleController(Class<? extends UICommand> command, UIContextFactory uiFactory);

/**
* Create a {@link WizardCommandController}. Should be called when a wizard (multisteps) execution must be performed.
*/
WizardCommandController createWizardController(Class<? extends UIWizard> wizard, UIContextFactory uiFactory);
}
@@ -0,0 +1,43 @@
/**
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.addon.ui.controller;

import org.jboss.forge.addon.ui.UICommand;

/**
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
public interface WizardCommandController extends CommandController
{
/**
* Returns the current {@link UICommand} based on the navigation
*/
public UICommand getCurrentCommand();

/**
* Is it possible to navigate to the next page ?
*/
public boolean canFlipToNextPage();

/**
* Is it possible to navigate to the previous page ?
*
*/
public boolean canFlipToPreviousPage();

/**
* Navigate to the next page. Throws {@link IllegalStateException} if navigation is not possible
*/
public UICommand next() throws IllegalStateException;

/**
* Navigate to the previous visited page
*/
public UICommand previous() throws IllegalStateException;
}
@@ -0,0 +1,41 @@
/**
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.addon.ui.spi;

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.UIValidationContext;

/**
* Creates UI objects. Should be implemented by UI Providers
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
public interface UIContextFactory
{
/**
* Creates the {@link UIContext} used
*/
UIContext createUIContext();

/**
* Creates a {@link UIBuilder} when needed
*/
UIBuilder createUIBuilder(UIContext context);

/**
* Creates a new {@link UIValidationContext}
*/
UIValidationContext createUIValidationContext(UIContext context);

/**
* Creates a new {@link UIExecutionContext}
*/
UIExecutionContext createUIExecutionContext(UIContext context);
}
@@ -0,0 +1,34 @@
/**
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.addon.ui.impl.controller;

import org.jboss.forge.addon.ui.UICommand;
import org.jboss.forge.addon.ui.controller.CommandController;
import org.jboss.forge.furnace.addons.AddonRegistry;

/**
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
public abstract class AbstractCommandController implements CommandController
{
protected final AddonRegistry addonRegistry;
private final UICommand initialCommand;

protected AbstractCommandController(AddonRegistry addonRegistry, UICommand initialCommand)
{
this.addonRegistry = addonRegistry;
this.initialCommand = initialCommand;
}

@Override
public UICommand getInitialCommand()
{
return this.initialCommand;
}
}
@@ -0,0 +1,68 @@
/**
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.addon.ui.impl.controller;

import javax.inject.Inject;
import javax.inject.Singleton;

import org.jboss.forge.addon.ui.UICommand;
import org.jboss.forge.addon.ui.context.UIContext;
import org.jboss.forge.addon.ui.controller.CommandController;
import org.jboss.forge.addon.ui.controller.CommandControllerFactory;
import org.jboss.forge.addon.ui.controller.WizardCommandController;
import org.jboss.forge.addon.ui.spi.UIContextFactory;
import org.jboss.forge.addon.ui.wizard.UIWizard;
import org.jboss.forge.addon.ui.wizard.UIWizardStep;
import org.jboss.forge.furnace.addons.AddonRegistry;

/**
* Creates {@link CommandController} objects
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
@Singleton
public class CommandControllerFactoryImpl implements CommandControllerFactory
{
private final AddonRegistry addonRegistry;

@Inject
public CommandControllerFactoryImpl(AddonRegistry addonRegistry)
{
this.addonRegistry = addonRegistry;
}

@Override
public CommandController createSingleController(Class<? extends UICommand> command, UIContextFactory uiFactory)
{
return null;
}

@Override
public WizardCommandController createWizardController(Class<? extends UIWizard> wizard, UIContextFactory uiFactory)
{
return null;
}

public CommandController create(Class<? extends UICommand> command, UIContext context)
{
if (UIWizardStep.class.isAssignableFrom(command))
{
throw new IllegalArgumentException("Class " + command.getName()
+ " implements UIWizardStep, and it's not possible to start from a step");
}
else if (UIWizard.class.isAssignableFrom(command))
{
return null;
}
else if (UICommand.class.isAssignableFrom(command))
{
// return new SingleCommandController(addonRegistry, addonRegistry.getServices(command).get());
}
throw new IllegalArgumentException(command + " is not a valid UICommand");
}
}
@@ -0,0 +1,25 @@
/**
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.addon.ui.impl.controller;

import org.jboss.forge.addon.ui.UICommand;
import org.jboss.forge.furnace.addons.AddonRegistry;

/**
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
abstract class SingleCommandController extends AbstractCommandController
{

public SingleCommandController(AddonRegistry addonRegistry, UICommand initialCommand)
{
super(addonRegistry, initialCommand);
}

}
@@ -0,0 +1,85 @@
/**
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.addon.ui.impl.controller;

import org.jboss.forge.addon.ui.UICommand;
import org.jboss.forge.addon.ui.controller.WizardCommandController;
import org.jboss.forge.addon.ui.wizard.UIWizard;
import org.jboss.forge.furnace.addons.AddonRegistry;

/**
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
abstract class WizardCommandControllerImpl extends AbstractCommandController implements WizardCommandController
{

public WizardCommandControllerImpl(AddonRegistry addonRegistry, UIWizard initialCommand)
{
super(addonRegistry, initialCommand);
}

@Override
public UIWizard getInitialCommand()
{
return (UIWizard) super.getInitialCommand();
}

@Override
public UICommand getCurrentCommand()
{
return null;
}

@Override
public void launch() throws Exception
{

}

@Override
public boolean canFlipToNextPage()
{
// TODO Auto-generated method stub
return false;
}

@Override
public boolean canFlipToPreviousPage()
{
// TODO Auto-generated method stub
return false;
}

@Override
public boolean canFinish()
{
// TODO Auto-generated method stub
return false;
}

@Override
public UICommand next() throws IllegalStateException
{
return null;
}

@Override
public UICommand previous() throws IllegalStateException
{
return null;
}

@Override
public void valueChanged()
{
// TODO Auto-generated method stub

}

}

0 comments on commit d7cea86

Please sign in to comment.