-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FORGE-2055: mocking UIProvider.isGUI for command names
- Loading branch information
Showing
7 changed files
with
359 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
ui/impl/src/main/java/org/jboss/forge/addon/ui/impl/context/DelegatingUIContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* Copyright 2014 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.context; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.jboss.forge.addon.ui.UIProvider; | ||
import org.jboss.forge.addon.ui.command.CommandExecutionListener; | ||
import org.jboss.forge.addon.ui.context.UIContext; | ||
import org.jboss.forge.addon.ui.context.UISelection; | ||
import org.jboss.forge.furnace.spi.ListenerRegistration; | ||
|
||
/** | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
public class DelegatingUIContext implements UIContext | ||
{ | ||
private final UIContext context; | ||
private final UIProvider provider; | ||
|
||
public DelegatingUIContext(UIContext context, UIProvider provider) | ||
{ | ||
super(); | ||
this.context = context; | ||
this.provider = provider; | ||
} | ||
|
||
@Override | ||
public void close() throws Exception | ||
{ | ||
context.close(); | ||
} | ||
|
||
@Override | ||
public Map<Object, Object> getAttributeMap() | ||
{ | ||
return context.getAttributeMap(); | ||
} | ||
|
||
@Override | ||
public <SELECTIONTYPE> UISelection<SELECTIONTYPE> getInitialSelection() | ||
{ | ||
return context.getInitialSelection(); | ||
} | ||
|
||
@Override | ||
public <SELECTIONTYPE> void setSelection(SELECTIONTYPE resource) | ||
{ | ||
context.setSelection(resource); | ||
} | ||
|
||
@Override | ||
public <SELECTIONTYPE> void setSelection(UISelection<SELECTIONTYPE> selection) | ||
{ | ||
context.setSelection(selection); | ||
} | ||
|
||
@Override | ||
public <SELECTIONTYPE> UISelection<SELECTIONTYPE> getSelection() | ||
{ | ||
return context.getSelection(); | ||
} | ||
|
||
@Override | ||
public UIProvider getProvider() | ||
{ | ||
return provider == null ? context.getProvider() : provider; | ||
} | ||
|
||
@Override | ||
public ListenerRegistration<CommandExecutionListener> addCommandExecutionListener(CommandExecutionListener listener) | ||
{ | ||
return context.addCommandExecutionListener(listener); | ||
} | ||
|
||
@Override | ||
public Set<CommandExecutionListener> getListeners() | ||
{ | ||
return context.getListeners(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
ui/tests/src/test/java/org/jboss/forge/addon/ui/controller/mock/DifferentNameCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* 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.mock; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.forge.addon.ui.command.UICommand; | ||
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; | ||
import org.jboss.forge.addon.ui.input.UIInput; | ||
import org.jboss.forge.addon.ui.metadata.UICommandMetadata; | ||
import org.jboss.forge.addon.ui.result.Result; | ||
import org.jboss.forge.addon.ui.result.Results; | ||
import org.jboss.forge.addon.ui.util.Categories; | ||
import org.jboss.forge.addon.ui.util.Metadata; | ||
|
||
public class DifferentNameCommand implements UICommand | ||
{ | ||
@Inject | ||
private UIInput<String> firstName; | ||
|
||
@Override | ||
public void initializeUI(UIBuilder builder) throws Exception | ||
{ | ||
firstName.setRequired(true); | ||
builder.add(firstName); | ||
} | ||
|
||
@Override | ||
public void validate(UIValidationContext context) | ||
{ | ||
} | ||
|
||
@Override | ||
public Result execute(UIExecutionContext context) throws Exception | ||
{ | ||
return Results.success("Hello, " + firstName.getValue()); | ||
} | ||
|
||
@Override | ||
public UICommandMetadata getMetadata(UIContext context) | ||
{ | ||
return Metadata.forCommand(DifferentNameCommand.class).description("generic test command") | ||
.name(context.getProvider().isGUI() ? "a-gui-command" : "a-shell-command") | ||
.category(Categories.create("Example")); | ||
} | ||
|
||
@Override | ||
public boolean isEnabled(UIContext context) | ||
{ | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.