Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #392 from gastaldi/features/FORGE-1465
FORGE-1465: Introduced org.jboss.forge.addon.ui.result.navigation package
- Loading branch information
Showing
21 changed files
with
966 additions
and
57 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
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
84 changes: 84 additions & 0 deletions
84
ui/api/src/main/java/org/jboss/forge/addon/ui/result/CompositeResultImpl.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,84 @@ | ||
/** | ||
* 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.result; | ||
|
||
import java.util.List; | ||
|
||
import org.jboss.forge.furnace.util.Assert; | ||
|
||
/** | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
abstract class CompositeResultImpl implements CompositeResult | ||
{ | ||
private final List<Result> results; | ||
|
||
public CompositeResultImpl(List<Result> results) | ||
{ | ||
Assert.notNull(results, "Result list cannot be null"); | ||
this.results = results; | ||
} | ||
|
||
@Override | ||
public List<Result> getResults() | ||
{ | ||
return results; | ||
} | ||
|
||
@Override | ||
public String getMessage() | ||
{ | ||
throw new UnsupportedOperationException( | ||
"getMessage() should not be called in a CompositeResult. Call getResults() instead."); | ||
} | ||
|
||
public static CompositeResult from(List<Result> results) | ||
{ | ||
boolean failed = false; | ||
Throwable throwable = null; | ||
for (Result result : results) | ||
{ | ||
if (result instanceof Failed) | ||
{ | ||
failed = true; | ||
throwable = ((Failed) result).getException(); | ||
break; | ||
} | ||
} | ||
|
||
if (failed) | ||
return new CompositeResultFailed(results, throwable); | ||
return new CompositeResultSuccess(results); | ||
} | ||
|
||
private static class CompositeResultFailed extends CompositeResultImpl implements Result, Failed | ||
{ | ||
private final Throwable exception; | ||
|
||
public CompositeResultFailed(List<Result> results, Throwable e) | ||
{ | ||
super(results); | ||
this.exception = e; | ||
} | ||
|
||
@Override | ||
public Throwable getException() | ||
{ | ||
return exception; | ||
} | ||
} | ||
|
||
private static class CompositeResultSuccess extends CompositeResultImpl implements Result | ||
{ | ||
public CompositeResultSuccess(List<Result> results) | ||
{ | ||
super(results); | ||
} | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
ui/api/src/main/java/org/jboss/forge/addon/ui/result/NavigationResultEntry.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,32 @@ | ||
/** | ||
* 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.result; | ||
|
||
import org.jboss.forge.addon.ui.command.UICommand; | ||
import org.jboss.forge.addon.ui.context.UIContext; | ||
import org.jboss.forge.addon.ui.controller.CommandController; | ||
import org.jboss.forge.furnace.addons.AddonRegistry; | ||
|
||
/** | ||
* Encapsulates the {@link UICommand} creation. | ||
* | ||
* This interface should only be used in {@link CommandController} implementations | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
public interface NavigationResultEntry | ||
{ | ||
/** | ||
* Returns a Command associated with this {@link NavigationResultEntry} | ||
* | ||
* @param addonRegistry the {@link AddonRegistry} instance of this | ||
* @param context the current {@link UIContext} | ||
* @return command instance, never null | ||
*/ | ||
UICommand getCommand(AddonRegistry addonRegistry, UIContext context); | ||
} |
27 changes: 0 additions & 27 deletions
27
ui/api/src/main/java/org/jboss/forge/addon/ui/result/NavigationResultImpl.java
This file was deleted.
Oops, something went wrong.
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
67 changes: 67 additions & 0 deletions
67
.../src/main/java/org/jboss/forge/addon/ui/result/navigation/ClassNavigationResultEntry.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,67 @@ | ||
/** | ||
* 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.result.navigation; | ||
|
||
import org.jboss.forge.addon.ui.command.UICommand; | ||
import org.jboss.forge.addon.ui.context.UIContext; | ||
import org.jboss.forge.addon.ui.result.NavigationResultEntry; | ||
import org.jboss.forge.furnace.addons.AddonRegistry; | ||
|
||
/** | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
class ClassNavigationResultEntry implements NavigationResultEntry | ||
{ | ||
private final Class<? extends UICommand> type; | ||
|
||
public ClassNavigationResultEntry(Class<? extends UICommand> type) | ||
{ | ||
this.type = type; | ||
} | ||
|
||
@Override | ||
public UICommand getCommand(AddonRegistry addonRegistry, UIContext context) | ||
{ | ||
return addonRegistry.getServices(type).get(); | ||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + ((type == null) ? 0 : type.hashCode()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) | ||
{ | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
ClassNavigationResultEntry other = (ClassNavigationResultEntry) obj; | ||
if (type == null) | ||
{ | ||
if (other.type != null) | ||
return false; | ||
} | ||
else if (!type.getName().equals(other.type.getName())) | ||
return false; | ||
return true; | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return "ClassNavigationResultEntry [type=" + type + "]"; | ||
} | ||
} |
Oops, something went wrong.