Author: xavier
Date: Fri Jul 25 08:31:45 2008
New Revision: 679837
URL: http://svn.apache.org/viewvc?rev=679837&view=rev
Log:
NEW: settings files code completion support (IVYDE-22)
Added:
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsFile.java
(with props)
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsModel.java
(with props)
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvySettingsEditor.java
(with props)
Modified:
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/CHANGES.txt
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/plugin.xml
Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/CHANGES.txt
URL:
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/CHANGES.txt?rev=679837&r1=679836&r2=679837&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/CHANGES.txt (original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/CHANGES.txt Fri Jul 25
08:31:45 2008
@@ -3,6 +3,8 @@
next
==========================
+- NEW: settings files code completion support (IVYDE-22)
+
- IMPROVE: Retrieve after resolve feature does not clean target directory
first (IVYDE-105)
Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/plugin.xml
URL:
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/plugin.xml?rev=679837&r1=679836&r2=679837&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/plugin.xml (original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/plugin.xml Fri Jul 25 08:31:45
2008
@@ -101,6 +101,14 @@
id="org.apache.ivyde.editors.IvyEditor"
name="Ivy Editor">
</editor>
+ <editor
+ class="org.apache.ivyde.eclipse.ui.editors.IvySettingsEditor"
+
contributorClass="org.apache.ivyde.eclipse.ui.editors.IvyModuleDescriptorEditorContributor"
+ filenames="ivysettings.xml"
+ icon="icons/logo16x16.gif"
+ id="org.apache.ivyde.editors.IvySettingsEditor"
+ name="Ivy Settings Editor">
+ </editor>
</extension>
<extension
point="org.eclipse.ui.newWizards">
Added:
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsFile.java
URL:
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsFile.java?rev=679837&view=auto
==============================================================================
---
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsFile.java
(added)
+++
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsFile.java
Fri Jul 25 08:31:45 2008
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.ivyde.common.ivysettings;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.ivy.core.IvyPatternHelper;
+import org.apache.ivy.core.settings.XmlSettingsParser;
+import org.apache.ivyde.common.model.IvyFile;
+import org.apache.ivyde.common.model.IvyModelSettings;
+import org.eclipse.core.resources.IFile;
+
+public class IvySettingsFile extends IvyFile {
+ private static final Pattern CLASSPATH_URL_PATTERN =
Pattern.compile("<[\\s]*classpath[^>]+url=\"([^\"]+)");
+ private static final Pattern CLASSPATH_FILE_PATTERN =
Pattern.compile("<[\\s]*classpath[^>]+file=\"([^\"]+)");
+
+ private static final Pattern TYPEDEF_PATTERN = Pattern.compile(
+ "<[\\s]*typedef[^>]+name=\"([^\"]+)\"[^>]+classname=\"([^\"]+)");
+
+ private IFile file;
+
+
+ public IvySettingsFile(IvyModelSettings settings, IFile file, String
projectName, String doc,
+ int currentOffset) {
+ super(settings, projectName, doc, currentOffset);
+ this.file = file;
+ }
+
+ public URL[] getClasspathUrls() {
+ List urls = new ArrayList();
+ Matcher m = CLASSPATH_URL_PATTERN.matcher(getDoc());
+ while (m.find()) {
+ try {
+ urls.add(new URL(substitute(m.group(1))));
+ } catch (MalformedURLException e) {
+ // ignored
+ }
+ }
+ m = CLASSPATH_FILE_PATTERN.matcher(getDoc());
+ while (m.find()) {
+ try {
+ urls.add(new URL(substitute(m.group(1))));
+ } catch (MalformedURLException e) {
+ try {
+ urls.add(new File(substitute(m.group(1))).toURL());
+ } catch (MalformedURLException e1) {
+ // ignored
+ }
+ }
+ }
+ return (URL[]) urls.toArray(new URL[urls.size()]);
+ }
+
+ private String substitute(String str) {
+ Map variables = new HashMap();
+ URI settingsDirUri = file.getParent().getLocationURI();
+ if (settingsDirUri != null) {
+ variables.put("ivy.settings.dir", settingsDirUri.toString());
+ }
+ return IvyPatternHelper.substituteVariables(str, variables);
+ }
+
+ public Map/*<String,String>*/ getTypedefs() {
+ Properties p = new Properties();
+ try {
+
p.load(XmlSettingsParser.class.getResourceAsStream("typedef.properties"));
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Matcher m = TYPEDEF_PATTERN.matcher(getDoc());
+ while (m.find()) {
+ p.put(substitute(m.group(1)), substitute(m.group(2)));
+ }
+ return p;
+ }
+
+}
Propchange:
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsFile.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsFile.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsModel.java
URL:
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsModel.java?rev=679837&view=auto
==============================================================================
---
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsModel.java
(added)
+++
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsModel.java
Fri Jul 25 08:31:45 2008
@@ -0,0 +1,366 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.ivyde.common.ivysettings;
+
+import java.lang.reflect.Method;
+import java.net.URLClassLoader;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.ivy.Ivy;
+import org.apache.ivy.plugins.conflict.ConflictManager;
+import org.apache.ivy.plugins.latest.LatestStrategy;
+import org.apache.ivy.plugins.lock.LockStrategy;
+import org.apache.ivy.plugins.namespace.Namespace;
+import org.apache.ivy.plugins.parser.ModuleDescriptorParser;
+import org.apache.ivy.plugins.report.ReportOutputter;
+import org.apache.ivy.plugins.resolver.DependencyResolver;
+import org.apache.ivy.plugins.trigger.Trigger;
+import org.apache.ivy.plugins.version.VersionMatcher;
+import org.apache.ivy.util.StringUtils;
+import org.apache.ivyde.common.model.IvyBooleanTagAttribute;
+import org.apache.ivyde.common.model.IvyFile;
+import org.apache.ivyde.common.model.IvyModel;
+import org.apache.ivyde.common.model.IvyModelSettings;
+import org.apache.ivyde.common.model.IvyReferenceTag;
+import org.apache.ivyde.common.model.IvyTag;
+import org.apache.ivyde.common.model.IvyTagAttribute;
+import org.eclipse.core.resources.IFile;
+
+public class IvySettingsModel extends IvyModel {
+ private String loaded = null;
+ private IFile file;
+ private ClassLoader cl;
+ private Map typedefClasses;
+
+ public IvySettingsModel(IvyModelSettings settings, IFile file) {
+ super(settings);
+ this.file = file;
+ }
+
+ public void refreshIfNeeded(IvyFile file) {
+ String toLoad = getLoad(file);
+ if (!toLoad.equals(loaded)) {
+ doRefresh(file, toLoad);
+ }
+ }
+
+ private String getLoad(IvyFile file) {
+ IvySettingsFile sfile = (IvySettingsFile) file;
+ return Arrays.asList(sfile.getClasspathUrls()) + "|" +
sfile.getTypedefs();
+ }
+
+ private void doRefresh(IvyFile file, String toLoad) {
+ IvySettingsFile sfile = (IvySettingsFile) file;
+ clearModel();
+ cl = getClassLoader(sfile);
+ typedefClasses = getTypedefClasses(sfile, cl);
+
+ IvyTag ivyTag = new IvyTag("ivysettings", "Root tag of Ivy settings
file");
+
+ ivyTag.addChildIvyTag(new IvyTag("property",
+ new IvyTagAttribute[] {
+ new IvyTagAttribute("name", true),
+ new IvyTagAttribute("value", true),
+ new IvyBooleanTagAttribute("override"),
+ }));
+ ivyTag.addChildIvyTag(new IvyTag("properties",
+ new IvyTagAttribute[] {
+ new IvyTagAttribute("file", true),
+ new IvyTagAttribute("environment"),
+ new IvyBooleanTagAttribute("override"),
+ }));
+ ivyTag.addChildIvyTag(new IvyTag("settings",
+ new IvyTagAttribute[] {
+ new IvyTagAttribute("defaultResolver"),
+ new IvyTagAttribute("defaultLatestStrategy"),
+ new IvyTagAttribute("defaultConflictManager"),
+ new IvyTagAttribute("defaultBranch"),
+ new IvyTagAttribute("defaultResolveMode"),
+ new IvyTagAttribute("circularDependencyStrategy"),
+ new IvyBooleanTagAttribute("validate"),
+ new IvyBooleanTagAttribute("useRemoteConfig"),
+ }));
+ ivyTag.addChildIvyTag(new IvyTag("include",
+ new IvyTagAttribute[] {
+ new IvyTagAttribute("url"),
+ new IvyTagAttribute("file"),
+ }));
+ ivyTag.addChildIvyTag(new IvyTag("classpath",
+ new IvyTagAttribute[] {
+ new IvyTagAttribute("url"),
+ new IvyTagAttribute("file"),
+ }));
+ ivyTag.addChildIvyTag(new IvyTag("typedef",
+ new IvyTagAttribute[] {
+ new IvyTagAttribute("name"),
+ new IvyTagAttribute("classname"),
+ }));
+
+ IvyTag tag = new IvyTag("locking-strategies");
+ addTypedefChildren(tag, getChildClasses(typedefClasses,
LockStrategy.class));
+ ivyTag.addChildIvyTag(tag);
+
+ ivyTag.addChildIvyTag(new IvyTag("caches",
+ new IvyTagAttribute[] {
+ new IvyTagAttribute("default"),
+ new IvyTagAttribute("defaultCacheDir"),
+ new IvyTagAttribute("resolutionCacheDir"),
+ new IvyTagAttribute("repositoryCacheDir"),
+ new IvyTagAttribute("ivyPattern"),
+ new IvyTagAttribute("artifactPattern"),
+ new IvyBooleanTagAttribute("checkUpToDate"),
+ new IvyBooleanTagAttribute("useOrigin"),
+ new IvyTagAttribute("lockStrategy"),
+ }).addChildIvyTag(new IvyTag("cache",
+ new IvyTagAttribute[] {
+ new IvyTagAttribute("name"),
+ new IvyTagAttribute("basedir"),
+ new IvyTagAttribute("ivyPattern"),
+ new IvyTagAttribute("artifactPattern"),
+ new IvyBooleanTagAttribute("useOrigin"),
+ new IvyTagAttribute("lockStrategy"),
+ new IvyTagAttribute("defaultTTL"),
+ }).addChildIvyTag(new IvyTag("ttl",
+ new IvyTagAttribute[] {
+ new IvyTagAttribute("organisation"),
+ new IvyTagAttribute("module"),
+ new IvyTagAttribute("revision"),
+ new IvyTagAttribute("matcher"),
+ new IvyTagAttribute("duration", true),
+ }))));
+
+ tag = new IvyTag("latest-strategies");
+ addTypedefChildren(tag, getChildClasses(typedefClasses,
LatestStrategy.class));
+ ivyTag.addChildIvyTag(tag);
+
+ tag = new IvyTag("parsers");
+ addTypedefChildren(tag, getChildClasses(typedefClasses,
ModuleDescriptorParser.class));
+ ivyTag.addChildIvyTag(tag);
+
+ tag = new IvyTag("namespaces");
+ addTypedefChildren(tag, getChildClasses(typedefClasses,
Namespace.class));
+ ivyTag.addChildIvyTag(tag);
+
+ tag = new IvyTag("macrodef", new IvyTagAttribute[] {
+ new IvyTagAttribute("name"),
+ }).addChildIvyTag(new IvyTag("attribute", new IvyTagAttribute[] {
+ new IvyTagAttribute("name"),
+ new IvyTagAttribute("default"),
+ }));
+ addTypedefChildren(tag, getChildClasses(typedefClasses,
DependencyResolver.class));
+ ivyTag.addChildIvyTag(tag);
+
+ tag = new IvyTag("resolvers");
+ addTypedefChildren(tag, getChildClasses(typedefClasses,
DependencyResolver.class));
+ tag.addChildIvyTag(new IvyReferenceTag("resolver"));
+ ivyTag.addChildIvyTag(tag);
+
+ tag = new IvyTag("conflict-managers");
+ addTypedefChildren(tag, getChildClasses(typedefClasses,
ConflictManager.class));
+ ivyTag.addChildIvyTag(tag);
+
+ ivyTag.addChildIvyTag(new IvyTag("modules")
+ .addChildIvyTag(new IvyTag("module",
+ new IvyTagAttribute[] {
+ new IvyTagAttribute("organisation"),
+ new IvyTagAttribute("name"),
+ new IvyTagAttribute("revision"),
+ new IvyTagAttribute("matcher"),
+ new IvyTagAttribute("resolver"),
+ new IvyTagAttribute("conflict-manager"),
+ new IvyTagAttribute("branch"),
+ new IvyTagAttribute("resolveMode"),
+ })));
+
+ tag = new IvyTag("outputters");
+ addTypedefChildren(tag, getChildClasses(typedefClasses,
ReportOutputter.class));
+ ivyTag.addChildIvyTag(tag);
+
+ ivyTag.addChildIvyTag(new IvyTag("statuses",
+ new IvyTagAttribute[] {
+ new IvyTagAttribute("default"),
+ })
+ .addChildIvyTag(new IvyTag("status",
+ new IvyTagAttribute[] {
+ new IvyTagAttribute("name"),
+ new IvyTagAttribute("integration"),
+ })));
+
+ tag = new IvyTag("triggers");
+ addTypedefChildren(tag, getChildClasses(typedefClasses,
Trigger.class));
+ ivyTag.addChildIvyTag(tag);
+
+ tag = new IvyTag("version-matchers");
+ addTypedefChildren(tag, getChildClasses(typedefClasses,
VersionMatcher.class));
+ ivyTag.addChildIvyTag(tag);
+
+ addTag(ivyTag);
+ loaded = toLoad;
+ }
+
+ private void addTypedefChildren(IvyTag tag, Map children) {
+ for (Iterator it = children.entrySet().iterator(); it.hasNext();) {
+ Entry entry = (Entry) it.next();
+ Class clazz = (Class) entry.getValue();
+ String childName = (String) entry.getKey();
+ tag.addChildIvyTag(typedefedTag(childName, clazz));
+ }
+ }
+
+ private IvyTag typedefedTag(String tagName, final Class clazz) {
+ IvyTag child = new IvyTag(tagName) {
+ // we lazy load children, since we may have a loop in children
(chain can contain chain)
+ // causing a stack overflow if we try to recursively add typedefed
children
+ private boolean init = false;
+ public List getAttributes() {
+ init();
+ return super.getAttributes();
+ }
+
+ public List getChilds() {
+ init();
+ return super.getChilds();
+ }
+
+ public boolean hasChild() {
+ init();
+ return super.hasChild();
+ }
+
+ private void init() {
+ if (!init) {
+ Method[] methods = clazz.getMethods();
+ for (int i = 0; i < methods.length; i++) {
+ Method m = methods[i];
+ if (m.getName().startsWith("create") &&
m.getParameterTypes().length == 0
+ && isSupportedChildType(m.getReturnType())) {
+ String name = StringUtils
+
.uncapitalize(m.getName().substring("create".length()));
+ if (name.length() == 0) {
+ continue;
+ }
+ addChildIvyTag(typedefedTag(name,
m.getReturnType()));
+ } else if (m.getName().startsWith("add")
+ && m.getParameterTypes().length == 1
+ &&
isSupportedChildType(m.getParameterTypes()[0])
+ && Void.TYPE.equals(m.getReturnType())) {
+ String name =
StringUtils.uncapitalize(m.getName().substring(
+
m.getName().startsWith("addConfigured") ?
+ "addConfigured".length() :
"add".length()));
+ if (name.length() == 0) {
+ addTypedefChildren(this,
getChildClasses(typedefClasses, m.getParameterTypes()[0]));
+ } else {
+ addChildIvyTag(typedefedTag(name,
m.getParameterTypes()[0]));
+ }
+ } else if (m.getName().startsWith("set")
+ && Void.TYPE.equals(m.getReturnType())
+ && m.getParameterTypes().length == 1
+ &&
isSupportedAttributeType(m.getParameterTypes()[0])) {
+ IvyTagAttribute att = new IvyTagAttribute(
+
StringUtils.uncapitalize(m.getName().substring(3)));
+ if (m.getParameterTypes()[0] == boolean.class) {
+
att.setValueProvider(IvyBooleanTagAttribute.VALUE_PROVIDER);
+ }
+ addAttribute(att);
+ }
+ }
+ init = true;
+ }
+ }
+ };
+ return child;
+ }
+
+ protected boolean isSupportedChildType(Class type) {
+ return !Void.TYPE.equals(type)
+ && !String.class.equals(type)
+ && !Character.class.equals(type) && !char.class.equals(type)
+ && !Boolean.class.equals(type) && !boolean.class.equals(type)
+ && !Integer.class.equals(type) && !int.class.equals(type)
+ && !Short.class.equals(type) && !short.class.equals(type)
+ && !Long.class.equals(type) && !long.class.equals(type)
+ && !Class.class.equals(type)
+ ;
+ }
+
+ private boolean isSupportedAttributeType(Class type) {
+ if (String.class.isAssignableFrom(type)
+ || Character.class.equals(type) || char.class.equals(type)
+ || Boolean.class.equals(type) || boolean.class.equals(type)
+ || Short.class.equals(type) || short.class.equals(type)
+ || Integer.class.equals(type) || int.class.equals(type)
+ || Long.class.equals(type) || long.class.equals(type)
+ || Class.class.equals(type)
+ ) {
+ return true;
+ }
+ try {
+ type.getConstructor(new Class[] {String.class});
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ private ClassLoader getClassLoader(IvySettingsFile sfile) {
+ if (sfile.getClasspathUrls().length > 0) {
+ return new URLClassLoader(sfile.getClasspathUrls(),
Ivy.class.getClassLoader());
+ } else {
+ return Ivy.class.getClassLoader();
+ }
+ }
+
+ private Map/*<String,Class>*/ getTypedefClasses(IvySettingsFile file,
ClassLoader cl) {
+ Map/*<String,Class>*/ classes = new LinkedHashMap();
+ Map typedefs = file.getTypedefs();
+ for (Iterator it = typedefs.entrySet().iterator(); it.hasNext();) {
+ Entry entry = (Entry) it.next();
+ try {
+ classes.put(entry.getKey(), cl.loadClass((String)
entry.getValue()));
+ } catch (ClassNotFoundException e) {
+ // ignored
+ }
+ }
+ return classes;
+ }
+
+ private Map/*<String,Class>*/ getChildClasses(Map/*<String,Class>*/
classes, Class type) {
+ Map/*<String,Class>*/ childClasses = new LinkedHashMap();
+ for (Iterator it = classes.entrySet().iterator(); it.hasNext();) {
+ Entry entry = (Entry) it.next();
+ if (type.isAssignableFrom((Class) entry.getValue())) {
+ childClasses.put(entry.getKey(), entry.getValue());
+ }
+ }
+ return childClasses;
+ }
+
+ protected String getRootIvyTagName() {
+ return "ivysettings";
+ }
+
+ public IvyFile newIvyFile(String name, String content, int documentOffset)
{
+ return new IvySettingsFile(getSettings(), file, name, content,
documentOffset);
+ }
+
+}
Propchange:
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsModel.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivysettings/IvySettingsModel.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvySettingsEditor.java
URL:
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvySettingsEditor.java?rev=679837&view=auto
==============================================================================
---
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvySettingsEditor.java
(added)
+++
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvySettingsEditor.java
Fri Jul 25 08:31:45 2008
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.ivyde.eclipse.ui.editors;
+
+import org.apache.ivyde.common.ivyfile.IvyModuleDescriptorModel;
+import org.apache.ivyde.common.ivysettings.IvySettingsModel;
+import org.apache.ivyde.common.model.IvyModel;
+import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathContainer;
+import org.apache.ivyde.eclipse.cpcontainer.IvyClasspathUtil;
+import org.apache.ivyde.eclipse.ui.core.IvyFileEditorInput;
+import org.apache.ivyde.eclipse.ui.editors.xml.EclipseIvyModelSettings;
+import org.apache.ivyde.eclipse.ui.editors.xml.IvyContentAssistProcessor;
+import org.apache.ivyde.eclipse.ui.editors.xml.XMLEditor;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.part.FileEditorInput;
+
+public class IvySettingsEditor extends FormEditor implements
IResourceChangeListener {
+ public final static String ID =
"org.apache.ivyde.editors.IvySettingsEditor";
+
+ private XMLEditor xmlEditor;
+
+ /**
+ * Creates a multi-page editor example.
+ */
+ public IvySettingsEditor() {
+ super();
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
+ }
+
+ protected void setInput(IEditorInput input) {
+ IvyFileEditorInput ivyFileEditorInput = null;
+ if (input instanceof FileEditorInput) {
+ FileEditorInput fei = (FileEditorInput) input;
+ IFile file = ((FileEditorInput) input).getFile();
+ ivyFileEditorInput = new IvyFileEditorInput(file);
+ } else if (input instanceof IvyFileEditorInput) {
+ ivyFileEditorInput = (IvyFileEditorInput) input;
+ }
+ super.setInput(ivyFileEditorInput);
+ if (ivyFileEditorInput.getFile() != null) {
+ if (xmlEditor != null) {
+ xmlEditor.setFile(ivyFileEditorInput.getFile());
+ }
+ }
+ // deprectated but we need retro compatibility
+ setTitle(ivyFileEditorInput.getFile().getName());
+ }
+
+ void createPageXML() {
+ try {
+ xmlEditor = new XMLEditor(new IvyContentAssistProcessor() {
+ protected IvyModel newCompletionModel(IFile file) {
+ return new IvySettingsModel(
+ new EclipseIvyModelSettings(getJavaProject()),
+ file);
+ }
+ });
+ xmlEditor.setFile(((IvyFileEditorInput)
getEditorInput()).getFile());
+ int index = addPage(xmlEditor, getEditorInput());
+ setPageText(index, xmlEditor.getTitle());
+ } catch (PartInitException e) {
+ ErrorDialog.openError(getSite().getShell(), "Error creating nested
text editor", null,
+ e.getStatus());
+ }
+ }
+
+ /**
+ * Creates the pages of the multi-page editor.
+ */
+ protected void addPages() {
+ // createPageOverView();
+ createPageXML();
+ // createPagePreview();
+ }
+
+ /**
+ * The <code>MultiPageEditorPart</code> implementation of this
<code>IWorkbenchPart</code>
+ * method disposes all nested editors. Subclasses may extend.
+ */
+ public void dispose() {
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
+ super.dispose();
+ }
+
+ /**
+ * Saves the multi-page editor's document.
+ */
+ public void doSave(IProgressMonitor monitor) {
+ xmlEditor.doSave(monitor);
+ IFile file = ((IvyFileEditorInput) getEditorInput()).getFile();
+ IJavaProject project = JavaCore.create(file.getProject());
+ IvyClasspathContainer cp =
IvyClasspathUtil.getIvyClasspathContainer(project);
+ if (cp != null
+ && cp.getConf().getInheritedIvySettingsPath().equals(
+ file.getProjectRelativePath().toString())) {
+ cp.scheduleResolve();
+ }
+ }
+
+ /**
+ * Saves the multi-page editor's document as another file. Also updates
the text for page 0's
+ * tab, and updates this multi-page editor's input to correspond to the
nested editor's.
+ */
+ public void doSaveAs() {
+ xmlEditor.doSaveAs();
+ setPageText(0, xmlEditor.getTitle());
+ setInput(xmlEditor.getEditorInput());
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IEditorPart
+ */
+ public void gotoMarker(IMarker marker) {
+ setActivePage(0);
+ IDE.gotoMarker(getEditor(0), marker);
+ }
+
+ /**
+ * The <code>MultiPageEditorExample</code> implementation of this method
checks that the input
+ * is an instance of <code>IFileEditorInput</code>.
+ */
+ public void init(IEditorSite site, IEditorInput editorInput) throws
PartInitException {
+ if (!(editorInput instanceof IFileEditorInput))
+ throw new PartInitException("Invalid Input: Must be
IFileEditorInput");
+ super.init(site, editorInput);
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IEditorPart.
+ */
+ public boolean isSaveAsAllowed() {
+ return xmlEditor.isSaveAsAllowed();
+ }
+
+ /**
+ * Closes all project files on project close.
+ */
+ public void resourceChanged(IResourceChangeEvent event) {
+ if (event.getType() == IResourceChangeEvent.PRE_CLOSE) {
+ final IResource res = event.getResource();
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ IWorkbenchPage[] pages =
getSite().getWorkbenchWindow().getPages();
+ for (int i = 0; i < pages.length; i++) {
+ if (((IFileEditorInput)
xmlEditor.getEditorInput()).getFile().getProject()
+ .equals(res)) {
+ IEditorPart editorPart = pages[i]
+ .findEditor(xmlEditor.getEditorInput());
+ pages[i].closeEditor(editorPart, true);
+ }
+ }
+ }
+ });
+ }
+ }
+}
Propchange:
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvySettingsEditor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/ui/editors/IvySettingsEditor.java
------------------------------------------------------------------------------
svn:mime-type = text/plain