1 11 package org.eclipse.ui.internal.ide.model; 12 13 import org.eclipse.core.commands.operations.IUndoContext; 14 import org.eclipse.core.resources.IMarker; 15 import org.eclipse.core.resources.IResource; 16 import org.eclipse.core.resources.IWorkspace; 17 import org.eclipse.core.resources.IWorkspaceRoot; 18 import org.eclipse.core.runtime.IAdapterFactory; 19 import org.eclipse.ui.IActionFilter; 20 import org.eclipse.ui.IElementFactory; 21 import org.eclipse.ui.IPersistableElement; 22 import org.eclipse.ui.PlatformUI; 23 import org.eclipse.ui.model.IWorkbenchAdapter; 24 25 30 class WorkbenchAdapterFactory implements IAdapterFactory { 31 private Object workspaceAdapter = new WorkbenchWorkspace(); 32 33 private Object rootAdapter = new WorkbenchRootResource(); 34 35 private Object projectAdapter = new WorkbenchProject(); 36 37 private Object folderAdapter = new WorkbenchFolder(); 38 39 private Object fileAdapter = new WorkbenchFile(); 40 41 private Object markerAdapter = new WorkbenchMarker(); 42 43 private Object resourceFactory = new ResourceFactory(); 44 45 private Object workspaceFactory = new WorkspaceFactory(); 46 47 50 protected Object getActionFilter(Object o) { 51 if (o instanceof IResource) { 52 switch (((IResource) o).getType()) { 53 case IResource.FILE: 54 return fileAdapter; 55 case IResource.FOLDER: 56 return folderAdapter; 57 case IResource.PROJECT: 58 return projectAdapter; 59 } 60 } 61 if (o instanceof IMarker) { 62 return markerAdapter; 63 } 64 return null; 65 } 66 67 80 public Object getAdapter(Object o, Class adapterType) { 81 if (adapterType.isInstance(o)) { 82 return o; 83 } 84 if (adapterType == IWorkbenchAdapter.class) { 85 return getWorkbenchElement(o); 86 } 87 if (adapterType == IPersistableElement.class) { 88 return getPersistableElement(o); 89 } 90 if (adapterType == IElementFactory.class) { 91 return getElementFactory(o); 92 } 93 if (adapterType == IActionFilter.class) { 94 return getActionFilter(o); 95 } 96 if (adapterType == IUndoContext.class) { 97 return getUndoContext(o); 98 } 99 return null; 100 } 101 102 113 public Class [] getAdapterList() { 114 return new Class [] { IWorkbenchAdapter.class, IElementFactory.class, 115 IPersistableElement.class, IActionFilter.class, IUndoContext.class }; 116 } 117 118 123 protected Object getElementFactory(Object o) { 124 if (o instanceof IResource) { 125 return resourceFactory; 126 } 127 if (o instanceof IWorkspace) { 128 return workspaceFactory; 129 } 130 return null; 131 } 132 133 138 protected Object getPersistableElement(Object o) { 139 if (o instanceof IResource) { 140 return new ResourceFactory((IResource) o); 141 } 142 if (o instanceof IWorkspace) { 143 return workspaceFactory; 144 } 145 return null; 146 } 147 148 153 protected Object getWorkbenchElement(Object o) { 154 if (o instanceof IResource) { 155 switch (((IResource) o).getType()) { 156 case IResource.FILE: 157 return fileAdapter; 158 case IResource.FOLDER: 159 return folderAdapter; 160 case IResource.PROJECT: 161 return projectAdapter; 162 } 163 } 164 if (o instanceof IWorkspaceRoot) { 165 return rootAdapter; 166 } 167 if (o instanceof IWorkspace) { 168 return workspaceAdapter; 169 } 170 if (o instanceof IMarker) { 171 return markerAdapter; 172 } 173 return null; 174 } 175 176 179 protected Object getUndoContext(Object o) { 180 if (o instanceof IWorkspace) { 181 return PlatformUI.getWorkbench().getOperationSupport().getUndoContext(); 182 } 183 return null; 184 } 185 } 186 | Popular Tags |