use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.
the class SmallTabLayoutState method renderContent.
@Override
protected JSONObject renderContent() throws JSONException {
JSONObject state = new JSONObject();
List<String> errorTabs = new LinkedList<String>();
for (Map.Entry<String, InternalComponentState> child : getChildren().entrySet()) {
if (child.getValue().isHasError()) {
for (SmallTabLayoutPatternTab tab : tabs) {
boolean found = false;
for (ComponentPattern tabComponents : tab.getComponents()) {
if (tabComponents.getName().equals(child.getValue().getName())) {
errorTabs.add(tab.getName());
found = true;
break;
}
}
if (found) {
break;
}
}
}
}
JSONArray errors = new JSONArray();
for (String tabName : errorTabs) {
errors.put(tabName);
}
state.put("errors", errors);
return state;
}
use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.
the class ViewTabModule method enable.
@Override
public void enable() {
addedTabs = ArrayListMultimap.create();
InternalViewDefinition viewDefinition = viewDefinitionService.getWithoutSession(viewExtension.getPluginName(), viewExtension.getViewName());
if (viewDefinition == null) {
throw new ModuleException(pluginIdentifier, "view", String.format("Reference to view which not exists: %s[%s]", viewExtension.getPluginName(), viewExtension.getViewName()));
}
try {
for (Node tabNode : viewDefinitionParser.geElementChildren(viewExtension.getExtesionNode())) {
WindowComponentPattern window = viewDefinition.getRootWindow();
ComponentDefinition tabDefinition = viewDefinitionParser.getComponentDefinition(tabNode, window, viewDefinition);
tabDefinition.setExtensionPluginIdentifier(pluginIdentifier);
ComponentPattern tabPattern = new WindowTabComponentPattern(tabDefinition);
try {
tabPattern.parse(tabNode, viewDefinitionParser);
} catch (ViewDefinitionParserNodeException e) {
throw ViewDefinitionParserException.forFileAndNode(fileName, e);
}
window.addChild(tabPattern);
addedTabs.put(window, tabPattern);
tabPattern.initializeAll();
tabPattern.registerViews(viewDefinitionService);
}
} catch (Exception e) {
throw new ModuleException(pluginIdentifier, "view-tab", e);
}
}
use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.
the class ViewDefinitionImpl method translateContextReferences.
@Override
@SuppressWarnings("unchecked")
public String translateContextReferences(final String context) {
if (context == null) {
return null;
}
try {
JSONObject oldContext = new JSONObject(context);
JSONObject newContext = new JSONObject();
Iterator<String> paths = oldContext.keys();
while (paths.hasNext()) {
String oldPath = paths.next();
String[] newPath = oldPath.split("\\.");
ComponentPattern pattern = getComponentByReference(newPath[0]);
if (pattern == null) {
throw new IllegalStateException("Cannot find component for " + getPluginIdentifier() + "." + getName() + ": " + newPath[0]);
}
newPath[0] = pattern.getPath();
newContext.put(StringUtils.arrayToDelimitedString(newPath, "."), oldContext.get(oldPath));
}
return newContext.toString();
} catch (JSONException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.
the class ViewDefinitionImpl method initialize.
@Override
public void initialize() {
List<ComponentPattern> list = getPatternsAsList(patterns.values());
int lastNotInitialized = 0;
while (true) {
int notInitialized = 0;
for (ComponentPattern pattern : list) {
if (!pattern.initialize()) {
notInitialized++;
}
}
if (notInitialized == 0) {
break;
}
if (notInitialized == lastNotInitialized) {
throw new IllegalStateException("There is cyclic dependency between components");
}
lastNotInitialized = notInitialized;
}
initAdditionalNavigation();
}
use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.
the class GridLayoutPattern method createGridLayoutCell.
private GridLayoutCell createGridLayoutCell(final Node child, final ViewDefinitionParser parser) throws ViewDefinitionParserNodeException {
Integer colspan = getIntAttribute(child, "width", parser);
Integer rowspan = getIntAttribute(child, "height", parser);
ComponentPattern elementComponent = null;
NodeList elementComponentNodes = child.getChildNodes();
GridLayoutCell cell = new GridLayoutCell();
for (int elementComponentNodesIter = 0; elementComponentNodesIter < elementComponentNodes.getLength(); elementComponentNodesIter++) {
Node elementComponentNode = elementComponentNodes.item(elementComponentNodesIter);
if (elementComponentNode.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
parser.checkState("component".equals(elementComponentNode.getNodeName()), elementComponentNode, "layoutElement can contains only components");
elementComponent = parser.parseComponent(elementComponentNode, this);
this.addChild(elementComponent);
cell.addComponent(elementComponent);
}
if (colspan != null) {
cell.setColspan(colspan);
}
if (rowspan != null) {
cell.setRowspan(rowspan);
}
return cell;
}
Aggregations