cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
jlanuti | fed82ab | 2005-12-01 22:03:10 +0000 | [diff] [blame] | 2 | * Copyright (c) 2003, 2005 IBM Corporation and others. |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
jlanuti | fed82ab | 2005-12-01 22:03:10 +0000 | [diff] [blame] | 7 | * |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 8 | * Contributors: |
| 9 | * IBM Corporation - initial API and implementation |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 10 | *******************************************************************************/ |
cbridgha | 44a17d7 | 2005-04-04 07:05:01 +0000 | [diff] [blame] | 11 | package org.eclipse.wst.common.componentcore.internal.resources; |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 12 | |
vbhadrir | 9dd55d9 | 2005-09-08 21:46:35 +0000 | [diff] [blame] | 13 | import java.util.ArrayList; |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 14 | import java.util.Arrays; |
vbhadrir | 9dd55d9 | 2005-09-08 21:46:35 +0000 | [diff] [blame] | 15 | import java.util.List; |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 16 | |
cbridgha | 2550120 | 2005-03-30 23:45:41 +0000 | [diff] [blame] | 17 | import org.eclipse.core.resources.IContainer; |
| 18 | import org.eclipse.core.resources.IFolder; |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 19 | import org.eclipse.core.resources.IProject; |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 20 | import org.eclipse.core.resources.IResource; |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 21 | import org.eclipse.core.runtime.CoreException; |
| 22 | import org.eclipse.core.runtime.IPath; |
| 23 | import org.eclipse.core.runtime.IProgressMonitor; |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 24 | import org.eclipse.core.runtime.jobs.ISchedulingRule; |
cbridgha | 44a17d7 | 2005-04-04 07:05:01 +0000 | [diff] [blame] | 25 | import org.eclipse.wst.common.componentcore.ComponentCore; |
cbridgha | 44a17d7 | 2005-04-04 07:05:01 +0000 | [diff] [blame] | 26 | import org.eclipse.wst.common.componentcore.internal.ComponentResource; |
vbhadrir | 58634cb | 2005-04-25 20:28:18 +0000 | [diff] [blame] | 27 | import org.eclipse.wst.common.componentcore.internal.StructureEdit; |
cbridgha | 44a17d7 | 2005-04-04 07:05:01 +0000 | [diff] [blame] | 28 | import org.eclipse.wst.common.componentcore.internal.WorkbenchComponent; |
cbridgha | 632c387 | 2005-10-03 13:27:37 +0000 | [diff] [blame] | 29 | import org.eclipse.wst.common.componentcore.internal.impl.ModuleURIUtil; |
cbridgha | b75aee9 | 2005-05-18 03:02:33 +0000 | [diff] [blame] | 30 | import org.eclipse.wst.common.componentcore.internal.impl.ResourceTreeNode; |
cbridgha | 44a17d7 | 2005-04-04 07:05:01 +0000 | [diff] [blame] | 31 | import org.eclipse.wst.common.componentcore.internal.impl.ResourceTreeRoot; |
| 32 | import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; |
| 33 | import org.eclipse.wst.common.componentcore.resources.IVirtualContainer; |
| 34 | import org.eclipse.wst.common.componentcore.resources.IVirtualResource; |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 35 | |
cbridgha | 1c6a6ba | 2005-03-24 16:24:53 +0000 | [diff] [blame] | 36 | public abstract class VirtualResource implements IVirtualResource { |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 37 | |
cbridgha | 2550120 | 2005-03-30 23:45:41 +0000 | [diff] [blame] | 38 | protected static final IResource[] NO_RESOURCES = null; |
jlanuti | 35b628c | 2006-01-04 16:44:24 +0000 | [diff] [blame] | 39 | private final IProject componentProject; |
| 40 | private final IPath runtimePath; |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 41 | private int hashCode; |
| 42 | private String toString; |
cbridgha | 1686f44 | 2005-03-29 20:48:41 +0000 | [diff] [blame] | 43 | private static final String EMPTY_STRING = ""; //$NON-NLS-1$ |
cbridgha | 44a17d7 | 2005-04-04 07:05:01 +0000 | [diff] [blame] | 44 | private IVirtualComponent component; |
cbridgha | 4da5ee7 | 2005-04-14 14:27:50 +0000 | [diff] [blame] | 45 | private String resourceType; |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 46 | |
| 47 | |
cbridgha | 632c387 | 2005-10-03 13:27:37 +0000 | [diff] [blame] | 48 | protected VirtualResource(IProject aComponentProject, IPath aRuntimePath) { |
| 49 | componentProject = aComponentProject; |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 50 | runtimePath = aRuntimePath; |
| 51 | } |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 52 | |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 53 | public void delete(int updateFlags, IProgressMonitor monitor) throws CoreException { |
| 54 | |
| 55 | if ((updateFlags & IVirtualResource.IGNORE_UNDERLYING_RESOURCE) == 0) { |
| 56 | doDeleteRealResources(updateFlags, monitor); |
| 57 | } |
| 58 | |
| 59 | doDeleteMetaModel(updateFlags, monitor); |
| 60 | } |
| 61 | |
| 62 | protected void doDeleteMetaModel(int updateFlags, IProgressMonitor monitor) { |
| 63 | StructureEdit moduleCore = null; |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 64 | try { |
cbridgha | 632c387 | 2005-10-03 13:27:37 +0000 | [diff] [blame] | 65 | moduleCore = StructureEdit.getStructureEditForWrite(getProject()); |
| 66 | WorkbenchComponent aComponent = moduleCore.getComponent(); |
vbhadrir | 9dd55d9 | 2005-09-08 21:46:35 +0000 | [diff] [blame] | 67 | ComponentResource[] resources = aComponent.findResourcesByRuntimePath(getRuntimePath()); |
| 68 | aComponent.getResources().removeAll(Arrays.asList(resources)); |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 69 | } finally { |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 70 | if (moduleCore != null) { |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 71 | moduleCore.saveIfNecessary(monitor); |
| 72 | moduleCore.dispose(); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | |
| 78 | protected abstract void doDeleteRealResources(int updateFlags, IProgressMonitor monitor) throws CoreException; |
| 79 | |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 80 | public boolean exists() { |
vbhadrir | 9dd55d9 | 2005-09-08 21:46:35 +0000 | [diff] [blame] | 81 | // verify all underlying resources exist for the virtual resource to exist |
| 82 | IResource[] resources = getUnderlyingResources(); |
vbhadrir | ff852bb | 2005-09-22 19:52:21 +0000 | [diff] [blame] | 83 | if (resources==null || resources.length==0) |
| 84 | return false; |
vbhadrir | 9dd55d9 | 2005-09-08 21:46:35 +0000 | [diff] [blame] | 85 | for (int i=0; i<resources.length; i++) { |
| 86 | if (resources[i]==null || !resources[i].exists()) |
| 87 | return false; |
| 88 | } |
| 89 | return true; |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 90 | } |
| 91 | |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 92 | public String getFileExtension() { |
cbridgha | 1686f44 | 2005-03-29 20:48:41 +0000 | [diff] [blame] | 93 | String name = getName(); |
| 94 | int dot = name.lastIndexOf('.'); |
| 95 | if (dot == -1) |
| 96 | return null; |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 97 | if (dot == name.length() - 1) |
| 98 | return EMPTY_STRING; |
| 99 | return name.substring(dot + 1); |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 100 | } |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 101 | |
cbridgha | 10e8223 | 2005-03-28 14:33:24 +0000 | [diff] [blame] | 102 | public IPath getWorkspaceRelativePath() { |
cbridgha | 1686f44 | 2005-03-29 20:48:41 +0000 | [diff] [blame] | 103 | return getProject().getFullPath().append(getProjectRelativePath()); |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 104 | } |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 105 | |
cbridgha | 1686f44 | 2005-03-29 20:48:41 +0000 | [diff] [blame] | 106 | public IPath getRuntimePath() { |
| 107 | return runtimePath; |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 108 | } |
| 109 | |
vbhadrir | 9dd55d9 | 2005-09-08 21:46:35 +0000 | [diff] [blame] | 110 | public IPath[] getProjectRelativePaths() { |
cbridgha | 44a17d7 | 2005-04-04 07:05:01 +0000 | [diff] [blame] | 111 | StructureEdit moduleCore = null; |
cbridgha | 17f4e1d | 2005-03-28 19:41:04 +0000 | [diff] [blame] | 112 | try { |
cbridgha | 44a17d7 | 2005-04-04 07:05:01 +0000 | [diff] [blame] | 113 | moduleCore = StructureEdit.getStructureEditForRead(getProject()); |
vbhadrir | f1b8046 | 2005-10-21 15:44:00 +0000 | [diff] [blame] | 114 | if (moduleCore !=null) { |
| 115 | WorkbenchComponent aComponent = moduleCore.getComponent(); |
| 116 | if (aComponent != null) { |
| 117 | ResourceTreeRoot root = ResourceTreeRoot.getDeployResourceTreeRoot(aComponent); |
| 118 | // still need some sort of loop here to search subpieces of the runtime path. |
| 119 | ComponentResource[] componentResources = null; |
| 120 | |
| 121 | if (root != null) { |
| 122 | IPath[] estimatedPaths = null; |
| 123 | IPath searchPath = null; |
| 124 | do { |
| 125 | searchPath = (searchPath == null) ? getRuntimePath() : searchPath.removeLastSegments(1); |
| 126 | componentResources = root.findModuleResources(searchPath, ResourceTreeNode.CREATE_NONE); |
| 127 | estimatedPaths = findBestMatches(componentResources); |
| 128 | } while (estimatedPaths.length==0 && canSearchContinue(componentResources, searchPath)); |
| 129 | if (estimatedPaths==null || estimatedPaths.length==0) |
| 130 | return new IPath[] {getRuntimePath()}; |
| 131 | return estimatedPaths; |
| 132 | } |
| 133 | } |
cbridgha | fe83b0c | 2005-04-19 19:54:55 +0000 | [diff] [blame] | 134 | } |
cbridgha | 17f4e1d | 2005-03-28 19:41:04 +0000 | [diff] [blame] | 135 | } finally { |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 136 | if (moduleCore != null) { |
cbridgha | 17f4e1d | 2005-03-28 19:41:04 +0000 | [diff] [blame] | 137 | moduleCore.dispose(); |
| 138 | } |
| 139 | } |
vbhadrir | 9dd55d9 | 2005-09-08 21:46:35 +0000 | [diff] [blame] | 140 | return new IPath[] {getRuntimePath()}; |
cbridgha | d953dc7 | 2005-04-26 21:38:47 +0000 | [diff] [blame] | 141 | } |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 142 | |
vbhadrir | 9dd55d9 | 2005-09-08 21:46:35 +0000 | [diff] [blame] | 143 | public IPath getProjectRelativePath() { |
| 144 | return getProjectRelativePaths()[0]; |
| 145 | } |
| 146 | |
cbridgha | d953dc7 | 2005-04-26 21:38:47 +0000 | [diff] [blame] | 147 | private boolean canSearchContinue(ComponentResource[] componentResources, IPath searchPath) { |
cbridgha | 07e7c5f | 2005-04-27 14:57:46 +0000 | [diff] [blame] | 148 | return (searchPath.segmentCount() > 0); |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 149 | } |
| 150 | |
vbhadrir | 9dd55d9 | 2005-09-08 21:46:35 +0000 | [diff] [blame] | 151 | private IPath[] findBestMatches(ComponentResource[] theComponentResources) { |
| 152 | List result = new ArrayList(); |
cbridgha | d953dc7 | 2005-04-26 21:38:47 +0000 | [diff] [blame] | 153 | int currentMatchLength = 0; |
cbridgha | 07e7c5f | 2005-04-27 14:57:46 +0000 | [diff] [blame] | 154 | int bestMatchLength = -1; |
cbridgha | d953dc7 | 2005-04-26 21:38:47 +0000 | [diff] [blame] | 155 | IPath estimatedPath = null; |
| 156 | IPath currentPath = null; |
vbhadrir | 9dd55d9 | 2005-09-08 21:46:35 +0000 | [diff] [blame] | 157 | final IPath aRuntimePath = getRuntimePath(); |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 158 | for (int i = 0; i < theComponentResources.length; i++) { |
cbridgha | d953dc7 | 2005-04-26 21:38:47 +0000 | [diff] [blame] | 159 | currentPath = theComponentResources[i].getRuntimePath(); |
vbhadrir | 9dd55d9 | 2005-09-08 21:46:35 +0000 | [diff] [blame] | 160 | if (currentPath.isPrefixOf(aRuntimePath)) { |
| 161 | if (currentPath.segmentCount() == aRuntimePath.segmentCount()) { |
| 162 | result.add(theComponentResources[i].getSourcePath()); |
| 163 | continue; |
| 164 | } |
| 165 | currentMatchLength = currentPath.matchingFirstSegments(aRuntimePath); |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 166 | if (currentMatchLength == currentPath.segmentCount() && currentMatchLength > bestMatchLength) { |
cbridgha | d953dc7 | 2005-04-26 21:38:47 +0000 | [diff] [blame] | 167 | bestMatchLength = currentMatchLength; |
| 168 | IPath sourcePath = theComponentResources[i].getSourcePath(); |
vbhadrir | 9dd55d9 | 2005-09-08 21:46:35 +0000 | [diff] [blame] | 169 | IPath subpath = aRuntimePath.removeFirstSegments(currentMatchLength); |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 170 | estimatedPath = sourcePath.append(subpath); |
| 171 | } |
cbridgha | d953dc7 | 2005-04-26 21:38:47 +0000 | [diff] [blame] | 172 | } |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 173 | } |
vbhadrir | 9dd55d9 | 2005-09-08 21:46:35 +0000 | [diff] [blame] | 174 | if (result.size()>0) |
| 175 | return (IPath[]) result.toArray(new IPath[result.size()]); |
vbhadrir | c269ec3 | 2005-09-09 16:11:46 +0000 | [diff] [blame] | 176 | if (estimatedPath == null) |
| 177 | return new IPath[] {}; |
vbhadrir | 9dd55d9 | 2005-09-08 21:46:35 +0000 | [diff] [blame] | 178 | return new IPath[] {estimatedPath}; |
cbridgha | d953dc7 | 2005-04-26 21:38:47 +0000 | [diff] [blame] | 179 | } |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 180 | |
cbridgha | 1686f44 | 2005-03-29 20:48:41 +0000 | [diff] [blame] | 181 | public String getName() { |
vbhadrir | dc0f5ee | 2005-08-17 20:16:35 +0000 | [diff] [blame] | 182 | if (getRuntimePath().segmentCount()>0) |
| 183 | return getRuntimePath().lastSegment(); |
| 184 | return getRuntimePath().toString(); |
cbridgha | 1686f44 | 2005-03-29 20:48:41 +0000 | [diff] [blame] | 185 | } |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 186 | |
cbridgha | 44a17d7 | 2005-04-04 07:05:01 +0000 | [diff] [blame] | 187 | public IVirtualComponent getComponent() { |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 188 | if (component == null) |
cbridgha | 632c387 | 2005-10-03 13:27:37 +0000 | [diff] [blame] | 189 | component = ComponentCore.createComponent(getProject()); |
cbridgha | 44a17d7 | 2005-04-04 07:05:01 +0000 | [diff] [blame] | 190 | return component; |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 191 | } |
vbhadrir | 35da0ba | 2005-06-27 20:02:56 +0000 | [diff] [blame] | 192 | |
| 193 | //returns null if the folder is already the root folder |
cbridgha | 1686f44 | 2005-03-29 20:48:41 +0000 | [diff] [blame] | 194 | public IVirtualContainer getParent() { |
cbridgha | 796d6a8 | 2005-06-28 00:23:26 +0000 | [diff] [blame] | 195 | if (getRuntimePath().segmentCount() >= 1) |
cbridgha | 632c387 | 2005-10-03 13:27:37 +0000 | [diff] [blame] | 196 | return new VirtualFolder(getProject(), getRuntimePath().removeLastSegments(1)); |
vbhadrir | 35da0ba | 2005-06-27 20:02:56 +0000 | [diff] [blame] | 197 | return null; |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 198 | } |
cbridgha | 1686f44 | 2005-03-29 20:48:41 +0000 | [diff] [blame] | 199 | |
| 200 | public IProject getProject() { |
cbridgha | 632c387 | 2005-10-03 13:27:37 +0000 | [diff] [blame] | 201 | return componentProject; |
cbridgha | 1686f44 | 2005-03-29 20:48:41 +0000 | [diff] [blame] | 202 | } |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 203 | |
| 204 | public boolean isAccessible() { |
| 205 | throw new UnsupportedOperationException("Method not supported"); //$NON-NLS-1$ |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 206 | // return false; |
| 207 | } |
| 208 | |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 209 | public Object getAdapter(Class adapter) { |
| 210 | throw new UnsupportedOperationException("Method not supported"); //$NON-NLS-1$ |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 211 | // return null; |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | public boolean contains(ISchedulingRule rule) { |
| 215 | throw new UnsupportedOperationException("Method not supported"); //$NON-NLS-1$ |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 216 | // return false; |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | public boolean isConflicting(ISchedulingRule rule) { |
| 220 | throw new UnsupportedOperationException("Method not supported"); //$NON-NLS-1$ |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 221 | // return false; |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 222 | } |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 223 | |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 224 | public String toString() { |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 225 | if (toString == null) |
cbridgha | 9be0d35 | 2005-10-03 16:01:21 +0000 | [diff] [blame] | 226 | toString = "[" + ModuleURIUtil.getHandleString(getComponent()) + ":" + getRuntimePath() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 227 | return toString; |
| 228 | } |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 229 | |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 230 | public int hashCode() { |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 231 | if (hashCode == 0) |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 232 | hashCode = toString().hashCode(); |
| 233 | return hashCode; |
| 234 | } |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 235 | |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 236 | public boolean equals(Object anOther) { |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 237 | return hashCode() == ((anOther != null && anOther instanceof VirtualResource) ? anOther.hashCode() : 0); |
cbridgha | 4da5ee7 | 2005-04-14 14:27:50 +0000 | [diff] [blame] | 238 | } |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 239 | |
| 240 | public void setResourceType(String aResourceType) { |
| 241 | resourceType = aResourceType; |
| 242 | StructureEdit moduleCore = null; |
| 243 | try { |
| 244 | moduleCore = StructureEdit.getStructureEditForRead(getProject()); |
cbridgha | 632c387 | 2005-10-03 13:27:37 +0000 | [diff] [blame] | 245 | WorkbenchComponent aComponent = moduleCore.getComponent(); |
vbhadrir | 9dd55d9 | 2005-09-08 21:46:35 +0000 | [diff] [blame] | 246 | ComponentResource[] resources = aComponent.findResourcesByRuntimePath(getRuntimePath()); |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 247 | for (int i = 0; i < resources.length; i++) { |
| 248 | resources[i].setResourceType(aResourceType); |
| 249 | } |
| 250 | } finally { |
| 251 | if (moduleCore != null) { |
| 252 | moduleCore.dispose(); |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | // TODO Fetch the resource type from the model. |
cbridgha | 4da5ee7 | 2005-04-14 14:27:50 +0000 | [diff] [blame] | 258 | public String getResourceType() { |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 259 | if (null == resourceType) { |
| 260 | StructureEdit moduleCore = null; |
| 261 | try { |
| 262 | moduleCore = StructureEdit.getStructureEditForRead(getProject()); |
cbridgha | 632c387 | 2005-10-03 13:27:37 +0000 | [diff] [blame] | 263 | WorkbenchComponent aComponent = moduleCore.getComponent(); |
vbhadrir | 9dd55d9 | 2005-09-08 21:46:35 +0000 | [diff] [blame] | 264 | ComponentResource[] resources = aComponent.findResourcesByRuntimePath(getRuntimePath()); |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 265 | for (int i = 0; i < resources.length; i++) { |
| 266 | resourceType = resources[i].getResourceType(); |
| 267 | return resourceType; |
| 268 | } |
| 269 | } finally { |
| 270 | if (moduleCore != null) { |
| 271 | moduleCore.dispose(); |
| 272 | } |
| 273 | } |
| 274 | } |
vbhadrir | 9dd55d9 | 2005-09-08 21:46:35 +0000 | [diff] [blame] | 275 | resourceType = ""; //$NON-NLS-1$ |
cbridgha | 4da5ee7 | 2005-04-14 14:27:50 +0000 | [diff] [blame] | 276 | return resourceType; |
| 277 | } |
cbridgha | 17f4e1d | 2005-03-28 19:41:04 +0000 | [diff] [blame] | 278 | |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 279 | |
cbridgha | 2550120 | 2005-03-30 23:45:41 +0000 | [diff] [blame] | 280 | protected void createResource(IContainer resource, int updateFlags, IProgressMonitor monitor) throws CoreException { |
cbridgha | 1686f44 | 2005-03-29 20:48:41 +0000 | [diff] [blame] | 281 | |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 282 | if (resource.exists()) |
vbhadrir | d384118 | 2005-06-07 17:57:08 +0000 | [diff] [blame] | 283 | return; |
cbridgha | 2550120 | 2005-03-30 23:45:41 +0000 | [diff] [blame] | 284 | if (!resource.getParent().exists()) |
| 285 | createResource(resource.getParent(), updateFlags, monitor); |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 286 | if (!resource.exists() && resource.getType() == IResource.FOLDER) { |
cbridgha | 2550120 | 2005-03-30 23:45:41 +0000 | [diff] [blame] | 287 | ((IFolder) resource).create(updateFlags, true, monitor); |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 288 | } |
cbridgha | 2550120 | 2005-03-30 23:45:41 +0000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | protected boolean isPotentalMatch(IPath aRuntimePath) { |
cbridgha | 1686f44 | 2005-03-29 20:48:41 +0000 | [diff] [blame] | 292 | return aRuntimePath.isPrefixOf(getRuntimePath()); |
| 293 | } |
cbridgha | af88ca6 | 2005-06-24 19:00:16 +0000 | [diff] [blame] | 294 | |
cbridgha | e26159c | 2005-12-06 04:14:47 +0000 | [diff] [blame] | 295 | /* (non-Javadoc) |
| 296 | * @see org.eclipse.wst.common.componentcore.resources.IVirtualResource#removeLink(org.eclipse.core.runtime.IPath, int, org.eclipse.core.runtime.IProgressMonitor) |
| 297 | */ |
| 298 | public void removeLink(IPath aProjectRelativeLocation, int updateFlags, IProgressMonitor monitor) throws CoreException { |
| 299 | StructureEdit moduleCore = null; |
| 300 | try { |
| 301 | moduleCore = StructureEdit.getStructureEditForWrite(getProject()); |
| 302 | WorkbenchComponent component = moduleCore.getComponent(); |
| 303 | ResourceTreeRoot root = ResourceTreeRoot.getDeployResourceTreeRoot(component); |
| 304 | ComponentResource[] resources = root.findModuleResources(getRuntimePath(), ResourceTreeNode.CREATE_NONE); |
| 305 | if (resources.length > 0) { |
| 306 | for (int resourceIndx = 0; resourceIndx < resources.length; resourceIndx++) { |
| 307 | if (aProjectRelativeLocation.makeAbsolute().equals(resources[resourceIndx].getSourcePath())) { |
| 308 | component.getResources().remove(resources[resourceIndx]); |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | } finally { |
| 313 | if (moduleCore != null) { |
| 314 | moduleCore.saveIfNecessary(monitor); |
| 315 | moduleCore.dispose(); |
| 316 | } |
| 317 | } |
| 318 | } |
cbridgha | 6887f4d | 2005-03-23 15:10:33 +0000 | [diff] [blame] | 319 | } |