blob: 0eced33e6525e546da203a0ce159b31c3534ea69 [file] [log] [blame]
itrimble38bf0b92006-10-30 18:59:16 +00001/*******************************************************************************
2 * Copyright (c) 2006 Sybase, Inc. and others.
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Sybase, Inc. - initial API and implementation
11 *******************************************************************************/
12package org.eclipse.jst.pagedesigner.properties.celleditors;
13
14import org.eclipse.core.resources.IFile;
15import org.eclipse.core.resources.IProject;
16import org.eclipse.core.runtime.IPath;
17import org.eclipse.jface.window.Window;
cbateman6d3359f2006-11-28 20:23:25 +000018import org.eclipse.jst.jsf.common.ui.internal.dialogs.CommonResourceDialog;
19import org.eclipse.jst.jsf.common.ui.internal.utils.PathUtil;
20import org.eclipse.jst.jsf.common.ui.internal.utils.WebrootUtil;
itrimble38bf0b92006-10-30 18:59:16 +000021import org.eclipse.jst.pagedesigner.utils.WebAppUtil;
22import org.eclipse.swt.SWT;
23import org.eclipse.swt.widgets.Composite;
24import org.eclipse.swt.widgets.Control;
25import org.eclipse.swt.widgets.Shell;
26
27/**
28 * @author mengbo
29 */
30public class ResourceDialogCellEditor extends EditableDialogCellEditor {
31 private IProject _project;
32
33 private String[] _suffixs;
34
35 private String _resourceDescription;
36
37 private IFile _referredFile;
38
39 private boolean _isWebPath = false;
40
41 private boolean _needTransformJSPURL = true;
42
gkessler5e2a6e32007-12-28 22:04:29 +000043 private String _separator = ""; //$NON-NLS-1$
itrimble38bf0b92006-10-30 18:59:16 +000044
cbatemanb7060242007-10-22 06:45:19 +000045
46 /**
gkesslerc2f44ec2007-12-07 23:43:50 +000047 * Constructor
itrimble38bf0b92006-10-30 18:59:16 +000048 */
49 public ResourceDialogCellEditor() {
50 super();
51 }
gkesslerc2f44ec2007-12-07 23:43:50 +000052
53 /**
54 * Constructor
55 * @param parent
56 */
57 public ResourceDialogCellEditor(Composite parent) {
itrimble38bf0b92006-10-30 18:59:16 +000058 super(parent);
59 }
gkesslerc2f44ec2007-12-07 23:43:50 +000060
cbatemanb7060242007-10-22 06:45:19 +000061 /**
gkesslerc2f44ec2007-12-07 23:43:50 +000062 * Constructor
63 * @param parent
64 * @param style
itrimble38bf0b92006-10-30 18:59:16 +000065 */
66 public ResourceDialogCellEditor(Composite parent, int style) {
67 super(parent, style);
68 }
69
itrimble38bf0b92006-10-30 18:59:16 +000070 protected Object openDialogBox(Control cellEditorWindow) {
71 Shell shell = cellEditorWindow.getShell();
gkessler5e2a6e32007-12-28 22:04:29 +000072 int style = "".equals(_separator) ? SWT.NONE : SWT.MULTI | SWT.H_SCROLL //$NON-NLS-1$
itrimble38bf0b92006-10-30 18:59:16 +000073 | SWT.V_SCROLL;
74 CommonResourceDialog dialog = new CommonResourceDialog(shell, _project,
75 style);
gkessler5e2a6e32007-12-28 22:04:29 +000076 dialog.setTitle(ResourceBoundle.getString("FileCellEditor.Title")); //$NON-NLS-1$
itrimble38bf0b92006-10-30 18:59:16 +000077 dialog.setSuffixs(_suffixs);
78 dialog.setResourceDescription(_resourceDescription);
79 if (dialog.open() == Window.OK) {
80 Object[] result = dialog.getResult();
81 StringBuffer buffer = new StringBuffer();
82 for (int i = 0; i < result.length; i++) {
83 IPath path = ((IFile) result[i]).getLocation();
84
85 IPath referredPath = null;
86 if (_referredFile != null) {
87 referredPath = _referredFile.getLocation();
88 } else {
89 referredPath = _project.getLocation();
90 }
91
92 String newValue = null;
93 if (this._isWebPath) {
94 IFile selectedFile = ((IFile) result[i]);
95 newValue = WebrootUtil.getWebPath(selectedFile
96 .getFullPath());
97 } else {
98 newValue = PathUtil.convertToRelativePath(path.toString(),
99 referredPath.toString());
100 }
101 if (this._needTransformJSPURL) {
102 newValue = WebAppUtil.transformJSPURL(newValue,
103 this._referredFile);
104 }
105 buffer.append(newValue);
106 buffer.append(_separator);
107 }
108 if (buffer.length() > 0) {
109 return buffer.substring(0, buffer.length()
110 - _separator.length());
111 }
112 }
113 return null;
114 }
115
116 /**
117 * @param project
118 */
119 public void setProject(IProject project) {
120 this._project = project;
121 }
122
123 /**
124 * @return Returns the project.
125 */
126 public IProject getProject() {
127 return _project;
128 }
129
130 /**
131 * @return Returns the referredFile.
132 */
133 public IFile getReferredFile() {
134 return _referredFile;
135 }
136
137 /**
138 * @param referredFile
139 * The referredFile to set.
140 */
141 public void setReferredFile(IFile referredFile) {
142 this._referredFile = referredFile;
143 }
144
145 /**
146 * @return Returns the resourceDescription.
147 */
148 public String getResourceDescription() {
gkesslerc2f44ec2007-12-07 23:43:50 +0000149 if (_resourceDescription == null) {
gkessler5e2a6e32007-12-28 22:04:29 +0000150 if ("".equalsIgnoreCase(getSeparator())) { //$NON-NLS-1$
gkesslerc2f44ec2007-12-07 23:43:50 +0000151 _resourceDescription = ResourceBoundle
gkessler5e2a6e32007-12-28 22:04:29 +0000152 .getString("FileCellEditor.Msg"); //$NON-NLS-1$
gkesslerc2f44ec2007-12-07 23:43:50 +0000153 } else {
154 _resourceDescription = ResourceBoundle
gkessler5e2a6e32007-12-28 22:04:29 +0000155 .getString("FileCellEditor.Msg1"); //$NON-NLS-1$
gkesslerc2f44ec2007-12-07 23:43:50 +0000156 }
157 }
itrimble38bf0b92006-10-30 18:59:16 +0000158 return _resourceDescription;
159 }
160
161 /**
162 * @param resourceDescription
163 * The resourceDescription to set.
164 */
165 public void setResourceDescription(String resourceDescription) {
166 this._resourceDescription = resourceDescription;
167 }
168
169 /**
gkesslerc2f44ec2007-12-07 23:43:50 +0000170 * @return Returns the suffixes.
itrimble38bf0b92006-10-30 18:59:16 +0000171 */
172 public String[] getSuffixs() {
173 return _suffixs;
174 }
175
176 /**
177 * @param suffixs
gkesslerc2f44ec2007-12-07 23:43:50 +0000178 * The suffixes to set.
itrimble38bf0b92006-10-30 18:59:16 +0000179 */
180 public void setSuffixs(String[] suffixs) {
181 this._suffixs = suffixs;
182 }
183
184 /**
185 * set some special path to web path instead of relative path
186 *
187 * @param isWebPath
188 */
189 public void setWebPath(boolean isWebPath) {
190 this._isWebPath = isWebPath;
191 }
192
cbatemanb7060242007-10-22 06:45:19 +0000193 /**
194 * @param needTransform
195 */
itrimble38bf0b92006-10-30 18:59:16 +0000196 public void setTransformJSPURL(boolean needTransform) {
197 this._needTransformJSPURL = needTransform;
198 }
199
cbatemanb7060242007-10-22 06:45:19 +0000200 /**
gkesslerc2f44ec2007-12-07 23:43:50 +0000201 * @return separator to use for between values
cbatemanb7060242007-10-22 06:45:19 +0000202 */
itrimble38bf0b92006-10-30 18:59:16 +0000203 public String getSeparator() {
204 return _separator;
205 }
206
cbatemanb7060242007-10-22 06:45:19 +0000207 /**
gkesslerc2f44ec2007-12-07 23:43:50 +0000208 * @param separator to use for between values
cbatemanb7060242007-10-22 06:45:19 +0000209 */
itrimble38bf0b92006-10-30 18:59:16 +0000210 public void setSeparator(String separator) {
211 this._separator = separator;
212 }
213}