001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.shared.search.query;
034:
035: import com.flexive.shared.FxLanguage;
036: import com.flexive.shared.FxSharedUtils;
037: import com.flexive.shared.exceptions.FxInvalidQueryNodeException;
038: import com.flexive.shared.exceptions.FxRuntimeException;
039: import com.flexive.shared.tree.FxTreeMode;
040: import com.flexive.shared.value.FxString;
041: import com.flexive.shared.value.FxValue;
042: import com.flexive.shared.value.renderer.FxValueFormatter;
043:
044: import java.util.Arrays;
045: import java.util.List;
046:
047: /**
048: * Value node for tree queries (i.e. search in subtrees).
049: *
050: * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
051: * @version $Rev: 181 $
052: */
053: public class TreeValueNode extends
054: QueryValueNode<FxValue, TreeValueNode.TreeValueComparator> {
055: private static final long serialVersionUID = -403941329020860113L;
056:
057: private final long nodeId;
058: private final FxTreeMode treeMode;
059: private final FxString nodeLabel;
060:
061: public static enum TreeValueComparator implements ValueComparator {
062: CHILD, DIRECTCHILD;
063:
064: /** {@inheritDoc} */
065: public boolean isNeedsInput() {
066: return false;
067: }
068:
069: /** {@inheritDoc} */
070: public FxString getLabel() {
071: return FxSharedUtils.getEnumLabel(this );
072: }
073: }
074:
075: public TreeValueNode(int id, long nodeId, FxTreeMode treeMode,
076: FxString nodeLabel) {
077: super (id);
078: this .nodeId = nodeId;
079: this .comparator = TreeValueComparator.CHILD;
080: this .nodeLabel = nodeLabel;
081: this .treeMode = treeMode;
082: setValue(this .nodeLabel);
083: }
084:
085: /** {@inheritDoc} */
086: @Override
087: public boolean isReadOnly() {
088: return true;
089: }
090:
091: /** {@inheritDoc} */
092: @Override
093: public FxString getLabel() {
094: return FxSharedUtils.getMessage(FxSharedUtils.SHARED_BUNDLE,
095: "shared.QueryNode.label.tree");
096: }
097:
098: /** {@inheritDoc} */
099: @Override
100: public boolean isValid() {
101: return true;
102: }
103:
104: /** {@inheritDoc} */
105: @Override
106: public FxValueFormatter getValueFormatter() {
107: return new FxValueFormatter() {
108: public String format(FxValue container, Object value,
109: FxLanguage outputLanguage) {
110: if (value == null) {
111: return "";
112: }
113: // append tree mode to label
114: return value.toString()
115: + " "
116: + FxSharedUtils
117: .getMessage(
118: FxSharedUtils.SHARED_BUNDLE,
119: "shared.QueryNode.label.tree."
120: + (FxTreeMode.Live
121: .equals(treeMode) ? "live"
122: : "edit"));
123: }
124: };
125: }
126:
127: /** {@inheritDoc} */
128: @Override
129: protected void buildSqlQuery(SqlQueryBuilder builder) {
130: try {
131: // TODO: add tree live mode to query
132: if (this .comparator.equals(TreeValueComparator.CHILD)) {
133: builder.isChild(nodeId);
134: } else {
135: builder.isDirectChild(nodeId);
136: }
137: } catch (FxRuntimeException e) {
138: throw new FxInvalidQueryNodeException(getId(), e
139: .getConverted()).asRuntimeException();
140: }
141: }
142:
143: /** {@inheritDoc} */
144: @Override
145: public List<TreeValueComparator> getNodeComparators() {
146: return Arrays.asList(TreeValueComparator.values());
147: }
148: }
|