001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: */
013: package org.pentaho.designstudio.editors.actionsequence.pages;
014:
015: import org.dom4j.Element;
016: import org.eclipse.jface.viewers.LabelProvider;
017: import org.eclipse.swt.graphics.Image;
018: import org.eclipse.swt.widgets.Display;
019: import org.pentaho.actionsequence.dom.ActionIfStatement;
020: import org.pentaho.actionsequence.dom.ActionInput;
021: import org.pentaho.actionsequence.dom.ActionLoop;
022: import org.pentaho.actionsequence.dom.ActionOutput;
023: import org.pentaho.actionsequence.dom.ActionSequenceDocument;
024: import org.pentaho.actionsequence.dom.ActionSequenceInput;
025: import org.pentaho.actionsequence.dom.ActionSequenceOutput;
026: import org.pentaho.actionsequence.dom.ActionSequenceResource;
027: import org.pentaho.actionsequence.dom.actions.ActionDefinition;
028: import org.pentaho.designstudio.editors.actionsequence.ActionSequenceEditorPlugin;
029: import org.pentaho.designstudio.messages.Messages;
030:
031: public class ActionSequenceLabelProvider extends LabelProvider {
032:
033: Display display;
034: static final Image folderImage = ActionSequenceEditorPlugin
035: .getImageDescriptor(
036: Messages
037: .getString("ActionSequenceLabelProvider.ICON_TREE_FOLDER")).createImage(); //$NON-NLS-1$
038: static final Image inputImage = ActionSequenceEditorPlugin
039: .getImageDescriptor(
040: Messages
041: .getString("ActionSequenceLabelProvider.ICON_TREE_INPUT")).createImage(); //$NON-NLS-1$
042: static final Image outputImage = ActionSequenceEditorPlugin
043: .getImageDescriptor(
044: Messages
045: .getString("ActionSequenceLabelProvider.ICON_TREE_OUTPUT")).createImage(); //$NON-NLS-1$
046: static final Image actionImage = ActionSequenceEditorPlugin
047: .getImageDescriptor(
048: Messages
049: .getString("ActionSequenceLabelProvider.ICON_TREE_ACTION_DEF")).createImage(); //$NON-NLS-1$
050: static final Image loopImage = ActionSequenceEditorPlugin
051: .getImageDescriptor(
052: Messages
053: .getString("ActionSequenceLabelProvider.ICON_TREE_ACTION_LOOP")).createImage(); //$NON-NLS-1$
054: static final Image ifImage = ActionSequenceEditorPlugin
055: .getImageDescriptor(
056: Messages
057: .getString("ActionSequenceLabelProvider.ICON_TREE_ACTION_IF")).createImage(); //$NON-NLS-1$
058: static final Image resourceImage = ActionSequenceEditorPlugin
059: .getImageDescriptor(
060: Messages
061: .getString("ActionSequenceLabelProvider.ICON_TREE_RESOURCE")).createImage(); //$NON-NLS-1$
062:
063: static final Image unknownActionImage = null;//ActionSequenceEditorPlugin.getImageDescriptor( Messages.getString("ActionSequenceLabelProvider.ICON_FLOW_DEFAULT_COMP")).createImage();
064:
065: /**
066: * Creates a label provider Tress which display action sequence contents.
067: */
068: public ActionSequenceLabelProvider(Display display) {
069: super ();
070: this .display = display;
071: }
072:
073: public Image getImage(Object obj) {
074: Image image = null;
075: if (obj instanceof ActionDefinition) {
076: image = actionImage;
077: } else if (obj instanceof ActionInput) {
078: image = inputImage;
079: } else if (obj instanceof ActionSequenceInput) {
080: image = inputImage;
081: } else if (obj instanceof ActionOutput) {
082: image = outputImage;
083: } else if (obj instanceof ActionSequenceOutput) {
084: image = outputImage;
085: } else if (obj instanceof ActionLoop) {
086: image = loopImage;
087: } else if (obj instanceof ActionIfStatement) {
088: image = ifImage;
089: } else if (obj instanceof ActionSequenceResource) {
090: image = resourceImage;
091: } else if (obj instanceof Element) {
092: Element element = (Element) obj;
093: if (element.getPath().equals(
094: ActionSequenceDocument.DOC_INPUTS_PATH)
095: || element.getPath().equals(
096: ActionSequenceDocument.DOC_OUTPUTS_PATH)
097: || element.getPath().equals(
098: ActionSequenceDocument.DOC_RESOURCES_PATH)) {
099: image = folderImage;
100: }
101: }
102: return image;
103:
104: }
105:
106: public static String getText(ActionIfStatement actionIf) {
107: String text = Messages
108: .getString("ActionSequenceLabelProvider.IF_STATEMENT"); //$NON-NLS-1$
109: String condition = actionIf.getCondition();
110: if (condition.length() < 25) {
111: text = text + " " + condition; //$NON-NLS-1$
112: } else {
113: text = text + " " + condition.substring(0, 25 - 3) + "..."; //$NON-NLS-1$ //$NON-NLS-2$
114: }
115: return text;
116: }
117:
118: public static String getText(ActionLoop actionLoop) {
119: String loopOn = actionLoop.getLoopOn();
120: if ((loopOn != null) && (loopOn.length() > 0)) {
121: loopOn = Messages
122: .getString("ActionSequenceLabelProvider.UI_ACTIONS_LOOP_ON_TEXT") + loopOn; //$NON-NLS-1$
123: } else {
124: loopOn = Messages
125: .getString("ActionSequenceLabelProvider.UI_ACTIONS_SET_TEXT"); //$NON-NLS-1$
126: }
127: return loopOn;
128: }
129:
130: public static String getText(ActionDefinition actionDefinition) {
131: String text = actionDefinition.getDescription();
132: if (text.length() == 0) {
133: text = actionDefinition.getComponentName().trim();
134: if ((text != null) && (text.length() > 0)) {
135: int index = text.lastIndexOf("."); //$NON-NLS-1$
136: if ((index >= 0) && ((index + 1) < text.length())) {
137: String subStr = text.substring(index + 1).trim();
138: if (subStr.length() > 0) {
139: text = subStr;
140: }
141: }
142: }
143: }
144: if ((text == null) || (text.length() == 0)) {
145: text = Messages
146: .getString("ActionSequenceLabelProvider.UI_ACTIONS_UNKNOWN_TEXT"); //$NON-NLS-1$
147: }
148: return text;
149: }
150:
151: public static String getText(ActionOutput output) {
152: return output.getPublicName();
153: }
154:
155: public static String getText(ActionSequenceOutput output) {
156: return output.getName() + " (" + output.getType() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
157: }
158:
159: public static String getText(ActionInput input) {
160: return input.getName();
161: }
162:
163: public static String getText(ActionSequenceInput input) {
164: return input.getName() + " (" + input.getType() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
165: }
166:
167: public static String getText(ActionSequenceResource resource) {
168: return resource.getName();
169: }
170:
171: /*
172: * (non-Javadoc)
173: *
174: * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
175: */
176: public String getText(Object obj) {
177: String text = obj.toString();
178: if (obj instanceof ActionDefinition) {
179: text = getText((ActionDefinition) obj);
180: } else if (obj instanceof ActionInput) {
181: text = getText((ActionInput) obj);
182: } else if (obj instanceof ActionSequenceInput) {
183: text = getText((ActionSequenceInput) obj);
184: } else if (obj instanceof ActionOutput) {
185: text = getText((ActionOutput) obj);
186: } else if (obj instanceof ActionSequenceOutput) {
187: text = getText((ActionSequenceOutput) obj);
188: } else if (obj instanceof ActionLoop) {
189: text = getText((ActionLoop) obj);
190: } else if (obj instanceof ActionIfStatement) {
191: text = getText((ActionIfStatement) obj);
192: } else if (obj instanceof ActionSequenceResource) {
193: text = getText((ActionSequenceResource) obj);
194: } else if (obj instanceof Element) {
195: text = ((Element) obj).getName();
196: }
197: return text;
198: }
199:
200: /* (non-Javadoc)
201: * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
202: */
203: public boolean isLabelProperty(Object obj, String property) {
204: return true;
205: }
206:
207: }
|