Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcbridgha2004-12-06 22:10:36 +0000
committercbridgha2004-12-06 22:10:36 +0000
commit7b3a67259a1c6d280c754b4d5df7addd75e1db73 (patch)
treeafef28669318f47c9a16799785b37b084e874348 /plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration
parent82ae7d1d41e267abdc03c517fc6abe8a10f49328 (diff)
downloadwebtools.javaee-7b3a67259a1c6d280c754b4d5df7addd75e1db73.tar.gz
webtools.javaee-7b3a67259a1c6d280c754b4d5df7addd75e1db73.tar.xz
webtools.javaee-7b3a67259a1c6d280c754b4d5df7addd75e1db73.zip
jst plugin refactor
Diffstat (limited to 'plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration')
-rw-r--r--plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/JavaInsertionHelper.java176
-rw-r--r--plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/JavaProjectCreationDataModel.java139
-rw-r--r--plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/JavaProjectCreationOperation.java64
-rw-r--r--plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/JavaProjectValidationHandler.java55
-rw-r--r--plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/WTPWorkingCopyManager.java533
-rw-r--r--plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/WorkingCopyManager.java49
-rw-r--r--plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/WorkingCopyManagerFactory.java57
-rw-r--r--plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/WorkingCopyProvider.java60
8 files changed, 1133 insertions, 0 deletions
diff --git a/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/JavaInsertionHelper.java b/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/JavaInsertionHelper.java
new file mode 100644
index 000000000..abab902bb
--- /dev/null
+++ b/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/JavaInsertionHelper.java
@@ -0,0 +1,176 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.common.jdt.internal.integration;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jdt.core.jdom.DOMFactory;
+import org.eclipse.wst.common.frameworks.internal.operations.IHeadlessRunnableWithProgress;
+
+
+/**
+ * @author DABERG
+ *
+ * This class is used by the Java snippet support to capture the insertionString that is to be
+ * inserted at the users selection point. It also provides the ability to define additional fields
+ * and methods to support the insertionString.
+ */
+public class JavaInsertionHelper {
+ protected DOMFactory domFactory = new DOMFactory();
+ protected List fields;
+ protected List methods;
+ protected List imports;
+ protected String insertionString;
+ protected List extendedOperations;
+
+ /**
+ *
+ */
+ public JavaInsertionHelper() {
+ super();
+ }
+
+ /**
+ * @return
+ */
+ public List getFields() {
+ return fields;
+ }
+
+ /**
+ * @return
+ */
+ public String getInsertionString() {
+ return insertionString;
+ }
+
+ /**
+ * @return
+ */
+ public List getMethods() {
+ return methods;
+ }
+
+ /**
+ * This is required to be set by the client. This is the String that will be inserted at the
+ * users selection point.
+ *
+ * @param string
+ */
+ public void setInsertionString(String string) {
+ insertionString = string;
+ }
+
+ /**
+ * This is a utility method that will parse the methodString and create a IDOMMethod. The
+ * DOMFactory will be used to create the method. This new method will be added to the list of
+ * methods.
+ *
+ * @param methodString
+ * @see DOMFactory#createMethod(java.lang.String)
+ * @link org.eclipse.jdt.core.jdom.IDOMMethod
+ */
+ public void addMethodFromSourceString(String methodString) {
+ if (methodString != null && methodString.length() > 0) {
+ if (methods == null)
+ methods = new ArrayList();
+ methods.add(domFactory.createMethod(methodString));
+ }
+ }
+
+ /**
+ * This is a utility method that will parse the fieldString and create a IDOMField. The
+ * DOMFactory will be used to create the field. This new field will be added to the list of
+ * fields.
+ *
+ * @param fieldString
+ * @see DOMFactory#createField(java.lang.String)
+ * @link org.eclipse.jdt.core.jdom.IDOMField
+ */
+ public void addFieldFromSourceString(String fieldString) {
+ if (fieldString != null && fieldString.length() > 0) {
+ if (fields == null)
+ fields = new ArrayList();
+ fields.add(domFactory.createField(fieldString));
+ }
+ }
+
+ /**
+ * Add an import that is either the qualified name of a type or a package name with .* at the
+ * end.
+ *
+ * @param importString
+ */
+ public void addImport(String importString) {
+ if (importString != null && importString.length() > 0) {
+ if (imports == null)
+ imports = new ArrayList();
+ imports.add(importString);
+ }
+ }
+
+ /**
+ * Return true if the insertionString is set and not a zero length.
+ *
+ * @return
+ */
+ public boolean canInsertText() {
+ return insertionString != null && insertionString.length() > 0;
+ }
+
+ /**
+ * @return
+ */
+ public boolean hasFields() {
+ return fields != null && !fields.isEmpty();
+ }
+
+ /**
+ * @return
+ */
+ public boolean hasMethods() {
+ return methods != null && !methods.isEmpty();
+ }
+
+ public boolean hasImports() {
+ return imports != null && !imports.isEmpty();
+ }
+
+ /**
+ * @return Returns the imports.
+ */
+ public List getImportStatements() {
+ return imports;
+ }
+
+ /**
+ * @return Returns the extendedOperations.
+ */
+ public List getExtendedOperations() {
+ return extendedOperations;
+ }
+
+ /**
+ * This method allows you to add additional operations which will be performed after this
+ * JavaInsertionHelper is processed by the JavaInsertionOperation.
+ *
+ * @param operation
+ * @link JavaInsertionOperation
+ */
+ public void addExtendedOperation(IHeadlessRunnableWithProgress operation) {
+ if (operation != null) {
+ if (extendedOperations == null)
+ extendedOperations = new ArrayList();
+ extendedOperations.add(operation);
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/JavaProjectCreationDataModel.java b/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/JavaProjectCreationDataModel.java
new file mode 100644
index 000000000..7088bc6df
--- /dev/null
+++ b/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/JavaProjectCreationDataModel.java
@@ -0,0 +1,139 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+/*
+ * Created on Nov 4, 2003
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+package org.eclipse.jst.common.jdt.internal.integration;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.wst.common.frameworks.internal.operations.ProjectCreationDataModel;
+import org.eclipse.wst.common.frameworks.internal.operations.WTPOperation;
+
+
+/**
+ * @author jsholl
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class JavaProjectCreationDataModel extends ProjectCreationDataModel {
+
+ /**
+ * Optional, type String []. These names are relative.
+ */
+ public static final String SOURCE_FOLDERS = "JavaProjectCreationDataModel.SOURCE_FOLDERS"; //$NON-NLS-1$
+ /**
+ * Optional, type Boolean default is True
+ */
+ public static final String CREATE_SOURCE_FOLDERS = "JavaProjectCreationDataModel.CREATE_SOURCE_FOLDERS"; //$NON-NLS-1$
+
+
+ /**
+ * Optional, type IClasspathEntry[]
+ */
+ public static final String CLASSPATH_ENTRIES = "JavaProjectCreationDataModel.CLASSPATH_ENTRIES"; //$NON-NLS-1$
+
+ /**
+ * Optional, type String
+ */
+ public static final String OUTPUT_LOCATION = "JavaProjectCreationDataModel.OUTPUT_LOCATION"; //$NON-NLS-1$
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperationDataModel#getDefaultOperation()
+ */
+ public WTPOperation getDefaultOperation() {
+ return new JavaProjectCreationOperation(this);
+ }
+
+ protected void initValidBaseProperties() {
+ super.initValidBaseProperties();
+ addValidBaseProperty(OUTPUT_LOCATION);
+ addValidBaseProperty(SOURCE_FOLDERS);
+ addValidBaseProperty(CLASSPATH_ENTRIES);
+ addValidBaseProperty(CREATE_SOURCE_FOLDERS);
+ }
+
+ protected Object getDefaultProperty(String propertyName) {
+ // TODO pull these from the java preferences
+ if (propertyName.equals(OUTPUT_LOCATION)) {
+ return "bin"; //$NON-NLS-1$
+ }
+ if (propertyName.equals(SOURCE_FOLDERS)) {
+ return new String[]{"src"}; //$NON-NLS-1$
+ }
+ if (propertyName.equals(CREATE_SOURCE_FOLDERS))
+ return Boolean.TRUE;
+ return super.getDefaultProperty(propertyName);
+ }
+
+ public IPath getOutputPath() {
+ String outputLocation = getStringProperty(OUTPUT_LOCATION);
+ return getProject().getFullPath().append(outputLocation);
+ }
+
+ public IClasspathEntry[] getClasspathEntries() {
+ IClasspathEntry[] entries = (IClasspathEntry[]) getProperty(CLASSPATH_ENTRIES);
+ IClasspathEntry[] sourceEntries = null;
+ if (getBooleanProperty(CREATE_SOURCE_FOLDERS))
+ sourceEntries = getSourceClasspathEntries();
+ return combineArrays(sourceEntries, entries);
+ }
+
+ /**
+ * @param sourceEntries
+ * @param entries
+ * @return
+ */
+ private IClasspathEntry[] combineArrays(IClasspathEntry[] sourceEntries, IClasspathEntry[] entries) {
+ if (sourceEntries != null) {
+ if (entries == null)
+ return sourceEntries;
+ return doCombineArrays(sourceEntries, entries);
+ } else if (entries != null)
+ return entries;
+ return new IClasspathEntry[0];
+ }
+
+ /**
+ * @param sourceEntries
+ * @param entries
+ * @return
+ */
+ private IClasspathEntry[] doCombineArrays(IClasspathEntry[] sourceEntries, IClasspathEntry[] entries) {
+ IClasspathEntry[] result = new IClasspathEntry[sourceEntries.length + entries.length];
+ System.arraycopy(sourceEntries, 0, result, 0, sourceEntries.length);
+ System.arraycopy(entries, 0, result, sourceEntries.length, entries.length);
+ return result;
+ }
+
+ private IClasspathEntry[] getSourceClasspathEntries() {
+ String[] sourceFolders = (String[]) getProperty(SOURCE_FOLDERS);
+ ArrayList list = new ArrayList();
+ for (int i = 0; i < sourceFolders.length; i++) {
+ list.add(JavaCore.newSourceEntry(getProject().getFullPath().append(sourceFolders[i])));
+ }
+ IClasspathEntry[] classpath = new IClasspathEntry[list.size()];
+ for (int i = 0; i < classpath.length; i++) {
+ classpath[i] = (IClasspathEntry) list.get(i);
+ }
+ return classpath;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/JavaProjectCreationOperation.java b/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/JavaProjectCreationOperation.java
new file mode 100644
index 000000000..90f7f9542
--- /dev/null
+++ b/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/JavaProjectCreationOperation.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+/*
+ * Created on Nov 4, 2003
+ *
+ * To change the template for this generated file go to
+ * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
+ */
+package org.eclipse.jst.common.jdt.internal.integration;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.wst.common.frameworks.internal.WTPProjectUtilities;
+import org.eclipse.wst.common.frameworks.internal.operations.ProjectCreationOperation;
+
+
+/**
+ * @author jsholl
+ *
+ * To change the template for this generated type comment go to
+ * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
+ */
+public class JavaProjectCreationOperation extends ProjectCreationOperation {
+
+ public JavaProjectCreationOperation(JavaProjectCreationDataModel dataModel) {
+ super(dataModel);
+ }
+
+ protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
+ super.execute(monitor);
+ createJavaProject(monitor);
+ }
+
+ private void createJavaProject(IProgressMonitor monitor) throws CoreException {
+ JavaProjectCreationDataModel model = (JavaProjectCreationDataModel) operationDataModel;
+ IProject project = model.getProject();
+ WTPProjectUtilities.addNatureToProjectLast(project, JavaCore.NATURE_ID);
+ IJavaProject javaProject = JavaCore.create(project);
+ javaProject.setOutputLocation(model.getOutputPath(), monitor);
+ javaProject.setRawClasspath(model.getClasspathEntries(), monitor);
+ if (model.getBooleanProperty(JavaProjectCreationDataModel.CREATE_SOURCE_FOLDERS)) {
+ String[] sourceFolders = (String[]) model.getProperty(JavaProjectCreationDataModel.SOURCE_FOLDERS);
+ IFolder folder = null;
+ for (int i = 0; i < sourceFolders.length; i++) {
+ folder = project.getFolder(sourceFolders[i]);
+ folder.create(true, true, monitor);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/JavaProjectValidationHandler.java b/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/JavaProjectValidationHandler.java
new file mode 100644
index 000000000..a5f04ebd2
--- /dev/null
+++ b/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/JavaProjectValidationHandler.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.jst.common.jdt.internal.integration;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.wst.common.frameworks.internal.IValidationSelectionHandler;
+
+/**
+ * Java Project validation
+ */
+public class JavaProjectValidationHandler implements IValidationSelectionHandler {
+
+ private String validationType = null;
+
+ /**
+ * Default constructor
+ */
+ public JavaProjectValidationHandler() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.common.frameworks.internal.IValidationSelectionHandler#getBaseValidationType(java.lang.Object)
+ */
+ public IResource getBaseValidationType(Object selection) {
+ if (selection instanceof IJavaProject)
+ return ((IJavaProject)selection).getProject();
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.common.frameworks.internal.IValidationSelectionHandler#getValidationTypeString()
+ */
+ public String getValidationTypeString() {
+ return validationType;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.common.frameworks.internal.IValidationSelectionHandler#setValidationTypeString(java.lang.String)
+ */
+ public void setValidationTypeString(String validationType) {
+ this.validationType = validationType;
+ }
+
+}
diff --git a/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/WTPWorkingCopyManager.java b/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/WTPWorkingCopyManager.java
new file mode 100644
index 000000000..065b228c8
--- /dev/null
+++ b/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/WTPWorkingCopyManager.java
@@ -0,0 +1,533 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.common.jdt.internal.integration;
+
+
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.internal.resources.Workspace;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.wst.common.frameworks.internal.ISaveHandler;
+import org.eclipse.wst.common.frameworks.internal.SaveFailedException;
+import org.eclipse.wst.common.frameworks.internal.SaveHandlerHeadless;
+import org.eclipse.wst.common.frameworks.internal.SaveHandlerRegister;
+import org.eclispe.wst.common.frameworks.internal.plugin.WTPCommonPlugin;
+
+import com.ibm.wtp.common.logger.proxy.Logger;
+
+/**
+ * Insert the type's description here. Creation date: (4/27/2001 4:14:30 PM)
+ *
+ * @author: Administrator
+ */
+public class WTPWorkingCopyManager implements WorkingCopyManager {
+
+ //New CUs that will need to be deleted upon dispose
+ private List originalNewCompilationUnits;
+ //New CUs that were created that need saved immediately (after each gen)
+ private List needsSavingCompilationUnits;
+ //A complete list of new CUs that is only cleared on save and dispose
+ private List newCompilationUnits;
+ private HashMap deletedCompilationUnits;
+ protected static final Class IRESOURCE_CLASS = IResource.class;
+
+ /**
+ * WTPWorkingCopyManager constructor comment.
+ */
+ public WTPWorkingCopyManager() {
+ super();
+ }
+
+ protected void addDeletedCompilationUnit(ICompilationUnit cu) {
+ getNeedsSavingCompilationUnits().remove(cu);
+ if (!getOriginalNewCompilationUnits().contains(cu) && !getDeletedCompilationUnits().containsKey(cu))
+ primAddDeletedCompilationUnit(cu);
+ getOriginalNewCompilationUnits().remove(cu);
+ }
+
+ protected void addNewCompilationUnit(ICompilationUnit cu, ICompilationUnit workingCopy) {
+ getNewCompilationUnits().add(cu);
+ getNeedsSavingCompilationUnits().add(workingCopy);
+ if (!getDeletedCompilationUnits().containsKey(cu))
+ getOriginalNewCompilationUnits().add(cu);
+ }
+
+ /**
+ * This will save all of the new CompilationUnits to be saved.
+ */
+ protected void commitWorkingCopy(ICompilationUnit wc, IProgressMonitor monitor) {
+ try {
+ try {
+ wc.commitWorkingCopy(false, monitor);
+ } catch (JavaModelException e) {
+ if (isFailedWriteFileFailure(e) && shouldSaveReadOnly(wc))
+ wc.commitWorkingCopy(false, monitor);
+ else
+ throw e;
+ }
+ } catch (JavaModelException e) {
+ com.ibm.wtp.common.logger.proxy.Logger.getLogger().logError(e);
+ throw new SaveFailedException(e);
+ } finally {
+ try {
+ wc.discardWorkingCopy();
+ } catch (JavaModelException e1) {
+ com.ibm.wtp.common.logger.proxy.Logger.getLogger().logError(e1);
+ throw new SaveFailedException(e1);
+ }
+ }
+ }
+
+ /**
+ * This will delete
+ *
+ * @cu from the workbench and fix the internal references for this working copy manager.
+ */
+ public void delete(ICompilationUnit cu, IProgressMonitor monitor) {
+ if (cu.isWorkingCopy())
+ cu = cu.getPrimary();
+ addDeletedCompilationUnit(cu);
+ try {
+ cu.delete(false, monitor);
+ } catch (JavaModelException e) {
+ if (e.getStatus().getCode() != org.eclipse.jdt.core.IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST)
+ com.ibm.wtp.common.logger.proxy.Logger.getLogger().logError(e);
+ }
+ }
+
+ protected void discardOriginalNewCompilationUnits() {
+ if (getOriginalNewCompilationUnits().isEmpty())
+ return;
+ List cus = getOriginalNewCompilationUnits();
+ ICompilationUnit cu;
+ ICompilationUnit wc = null;
+ for (int i = 0; i < cus.size(); i++) {
+ cu = (ICompilationUnit) cus.get(i);
+ if (cu.isWorkingCopy()) {
+ wc = cu;
+ cu = wc.getPrimary();
+ }
+ primDelete(cu);
+ if (wc != null)
+ try {
+ wc.discardWorkingCopy();
+ } catch (JavaModelException e) {
+ Logger.getLogger().logError(e);
+ }
+ }
+ }
+
+ public void dispose() {
+ IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
+ public void run(IProgressMonitor aMonitor) {
+ primDispose();
+ }
+ };
+ runOperation(runnable, null, true);
+ }
+
+ public void revert() {
+ IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
+ public void run(IProgressMonitor aMonitor) {
+ primRevert();
+ }
+ };
+ runOperation(runnable, null, true);
+ }
+
+ public Set getAffectedFiles() {
+ return Collections.EMPTY_SET;
+ }
+
+ /**
+ * Insert the method's description here. Creation date: (7/11/2001 6:43:37 PM)
+ *
+ * @return java.util.HashMap
+ */
+ protected HashMap getDeletedCompilationUnits() {
+ if (deletedCompilationUnits == null)
+ deletedCompilationUnits = new HashMap();
+ return deletedCompilationUnits;
+ }
+
+ /**
+ * Returns the working copy remembered for the compilation unit encoded in the given editor
+ * input. Does not connect the edit model to the working copy.
+ *
+ * @param input
+ * ICompilationUnit
+ * @return the working copy of the compilation unit, or <code>null</code> if the input does
+ * not encode an editor input, or if there is no remembered working copy for this
+ * compilation unit
+ */
+ public org.eclipse.jdt.core.ICompilationUnit getExistingWorkingCopy(ICompilationUnit cu) throws CoreException {
+ ICompilationUnit newCU = getNewCompilationUnitWorkingCopy(cu);
+ if (newCU != null)
+ return newCU;
+ return null;
+ }
+
+ /**
+ * Insert the method's description here. Creation date: (7/19/2001 11:00:19 AM)
+ *
+ * @return java.util.List
+ */
+ protected java.util.List getNeedsSavingCompilationUnits() {
+ if (needsSavingCompilationUnits == null)
+ needsSavingCompilationUnits = new ArrayList();
+ return needsSavingCompilationUnits;
+ }
+
+ /**
+ * Insert the method's description here. Creation date: (4/26/2001 3:49:05 PM)
+ *
+ * @return java.util.List
+ */
+ protected java.util.List getNewCompilationUnits() {
+ if (newCompilationUnits == null)
+ newCompilationUnits = new ArrayList();
+ return newCompilationUnits;
+ }
+
+ /**
+ * It is possible that we have already created this CompilationUnit and its working copy. If
+ * this is the case, return our new working copy and do not create a new one.
+ */
+ protected ICompilationUnit getNewCompilationUnitWorkingCopy(ICompilationUnit cu) {
+ if (hasNewCompilationUnit(cu)) {
+ List list = getNeedsSavingCompilationUnits();
+ ICompilationUnit copy;
+ for (int i = 0; i < list.size(); i++) {
+ copy = (ICompilationUnit) list.get(i);
+ if (cu.equals(copy.getPrimary()))
+ return copy;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Insert the method's description here. Creation date: (4/26/2001 3:49:05 PM)
+ *
+ * @return java.util.List
+ */
+ protected java.util.List getOriginalNewCompilationUnits() {
+ if (originalNewCompilationUnits == null)
+ originalNewCompilationUnits = new ArrayList();
+ return originalNewCompilationUnits;
+ }
+
+ /**
+ * Return the IPackageFragment for the given ICompilationUnit.
+ */
+ protected IPackageFragment getPackageFragment(ICompilationUnit cu) {
+ if (cu == null)
+ return null;
+ IJavaElement parent = cu;
+ int elementType = cu.getElementType();
+ while (parent != null && elementType != IJavaElement.PACKAGE_FRAGMENT) {
+ parent = parent.getParent();
+ if (parent != null)
+ elementType = parent.getElementType();
+ else
+ elementType = -1;
+ }
+ return (IPackageFragment) parent;
+ }
+
+ protected ISaveHandler getSaveHandler() {
+ return SaveHandlerRegister.getSaveHandler();
+ }
+
+ /**
+ * Returns the working copy remembered for the compilation unit.
+ *
+ * @param input
+ * ICompilationUnit
+ * @return the working copy of the compilation unit, or <code>null</code> if there is no
+ * remembered working copy for this compilation unit
+ */
+ public ICompilationUnit getWorkingCopy(ICompilationUnit cu, boolean forNewCU) throws org.eclipse.core.runtime.CoreException {
+ if (cu == null || cu.isWorkingCopy())
+ return cu;
+ ICompilationUnit newCU = getNewCompilationUnitWorkingCopy(cu);
+ if (newCU != null)
+ return newCU;
+ ICompilationUnit workingCopy = cu.getWorkingCopy(null);
+ addNewCompilationUnit(cu, workingCopy);
+ return workingCopy;
+ }
+
+ /**
+ * Has a new compilation unit already been created.
+ */
+ protected boolean hasNewCompilationUnit(ICompilationUnit cu) {
+ return getNewCompilationUnits().contains(cu);
+ }
+
+ protected boolean isFailedWriteFileFailure(Exception ex) {
+ return SaveHandlerHeadless.isFailedWriteFileFailure(ex);
+ }
+
+ protected void primAddDeletedCompilationUnit(ICompilationUnit cu) {
+ if (cu == null)
+ return;
+ Object[] info = new Object[2];
+ info[0] = getPackageFragment(cu);
+ try {
+ info[1] = cu.getSource();
+ } catch (JavaModelException e) {
+ info[1] = null;
+ }
+ getDeletedCompilationUnits().put(cu, info);
+ }
+
+ // This is an internal delete call.
+ protected void primDelete(ICompilationUnit cu) {
+ try {
+ if (cu.exists())
+ cu.delete(true, new org.eclipse.core.runtime.NullProgressMonitor());
+ } catch (JavaModelException e) {
+ com.ibm.wtp.common.logger.proxy.Logger.getLogger().logError(e);
+ //What to do here?
+ }
+ }
+
+ protected void primDispose() {
+ discardOriginalNewCompilationUnits();
+ reviveDeletedCompilationUnits();
+ newCompilationUnits = null;
+ needsSavingCompilationUnits = null;
+ originalNewCompilationUnits = null;
+ deletedCompilationUnits = null;
+ }
+
+ protected void primRevert() {
+ discardOriginalNewCompilationUnits();
+ reviveDeletedCompilationUnits();
+ newCompilationUnits = null;
+ needsSavingCompilationUnits = null;
+ originalNewCompilationUnits = null;
+ deletedCompilationUnits = null;
+ }
+
+ /**
+ * Returns the working copy remembered for the compilation unit encoded in the given editor
+ * input.
+ *
+ * @param input
+ * ICompilationUnit
+ * @return the working copy of the compilation unit, or <code>null</code> if the input does
+ * not encode an editor input, or if there is no remembered working copy for this
+ * compilation unit
+ */
+ protected org.eclipse.jdt.core.ICompilationUnit primGetWorkingCopy(ICompilationUnit cu) throws CoreException {
+ return null;
+ }
+
+ /**
+ * This will save all of the referenced CompilationUnits to be saved.
+ */
+ protected void primSaveCompilationUnits(org.eclipse.core.runtime.IProgressMonitor monitor) {
+ saveNewCompilationUnits(monitor);
+ getDeletedCompilationUnits().clear();
+ }
+
+ /**
+ * This will save all of the new CompilationUnits to be saved.
+ */
+ protected void primSaveOnlyNewCompilationUnits(org.eclipse.core.runtime.IProgressMonitor monitor) {
+ List cus = getNeedsSavingCompilationUnits();
+ ICompilationUnit wc;
+ for (int i = 0; i < cus.size(); i++) {
+ wc = (ICompilationUnit) cus.get(i);
+ commitWorkingCopy(wc, monitor);
+ }
+ cus.clear();
+ }
+
+ protected void removeDeletedCompilationUnit(ICompilationUnit cu) {
+ if (getDeletedCompilationUnits().remove(cu) != null) {
+ if (cu.isWorkingCopy()) {
+ ICompilationUnit original, nextCU, testCU;
+ original = cu.getPrimary();
+ Set cus = getDeletedCompilationUnits().keySet();
+ Iterator it = cus.iterator();
+ while (it.hasNext()) {
+ nextCU = (ICompilationUnit) it.next();
+ testCU = nextCU.isWorkingCopy() ? (ICompilationUnit) nextCU.getPrimary() : nextCU;
+ if (testCU.equals(original)) {
+ cus.remove(nextCU);
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ protected void reviveDeletedCompilationUnit(ICompilationUnit cu, Object[] info, IProgressMonitor pm) {
+ if (info[0] != null && info[1] != null) {
+ String typeName = cu.getElementName();
+ IPackageFragment pack = (IPackageFragment) info[0];
+ String source = (String) info[1];
+ try {
+ ICompilationUnit existingCU = pack.getCompilationUnit(typeName);
+ if (existingCU.exists() && getNewCompilationUnits().contains(existingCU))
+ existingCU.delete(false, pm);
+ pack.createCompilationUnit(typeName, source, false, pm);
+ } catch (JavaModelException e) {
+ com.ibm.wtp.common.logger.proxy.Logger.getLogger().logError(e);
+ }
+ }
+ }
+
+ protected void reviveDeletedCompilationUnits() {
+ if (getDeletedCompilationUnits().isEmpty())
+ return;
+ IProgressMonitor pm = new org.eclipse.core.runtime.NullProgressMonitor();
+ Iterator it = getDeletedCompilationUnits().entrySet().iterator();
+ Map.Entry entry;
+ ICompilationUnit cu;
+ Object[] info;
+ while (it.hasNext()) {
+ entry = (Map.Entry) it.next();
+ cu = (ICompilationUnit) entry.getKey();
+ info = (Object[]) entry.getValue();
+ reviveDeletedCompilationUnit(cu, info, pm);
+ }
+
+ }
+
+ protected void runOperation(IWorkspaceRunnable aRunnable, IProgressMonitor monitor, boolean validate) {
+ primRunOperation(aRunnable, monitor);
+
+ // TODO Break the validator depedency
+ // if (validate)
+ // primRunOperation(aRunnable, monitor);
+ // else {
+ // IProject proj = getValidationProject();
+ //
+ // ValidatorManager mgr = ValidatorManager.getManager();
+ // boolean disableValidators = proj != null;
+ // boolean wasSuspended = false;
+ // if (disableValidators) {
+ // wasSuspended = mgr.isSuspended(proj);
+ // if (!wasSuspended)
+ // mgr.suspendValidation(proj, true);
+ // }
+ // try {
+ // primRunOperation(aRunnable, monitor);
+ // } finally {
+ // if (disableValidators && !wasSuspended)
+ // mgr.suspendValidation(proj, false);
+ // }
+ // }
+ }
+
+ protected void primRunOperation(IWorkspaceRunnable aRunnable, IProgressMonitor monitor) {
+ Workspace workspace = (Workspace) WTPCommonPlugin.getWorkspace();
+ if (aRunnable != null) {
+ //if (workspace.isTreeLocked())
+ //Logger.getLogger().logTrace(ResourceHandler.getString("Cannot_run_J2EEUIWorkingCo_ERROR_"));
+ // //$NON-NLS-1$ = "Cannot run J2EEUIWorkingCopyManager operation because the Workspace
+ // tree is locked."
+ //else {
+ if (!workspace.isTreeLocked()) {
+ try {
+ WTPCommonPlugin.getWorkspace().run(aRunnable, monitor);
+ } catch (CoreException e) {
+ throw new SaveFailedException(e);
+ }
+ }
+ }
+ }
+
+ /**
+ * This will save all of the referenced CompilationUnits to be saved.
+ */
+ public void saveCompilationUnits(org.eclipse.core.runtime.IProgressMonitor monitor) {
+ getSaveHandler().access();
+ try {
+ IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
+ public void run(IProgressMonitor aMonitor) {
+ primSaveCompilationUnits(aMonitor);
+ }
+ };
+ runOperation(runnable, monitor, true);
+ } catch (SaveFailedException ex) {
+ getSaveHandler().handleSaveFailed(ex, monitor);
+ } finally {
+ getSaveHandler().release();
+ }
+ }
+
+ /**
+ * This will save all of the referenced CompilationUnits to be saved.
+ */
+ protected void saveNewCompilationUnits(IProgressMonitor monitor) {
+ primSaveOnlyNewCompilationUnits(monitor);
+ getOriginalNewCompilationUnits().clear();
+ getNewCompilationUnits().clear();
+ }
+
+ /**
+ * This will save all of the new CompilationUnits to be saved.
+ */
+ public void saveOnlyNewCompilationUnits(org.eclipse.core.runtime.IProgressMonitor monitor) {
+ getSaveHandler().access();
+ try {
+ IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
+ public void run(IProgressMonitor aMonitor) {
+ primSaveOnlyNewCompilationUnits(aMonitor);
+ }
+ };
+ runOperation(runnable, monitor, false);
+ } catch (SaveFailedException ex) {
+ getSaveHandler().handleSaveFailed(ex, monitor);
+ } finally {
+ getSaveHandler().release();
+ }
+ }
+
+ protected boolean shouldSaveReadOnly(ICompilationUnit wc) {
+ IResource resource = null;
+
+ resource = (IResource) wc.getPrimary().getAdapter(IRESOURCE_CLASS);
+
+ if (resource == null || resource.getType() != IResource.FILE || !resource.isReadOnly())
+ return false;
+
+ return getSaveHandler().shouldContinueAndMakeFileEditable((IFile) resource);
+ }
+
+ /**
+ * @see com.ibm.etools.j2ee.workbench.IJ2EEWorkingCopyManager#hasWorkingCopies()
+ */
+ public boolean hasWorkingCopies() {
+ return (deletedCompilationUnits != null && !deletedCompilationUnits.isEmpty()) || (needsSavingCompilationUnits != null && !needsSavingCompilationUnits.isEmpty()) || (newCompilationUnits != null && !newCompilationUnits.isEmpty());
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/WorkingCopyManager.java b/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/WorkingCopyManager.java
new file mode 100644
index 000000000..35ccc89fb
--- /dev/null
+++ b/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/WorkingCopyManager.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.common.jdt.internal.integration;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+
+
+/**
+ * @author Administrator
+ *
+ *
+ */
+public interface WorkingCopyManager extends WorkingCopyProvider {
+
+ void dispose();
+
+ java.util.Set getAffectedFiles();
+
+ /**
+ * This will save all of the referenced CompilationUnits to be saved.
+ */
+ void saveCompilationUnits(IProgressMonitor monitor);
+
+ /**
+ * This will save all of the new CompilationUnits to be saved.
+ */
+ void saveOnlyNewCompilationUnits(IProgressMonitor monitor);
+
+ /**
+ * Method hasWorkingCopies.
+ *
+ * @return boolean
+ */
+ boolean hasWorkingCopies();
+
+ /**
+ * Revert all working copies.
+ */
+ void revert();
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/WorkingCopyManagerFactory.java b/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/WorkingCopyManagerFactory.java
new file mode 100644
index 000000000..26b51aac9
--- /dev/null
+++ b/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/WorkingCopyManagerFactory.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.common.jdt.internal.integration;
+
+import com.ibm.wtp.common.UIContextDetermination;
+
+
+/**
+ * @author mdelder
+ *
+ *
+ */
+public class WorkingCopyManagerFactory {
+
+ // protected static Class workingCopyManagerClass;
+
+ public static WorkingCopyManager newRegisteredInstance() {
+ return (WorkingCopyManager) UIContextDetermination.createInstance("workingCopyManager"); //$NON-NLS-1$
+ }
+
+ // public static IWorkingCopyManager createWorkingCopyManager() {
+ // if (getWorkingCopyManagerClass() != null)
+ // try {
+ // return (IWorkingCopyManager) getWorkingCopyManagerClass().newInstance();
+ // } catch (InstantiationException e1) {
+ // } catch (IllegalAccessException e2) {
+ // }
+ // return null;
+ // }
+ //
+ // /**
+ // * Insert the method's description here.
+ // * Creation date: (4/26/2001 7:53:15 AM)
+ // * @return java.lang.Class
+ // */
+ // public static java.lang.Class getWorkingCopyManagerClass() {
+ // return workingCopyManagerClass;
+ // }
+ //
+ // /**
+ // * Insert the method's description here.
+ // * Creation date: (4/26/2001 7:53:15 AM)
+ // * @param newWorkingCopyManagerClass java.lang.Class
+ // */
+ // public static void setWorkingCopyManagerClass(java.lang.Class newWorkingCopyManagerClass) {
+ // workingCopyManagerClass = newWorkingCopyManagerClass;
+ // }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/WorkingCopyProvider.java b/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/WorkingCopyProvider.java
new file mode 100644
index 000000000..2696f5c54
--- /dev/null
+++ b/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/integration/WorkingCopyProvider.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jst.common.jdt.internal.integration;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.ICompilationUnit;
+
+
+/**
+ * The user of the Java code generation framework must supply an implementation of this interface.
+ * The framework will obtain compilation working copies from this interface. The supplier of the
+ * implementation is responsible for committing the working copies when appropriate for the user's
+ * edit model.
+ */
+public interface WorkingCopyProvider {
+
+ /**
+ * This will delete compilation unit from the workbench and fix the internal references for this
+ * working copy manager.
+ *
+ * @param cu
+ * the compilation unit to delete
+ * @param monitor
+ * the progress monitor to use for the delete
+ */
+ void delete(ICompilationUnit cu, IProgressMonitor monitor);
+
+ /**
+ * Returns the working copy remembered for the compilation unit. That is, the manager already
+ * has a working copy for this unit, it does not create a new working copy. Does not connect the
+ * edit model to the working copy.
+ *
+ * @param input
+ * the compilation unit
+ * @return the working copy of the compilation unit, or <code>null</code> it there is no
+ * remembered working copy for this compilation unit
+ */
+ ICompilationUnit getExistingWorkingCopy(ICompilationUnit cu) throws CoreException;
+
+ /**
+ * Returns the working copy remembered for the compilation unit or creates a new working copy
+ * for the compilation unit and returns it. If a working copy is passed in, it is returned.
+ *
+ * @param input
+ * the compilation unit
+ * @return the working copy of the compilation unit
+ * @exception CoreException
+ * if the working copy can not be created
+ */
+ ICompilationUnit getWorkingCopy(ICompilationUnit cu, boolean forNewCU) throws CoreException;
+} \ No newline at end of file

Back to the top