public void dispose() {
listenerList = null;
}
public Object execute(final ExecutionEvent event) throws ExecutionException {
EOModelEditor modelEditor = null;
final List<IResource> files = new ArrayList<IResource>();
if (event.getParameter(PARAM_ID_FILE_PATH) == null) {
// Prompt the user for the resource to open.
Object[] result = queryFileResource();
if (result != null) {
if (result.length == 2 && result[0] instanceof EOModelEditor) {
modelEditor = (EOModelEditor)result[0];
result = (Object[])result[1];
}
if (result != null) {
for (int i = 0; i < result.length; i++) {
files.add((IResource)result[i]);
}
}
}
} else {
// Use the given parameter.
final IResource resource = (IResource) event.getObjectParameterForExecution(PARAM_ID_FILE_PATH);
if (!(resource instanceof IFile)) {
throw new ExecutionException("filePath parameter must identify a file"); //$NON-NLS-1$
}
files.add(resource);
}
if (files.size() > 0) {
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
throw new ExecutionException("no active workbench window"); //$NON-NLS-1$
}
final IWorkbenchPage page = window.getActivePage();
if (page == null) {
throw new ExecutionException("no active workbench page"); //$NON-NLS-1$
}
for (Iterator it = files.iterator(); it.hasNext();) {
IResource resource = (IResource)it.next();
IFile file = null;
if (!"eomodeld".equals(resource.getFileExtension()) && resource instanceof IFile) {
if (modelEditor != null) {
EOEntity entity = modelEditor.getModel().getModelGroup().getEntityNamed(ResourceUtilities.getFileNameWithoutExtension(resource));
if (entity != null) {
modelEditor.setSelection(new StructuredSelection(entity));
}
}
else {
file = (IFile)resource;//resource.getParent().getFile(new Path("index.eomodeld"));
OpenEntityModelerAction.openResourceIfPossible(null, file);
}
}
else if (resource instanceof IContainer) {
if (modelEditor != null) {
EOModel model = modelEditor.getModel().getModelGroup().getModelNamed(ResourceUtilities.getFileNameWithoutExtension(resource.getName()));
if (model != null) {
modelEditor.setSelection(new StructuredSelection(model));
}
}
else {
file = ((IContainer)resource).getFile(new Path("index.eomodeld"));
OpenEntityModelerAction.openResourceIfPossible(null, file);