itrimble | 38bf0b9 | 2006-10-30 18:59:16 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 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 | *******************************************************************************/ |
| 12 | package org.eclipse.jst.pagedesigner.properties.celleditors; |
| 13 | |
| 14 | import org.eclipse.core.resources.IFile; |
| 15 | import org.eclipse.core.resources.IProject; |
| 16 | import org.eclipse.core.runtime.IPath; |
| 17 | import org.eclipse.jface.window.Window; |
cbateman | 6d3359f | 2006-11-28 20:23:25 +0000 | [diff] [blame] | 18 | import org.eclipse.jst.jsf.common.ui.internal.dialogs.CommonResourceDialog; |
| 19 | import org.eclipse.jst.jsf.common.ui.internal.utils.PathUtil; |
| 20 | import org.eclipse.jst.jsf.common.ui.internal.utils.WebrootUtil; |
itrimble | 38bf0b9 | 2006-10-30 18:59:16 +0000 | [diff] [blame] | 21 | import org.eclipse.jst.pagedesigner.utils.WebAppUtil; |
| 22 | import org.eclipse.swt.SWT; |
| 23 | import org.eclipse.swt.widgets.Composite; |
| 24 | import org.eclipse.swt.widgets.Control; |
| 25 | import org.eclipse.swt.widgets.Shell; |
| 26 | |
| 27 | /** |
| 28 | * @author mengbo |
| 29 | */ |
| 30 | public 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 | |
gkessler | 5e2a6e3 | 2007-12-28 22:04:29 +0000 | [diff] [blame] | 43 | private String _separator = ""; //$NON-NLS-1$ |
itrimble | 38bf0b9 | 2006-10-30 18:59:16 +0000 | [diff] [blame] | 44 | |
cbateman | b706024 | 2007-10-22 06:45:19 +0000 | [diff] [blame] | 45 | |
| 46 | /** |
gkessler | c2f44ec | 2007-12-07 23:43:50 +0000 | [diff] [blame] | 47 | * Constructor |
itrimble | 38bf0b9 | 2006-10-30 18:59:16 +0000 | [diff] [blame] | 48 | */ |
| 49 | public ResourceDialogCellEditor() { |
| 50 | super(); |
| 51 | } |
gkessler | c2f44ec | 2007-12-07 23:43:50 +0000 | [diff] [blame] | 52 | |
| 53 | /** |
| 54 | * Constructor |
| 55 | * @param parent |
| 56 | */ |
| 57 | public ResourceDialogCellEditor(Composite parent) { |
itrimble | 38bf0b9 | 2006-10-30 18:59:16 +0000 | [diff] [blame] | 58 | super(parent); |
| 59 | } |
gkessler | c2f44ec | 2007-12-07 23:43:50 +0000 | [diff] [blame] | 60 | |
cbateman | b706024 | 2007-10-22 06:45:19 +0000 | [diff] [blame] | 61 | /** |
gkessler | c2f44ec | 2007-12-07 23:43:50 +0000 | [diff] [blame] | 62 | * Constructor |
| 63 | * @param parent |
| 64 | * @param style |
itrimble | 38bf0b9 | 2006-10-30 18:59:16 +0000 | [diff] [blame] | 65 | */ |
| 66 | public ResourceDialogCellEditor(Composite parent, int style) { |
| 67 | super(parent, style); |
| 68 | } |
| 69 | |
itrimble | 38bf0b9 | 2006-10-30 18:59:16 +0000 | [diff] [blame] | 70 | protected Object openDialogBox(Control cellEditorWindow) { |
| 71 | Shell shell = cellEditorWindow.getShell(); |
gkessler | 5e2a6e3 | 2007-12-28 22:04:29 +0000 | [diff] [blame] | 72 | int style = "".equals(_separator) ? SWT.NONE : SWT.MULTI | SWT.H_SCROLL //$NON-NLS-1$ |
itrimble | 38bf0b9 | 2006-10-30 18:59:16 +0000 | [diff] [blame] | 73 | | SWT.V_SCROLL; |
| 74 | CommonResourceDialog dialog = new CommonResourceDialog(shell, _project, |
| 75 | style); |
gkessler | 5e2a6e3 | 2007-12-28 22:04:29 +0000 | [diff] [blame] | 76 | dialog.setTitle(ResourceBoundle.getString("FileCellEditor.Title")); //$NON-NLS-1$ |
itrimble | 38bf0b9 | 2006-10-30 18:59:16 +0000 | [diff] [blame] | 77 | 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() { |
gkessler | c2f44ec | 2007-12-07 23:43:50 +0000 | [diff] [blame] | 149 | if (_resourceDescription == null) { |
gkessler | 5e2a6e3 | 2007-12-28 22:04:29 +0000 | [diff] [blame] | 150 | if ("".equalsIgnoreCase(getSeparator())) { //$NON-NLS-1$ |
gkessler | c2f44ec | 2007-12-07 23:43:50 +0000 | [diff] [blame] | 151 | _resourceDescription = ResourceBoundle |
gkessler | 5e2a6e3 | 2007-12-28 22:04:29 +0000 | [diff] [blame] | 152 | .getString("FileCellEditor.Msg"); //$NON-NLS-1$ |
gkessler | c2f44ec | 2007-12-07 23:43:50 +0000 | [diff] [blame] | 153 | } else { |
| 154 | _resourceDescription = ResourceBoundle |
gkessler | 5e2a6e3 | 2007-12-28 22:04:29 +0000 | [diff] [blame] | 155 | .getString("FileCellEditor.Msg1"); //$NON-NLS-1$ |
gkessler | c2f44ec | 2007-12-07 23:43:50 +0000 | [diff] [blame] | 156 | } |
| 157 | } |
itrimble | 38bf0b9 | 2006-10-30 18:59:16 +0000 | [diff] [blame] | 158 | 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 | /** |
gkessler | c2f44ec | 2007-12-07 23:43:50 +0000 | [diff] [blame] | 170 | * @return Returns the suffixes. |
itrimble | 38bf0b9 | 2006-10-30 18:59:16 +0000 | [diff] [blame] | 171 | */ |
| 172 | public String[] getSuffixs() { |
| 173 | return _suffixs; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * @param suffixs |
gkessler | c2f44ec | 2007-12-07 23:43:50 +0000 | [diff] [blame] | 178 | * The suffixes to set. |
itrimble | 38bf0b9 | 2006-10-30 18:59:16 +0000 | [diff] [blame] | 179 | */ |
| 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 | |
cbateman | b706024 | 2007-10-22 06:45:19 +0000 | [diff] [blame] | 193 | /** |
| 194 | * @param needTransform |
| 195 | */ |
itrimble | 38bf0b9 | 2006-10-30 18:59:16 +0000 | [diff] [blame] | 196 | public void setTransformJSPURL(boolean needTransform) { |
| 197 | this._needTransformJSPURL = needTransform; |
| 198 | } |
| 199 | |
cbateman | b706024 | 2007-10-22 06:45:19 +0000 | [diff] [blame] | 200 | /** |
gkessler | c2f44ec | 2007-12-07 23:43:50 +0000 | [diff] [blame] | 201 | * @return separator to use for between values |
cbateman | b706024 | 2007-10-22 06:45:19 +0000 | [diff] [blame] | 202 | */ |
itrimble | 38bf0b9 | 2006-10-30 18:59:16 +0000 | [diff] [blame] | 203 | public String getSeparator() { |
| 204 | return _separator; |
| 205 | } |
| 206 | |
cbateman | b706024 | 2007-10-22 06:45:19 +0000 | [diff] [blame] | 207 | /** |
gkessler | c2f44ec | 2007-12-07 23:43:50 +0000 | [diff] [blame] | 208 | * @param separator to use for between values |
cbateman | b706024 | 2007-10-22 06:45:19 +0000 | [diff] [blame] | 209 | */ |
itrimble | 38bf0b9 | 2006-10-30 18:59:16 +0000 | [diff] [blame] | 210 | public void setSeparator(String separator) { |
| 211 | this._separator = separator; |
| 212 | } |
| 213 | } |