### Eclipse Workspace Patch 1.0 #P org.eclipse.wst.common.snippets Index: META-INF/MANIFEST.MF =================================================================== RCS file: /cvsroot/webtools/common/plugins/org.eclipse.wst.common.snippets/META-INF/MANIFEST.MF,v retrieving revision 1.20 diff -u -r1.20 MANIFEST.MF --- META-INF/MANIFEST.MF 26 Jan 2009 20:07:49 -0000 1.20 +++ META-INF/MANIFEST.MF 1 Sep 2009 21:50:26 -0000 @@ -25,6 +25,7 @@ org.eclipse.ui;bundle-version="[3.4.0,4.0.0)", org.eclipse.jface.text;bundle-version="[3.4.0,4.0.0)", org.eclipse.core.resources;bundle-version="[3.4.0,4.0.0)", - org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)" + org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)", + org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.4 Index: src/org/eclipse/wst/common/snippets/internal/palette/ModelFactoryForUser.java =================================================================== RCS file: /cvsroot/webtools/common/plugins/org.eclipse.wst.common.snippets/src/org/eclipse/wst/common/snippets/internal/palette/ModelFactoryForUser.java,v retrieving revision 1.12 diff -u -r1.12 ModelFactoryForUser.java --- src/org/eclipse/wst/common/snippets/internal/palette/ModelFactoryForUser.java 9 Dec 2008 18:15:46 -0000 1.12 +++ src/org/eclipse/wst/common/snippets/internal/palette/ModelFactoryForUser.java 1 Sep 2009 21:50:26 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2009 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 @@ -219,11 +219,47 @@ return definitions; } - + public SnippetDefinitions loadCurrent() { return load(getFilename()); } + public SnippetDefinitions load(InputStream in) { + SnippetDefinitions definitions = new SnippetDefinitions(); + Document document = null; + try { + DocumentBuilder builder = CommonXML.getDocumentBuilder(); + if (builder != null) { + document = builder.parse(new InputSource(in)); + } + else { + Logger.log(Logger.ERROR, "Couldn't obtain a DocumentBuilder"); //$NON-NLS-1$ + } + } + catch (FileNotFoundException e) { + // typical of new workspace, don't log it + document = null; + } + catch (IOException e) { + Logger.logException("Could not load user items", e); //$NON-NLS-1$ + return definitions; + } + catch (SAXException e) { + Logger.logException("Could not load user items", e); //$NON-NLS-1$ + return definitions; + } + if (document == null) + return definitions; + Element library = document.getDocumentElement(); + if (library == null || !library.getNodeName().equals(SnippetsPlugin.NAMES.SNIPPETS)) + return definitions; + loadDefinitions(definitions, library); + + connectItemsAndCategories(definitions); + + return definitions; + } + protected void loadDefinitions(SnippetDefinitions definitions, Node library) { NodeList children = library.getChildNodes(); int length = children.getLength(); @@ -313,6 +349,7 @@ setProperty(item, SnippetsPlugin.NAMES.ID, element.getAttribute(SnippetsPlugin.NAMES.ID)); setProperty(item, SnippetsPlugin.NAMES.LABEL, element.getAttribute(SnippetsPlugin.NAMES.LABEL)); setProperty(item, SnippetsPlugin.NAMES.LARGEICON, element.getAttribute(SnippetsPlugin.NAMES.LARGEICON)); + setProperty(item, SnippetsPlugin.NAMES.PROVIDER_ID, element.getAttribute(SnippetsPlugin.NAMES.PROVIDER_ID)); NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Index: src/org/eclipse/wst/common/snippets/internal/palette/AbstractModelFactory.java =================================================================== RCS file: /cvsroot/webtools/common/plugins/org.eclipse.wst.common.snippets/src/org/eclipse/wst/common/snippets/internal/palette/AbstractModelFactory.java,v retrieving revision 1.7 diff -u -r1.7 AbstractModelFactory.java --- src/org/eclipse/wst/common/snippets/internal/palette/AbstractModelFactory.java 10 Apr 2007 17:23:34 -0000 1.7 +++ src/org/eclipse/wst/common/snippets/internal/palette/AbstractModelFactory.java 1 Sep 2009 21:50:26 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2009 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 @@ -20,6 +20,7 @@ import org.eclipse.wst.common.snippets.internal.Logger; import org.eclipse.wst.common.snippets.internal.SnippetDefinitions; import org.eclipse.wst.common.snippets.internal.SnippetsPlugin; +import org.eclipse.wst.common.snippets.internal.util.SnippetProviderManager; public abstract class AbstractModelFactory { @@ -73,6 +74,7 @@ setProperties(item, source); migrate50to51(item); + return item; } @@ -176,6 +178,8 @@ item.setContentString(propertyValue.toString()); else if (property.equals(SnippetsPlugin.NAMES.EDITORCLASSNAME)) item.setEditorClassName(propertyValue.toString()); + else if (property.equals(SnippetsPlugin.NAMES.PROVIDER_ID)) + item.setProvider(SnippetProviderManager.findProvider(propertyValue.toString())); else setEntryProperty(item, property, propertyValue); } Index: src/org/eclipse/wst/common/snippets/internal/palette/SnippetPaletteItem.java =================================================================== RCS file: /cvsroot/webtools/common/plugins/org.eclipse.wst.common.snippets/src/org/eclipse/wst/common/snippets/internal/palette/SnippetPaletteItem.java,v retrieving revision 1.4 diff -u -r1.4 SnippetPaletteItem.java --- src/org/eclipse/wst/common/snippets/internal/palette/SnippetPaletteItem.java 10 Apr 2007 17:23:34 -0000 1.4 +++ src/org/eclipse/wst/common/snippets/internal/palette/SnippetPaletteItem.java 1 Sep 2009 21:50:26 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2009 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 @@ -16,12 +16,15 @@ import java.util.Arrays; import java.util.List; +import org.eclipse.core.runtime.IPath; import org.eclipse.gef.palette.PaletteContainer; import org.eclipse.gef.palette.PaletteTemplateEntry; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.wst.common.snippets.core.ISnippetCategory; import org.eclipse.wst.common.snippets.core.ISnippetItem; +import org.eclipse.wst.common.snippets.core.ISnippetProvider; import org.eclipse.wst.common.snippets.core.ISnippetVariable; +import org.eclipse.wst.common.snippets.internal.model.SnippetManager; public class SnippetPaletteItem extends PaletteTemplateEntry implements ISnippetItem { @@ -38,6 +41,7 @@ protected Object fSourceDescriptor; protected Object fSourceType = SNIPPET_SOURCE_USER; protected List fVariables; + private ISnippetProvider provider; /** * @param label @@ -219,4 +223,17 @@ fVariables = new ArrayList(variables.length); fVariables.addAll(Arrays.asList(variables)); } + + public IPath getStorageLocation() { + return SnippetManager.getInstance().getStorageLocation(getId()); + } + + + public ISnippetProvider getProvider() { + return provider; + } + + public void setProvider(ISnippetProvider provider) { + this.provider = provider; + } } Index: src/org/eclipse/wst/common/snippets/internal/palette/SnippetCustomizerDialog.java =================================================================== RCS file: /cvsroot/webtools/common/plugins/org.eclipse.wst.common.snippets/src/org/eclipse/wst/common/snippets/internal/palette/SnippetCustomizerDialog.java,v retrieving revision 1.7 diff -u -r1.7 SnippetCustomizerDialog.java --- src/org/eclipse/wst/common/snippets/internal/palette/SnippetCustomizerDialog.java 25 Feb 2009 21:18:54 -0000 1.7 +++ src/org/eclipse/wst/common/snippets/internal/palette/SnippetCustomizerDialog.java 1 Sep 2009 21:50:26 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. + * Copyright (c) 2004, 2009 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 @@ -10,12 +10,23 @@ *******************************************************************************/ package org.eclipse.wst.common.snippets.internal.palette; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; +import java.util.Enumeration; import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipException; +import java.util.zip.ZipFile; +import java.util.zip.ZipOutputStream; +import org.eclipse.core.runtime.Platform; import org.eclipse.gef.palette.PaletteDrawer; import org.eclipse.gef.palette.PaletteEntry; import org.eclipse.gef.palette.PaletteRoot; @@ -32,16 +43,24 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; import org.eclipse.wst.common.snippets.core.ISnippetCategory; +import org.eclipse.wst.common.snippets.core.ISnippetItem; import org.eclipse.wst.common.snippets.internal.IHelpContextIds; import org.eclipse.wst.common.snippets.internal.SnippetDefinitions; import org.eclipse.wst.common.snippets.internal.SnippetsMessages; +import org.eclipse.wst.common.snippets.internal.SnippetsPlugin; import org.eclipse.wst.common.snippets.internal.SnippetsPluginImageHelper; import org.eclipse.wst.common.snippets.internal.SnippetsPluginImages; import org.eclipse.wst.common.snippets.internal.model.SnippetManager; import org.eclipse.wst.common.snippets.internal.ui.SnippetsCustomizer; +import org.osgi.framework.Bundle; public class SnippetCustomizerDialog extends PaletteCustomizerDialog { + private static class EXPORT_IMPORT_STRATEGY { + static EXPORT_IMPORT_STRATEGY ARCHIVE = new EXPORT_IMPORT_STRATEGY(); + static EXPORT_IMPORT_STRATEGY XML = new EXPORT_IMPORT_STRATEGY(); + } + private class ExportAction extends PaletteCustomizationAction { public ExportAction() { setEnabled(false); @@ -54,33 +73,92 @@ protected void handleExport() { PaletteDrawer exportCategory = (PaletteDrawer) getSelectedPaletteEntry(); + EXPORT_IMPORT_STRATEGY strategy = exportStrategy(exportCategory); - final FileDialog fileDialog = new FileDialog(getShell(), SWT.SAVE); - fileDialog.setText(SnippetsMessages.Export_Snippets); - fileDialog.setFileName("snippets.xml"); //$NON-NLS-1$ - String[] filterExtensions = new String[2]; - filterExtensions[0] = "*.xml"; //$NON-NLS-1$ - filterExtensions[1] = "*.*"; //$NON-NLS-1$ - fileDialog.setFilterExtensions(filterExtensions); - String filename = fileDialog.open(); + if (EXPORT_IMPORT_STRATEGY.ARCHIVE == strategy){ + exportArchive(exportCategory); + } else { + exportXML(exportCategory); + } + updateActions(); + } + + private EXPORT_IMPORT_STRATEGY exportStrategy(PaletteDrawer exportCategory) { + List children = exportCategory.getChildren(); + for (int i = 0; i < children.size(); i++) { + ISnippetItem snippetItem = (ISnippetItem) children.get(i); + File folder = new File(SnippetManager.getInstance().getStorageLocation(snippetItem.getId()).toOSString()); + if (folder.exists()){ + return EXPORT_IMPORT_STRATEGY.ARCHIVE; + } + } + return EXPORT_IMPORT_STRATEGY.XML; + } + + private void exportArchive(PaletteDrawer exportCategory) { + String filename = openFileDialog("*.zip");//$NON-NLS-1$ if (filename != null) { - SnippetDefinitions definitions = ModelFactoryForUser.getInstance().load(filename); - ISnippetCategory existingCategory = definitions.getCategory(exportCategory.getId()); + ZipOutputStream outputStream = null; + try { + SnippetDefinitions definitions = getCategory(exportCategory, filename); + outputStream = new ZipOutputStream(new FileOutputStream(filename)); + ZipEntry descriptorFile = new ZipEntry("snippets.xml"); + outputStream.putNextEntry(descriptorFile); + new UserModelDumper().write(definitions, outputStream); + ISnippetCategory existingCategory = definitions.getCategory(exportCategory.getId()); + ISnippetItem[] items = existingCategory.getItems(); + for (int i = 0; i < items.length; i++) { + File folder = new File(SnippetManager.getInstance().getStorageLocation(items[i].getId()).toOSString()); + if (folder.exists()){ + addToZip(folder.getParentFile(), folder, outputStream); + } + } + } + catch (FileNotFoundException e) { + // should not have problem finding the output file + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + finally { + if (outputStream != null) + try { + outputStream.close(); + } + catch (IOException e) { + // should not have problem closing the output file + e.printStackTrace(); + } + } + } + } - if (existingCategory == null) - definitions.getCategories().add(exportCategory); - else { - String title = SnippetsMessages.SnippetCustomizerDialog_2; //$NON-NLS-1$ - String message = NLS.bind(SnippetsMessages.SnippetCustomizerDialog_4, new String[]{existingCategory.getLabel()}); - boolean answer = MessageDialog.openConfirm(getShell(), title, message); - if (answer) { - definitions.getCategories().remove(existingCategory); - definitions.getCategories().add(exportCategory); + private void addToZip(File root, File folder, ZipOutputStream outputStream) throws IOException { + File[] listedFiles = folder.listFiles(); + for (int i = 0; i < listedFiles.length; i++) { + if (listedFiles[i].isDirectory()){ + addToZip(root, listedFiles[i], outputStream); + } else { + ZipEntry ze = new ZipEntry(listedFiles[i].getAbsolutePath().substring(root.getAbsolutePath().length()+1)); + outputStream.putNextEntry(ze); + BufferedInputStream bis = new BufferedInputStream(new FileInputStream(listedFiles[i]), 1024); + byte[] data = new byte[1024]; + int count; + while ((count = bis.read(data, 0, 1024)) != -1) { + outputStream.write(data, 0, count); } + bis.close(); } + } + } - OutputStream outputStream = null; - try { + private void exportXML(PaletteDrawer exportCategory) { + String filename = openFileDialog("*.xml");//$NON-NLS-1$ + + OutputStream outputStream = null; + if (filename != null) { + try{ + SnippetDefinitions definitions = getCategory(exportCategory, filename); outputStream = new FileOutputStream(filename); new UserModelDumper().write(definitions, outputStream); } @@ -93,14 +171,46 @@ try { outputStream.close(); } - catch (IOException e) { - // should not have problem closing the output file - e.printStackTrace(); - } + catch (IOException e) { + // should not have problem closing the output file + e.printStackTrace(); + } } - updateActions(); } + + + } + + private SnippetDefinitions getCategory(PaletteDrawer exportCategory, + String fileName) { + SnippetDefinitions definitions = ModelFactoryForUser.getInstance().load(fileName); + ISnippetCategory existingCategory = definitions.getCategory(exportCategory.getId()); + + if (existingCategory == null) + definitions.getCategories().add(exportCategory); + else { + String title = SnippetsMessages.SnippetCustomizerDialog_2; //$NON-NLS-1$ + String message = NLS.bind(SnippetsMessages.SnippetCustomizerDialog_4, new String[]{existingCategory.getLabel()}); + boolean answer = MessageDialog.openConfirm(getShell(), title, message); + if (answer) { + definitions.getCategories().remove(existingCategory); + definitions.getCategories().add(exportCategory); + } + } + return definitions; + } + + private String openFileDialog(String extension) { + final FileDialog fileDialog = new FileDialog(getShell(), SWT.SAVE); + fileDialog.setText(SnippetsMessages.Export_Snippets); + fileDialog.setFileName("snippets"+ extension.substring(1)); //$NON-NLS-1$ + String[] filterExtensions = new String[2]; + filterExtensions[0] = extension; + filterExtensions[1] = "*.*"; //$NON-NLS-1$ + fileDialog.setFilterExtensions(filterExtensions); + String filename = fileDialog.open(); + return filename; } public void run() { @@ -132,14 +242,38 @@ protected void handleImport() { final FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN); fileDialog.setText(SnippetsMessages.Import_Snippets); - fileDialog.setFileName("snippets.xml"); //$NON-NLS-1$ +// fileDialog.setFileName("snippets.xml"); //$NON-NLS-1$ String[] filterExtensions = new String[2]; - filterExtensions[0] = "*.xml"; //$NON-NLS-1$ + filterExtensions[0] = "*.xml; *.zip"; //$NON-NLS-1$ filterExtensions[1] = "*.*"; //$NON-NLS-1$ fileDialog.setFilterExtensions(filterExtensions); String filename = fileDialog.open(); - if (filename != null) { - SnippetDefinitions definitions = ModelFactoryForUser.getInstance().load(filename); + try { + if (filename.toLowerCase().endsWith(".zip")){ + ZipFile zip = new ZipFile(new File(filename)); + ZipEntry entry = zip.getEntry("snippets.xml"); + loadMetadata(zip.getInputStream(entry)); + Bundle bundle = Platform.getBundle(SnippetsPlugin.BUNDLE_ID); + unzip(zip, Platform.getStateLocation(bundle).toOSString()); + } else { + loadMetadata(new FileInputStream(filename)); + } + + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (ZipException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private void loadMetadata(InputStream fileInputStream) { + if (fileInputStream != null) { + SnippetDefinitions definitions = ModelFactoryForUser.getInstance().load(fileInputStream); List importCategories = definitions.getCategories(); List currentCategories = SnippetManager.getInstance().getDefinitions().getCategories(); PaletteEntry lastImportEntry = null; @@ -215,4 +349,42 @@ return super.open(); } + + public static final void copyInputStream(InputStream in, OutputStream out) + throws IOException + { + byte[] buffer = new byte[1024]; + int len; + + while((len = in.read(buffer)) >= 0) + out.write(buffer, 0, len); + + in.close(); + out.close(); + } + + public void unzip(ZipFile zipFile, String path) throws FileNotFoundException, IOException { + Enumeration entries; + entries = zipFile.entries(); + + while(entries.hasMoreElements()) { + ZipEntry entry = (ZipEntry)entries.nextElement(); + File file = new File(path + File.separator+ entry.getName()); + if(entry.isDirectory()) { + file.mkdir(); + continue; + } + if (!file.getParentFile().exists()){ + file.getParentFile().mkdirs(); + } + if (entry.getName().toLowerCase().equals("snippets.xml")){ + continue; + } + + copyInputStream(zipFile.getInputStream(entry), new BufferedOutputStream(new FileOutputStream(file))); + } + + zipFile.close(); + } + } Index: src/org/eclipse/wst/common/snippets/internal/palette/ModelFactoryForPlugins.java =================================================================== RCS file: /cvsroot/webtools/common/plugins/org.eclipse.wst.common.snippets/src/org/eclipse/wst/common/snippets/internal/palette/ModelFactoryForPlugins.java,v retrieving revision 1.8 diff -u -r1.8 ModelFactoryForPlugins.java --- src/org/eclipse/wst/common/snippets/internal/palette/ModelFactoryForPlugins.java 10 Apr 2007 17:23:34 -0000 1.8 +++ src/org/eclipse/wst/common/snippets/internal/palette/ModelFactoryForPlugins.java 1 Sep 2009 21:50:26 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2009 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 @@ -169,6 +169,7 @@ setProperty(item, SnippetsPlugin.NAMES.ID, element.getAttribute(SnippetsPlugin.NAMES.ID)); setProperty(item, SnippetsPlugin.NAMES.LABEL, element.getAttribute(SnippetsPlugin.NAMES.LABEL)); setProperty(item, SnippetsPlugin.NAMES.LARGEICON, element.getAttribute(SnippetsPlugin.NAMES.LARGEICON)); + setProperty(item, SnippetsPlugin.NAMES.PROVIDER_ID, element.getAttribute(SnippetsPlugin.NAMES.PROVIDER_ID)); IConfigurationElement[] children = element.getChildren(); for (int i = 0; i < children.length; i++) { Index: src/org/eclipse/wst/common/snippets/internal/palette/UserModelDumper.java =================================================================== RCS file: /cvsroot/webtools/common/plugins/org.eclipse.wst.common.snippets/src/org/eclipse/wst/common/snippets/internal/palette/UserModelDumper.java,v retrieving revision 1.8 diff -u -r1.8 UserModelDumper.java --- src/org/eclipse/wst/common/snippets/internal/palette/UserModelDumper.java 9 Dec 2008 18:15:46 -0000 1.8 +++ src/org/eclipse/wst/common/snippets/internal/palette/UserModelDumper.java 1 Sep 2009 21:50:26 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2009 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 @@ -178,6 +178,8 @@ element.setAttribute(SnippetsPlugin.NAMES.CLASSNAME, ((SnippetPaletteItem) item).getClassName()); if (((SnippetPaletteItem) item).getEditorClassName() != null) element.setAttribute(SnippetsPlugin.NAMES.EDITORCLASSNAME, ((SnippetPaletteItem) item).getEditorClassName()); + if (((SnippetPaletteItem) item).getProvider() != null) + element.setAttribute(SnippetsPlugin.NAMES.PROVIDER_ID, ((SnippetPaletteItem) item).getProvider().getId()); element.appendChild(createContent(doc, item)); ISnippetVariable[] variables = item.getVariables(); for (int i = 0; i < variables.length; i++) { @@ -279,13 +281,8 @@ Logger.log(Logger.ERROR, "could not save " + stream, e); //$NON-NLS-1$ } finally { - try { - stream.close(); - document = null; - } - catch (IOException e) { - // nothing to be done while closing - } + // stream.close(); + document = null; } } Index: src/org/eclipse/wst/common/snippets/internal/ui/EntrySerializer.java =================================================================== RCS file: /cvsroot/webtools/common/plugins/org.eclipse.wst.common.snippets/src/org/eclipse/wst/common/snippets/internal/ui/EntrySerializer.java,v retrieving revision 1.5 diff -u -r1.5 EntrySerializer.java --- src/org/eclipse/wst/common/snippets/internal/ui/EntrySerializer.java 10 Apr 2007 17:23:35 -0000 1.5 +++ src/org/eclipse/wst/common/snippets/internal/ui/EntrySerializer.java 1 Sep 2009 21:50:26 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2009 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 @@ -116,6 +116,8 @@ element.setAttribute(SnippetsPlugin.NAMES.CLASSNAME, item.getClassName()); if (item.getEditorClassName() != null) element.setAttribute(SnippetsPlugin.NAMES.EDITORCLASSNAME, item.getEditorClassName()); + if (item.getProvider() != null) + element.setAttribute(SnippetsPlugin.NAMES.PROVIDER_ID, item.getProvider().getId()); if (item.getContentString() != null) element.appendChild(createContent(doc, item)); ISnippetVariable[] variables = item.getVariables(); Index: src/org/eclipse/wst/common/snippets/internal/ui/EntryDeserializer.java =================================================================== RCS file: /cvsroot/webtools/common/plugins/org.eclipse.wst.common.snippets/src/org/eclipse/wst/common/snippets/internal/ui/EntryDeserializer.java,v retrieving revision 1.5 diff -u -r1.5 EntryDeserializer.java --- src/org/eclipse/wst/common/snippets/internal/ui/EntryDeserializer.java 10 Apr 2007 17:23:35 -0000 1.5 +++ src/org/eclipse/wst/common/snippets/internal/ui/EntryDeserializer.java 1 Sep 2009 21:50:26 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2009 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 @@ -22,6 +22,7 @@ import org.eclipse.wst.common.snippets.internal.palette.SnippetPaletteItem; import org.eclipse.wst.common.snippets.internal.palette.SnippetVariable; import org.eclipse.wst.common.snippets.internal.util.CommonXML; +import org.eclipse.wst.common.snippets.internal.util.SnippetProviderManager; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -72,6 +73,7 @@ item.setCategoryName(element.getAttribute(SnippetsPlugin.NAMES.CATEGORY)); item.setClassName(element.getAttribute(SnippetsPlugin.NAMES.CLASSNAME)); item.setEditorClassName(element.getAttribute(SnippetsPlugin.NAMES.EDITORCLASSNAME)); + item.setProvider(SnippetProviderManager.findProvider(element.getAttribute(SnippetsPlugin.NAMES.PROVIDER_ID))); NodeList children = element.getChildNodes(); int length = children.getLength(); for (int i = 0; i < length; i++) { Index: src/org/eclipse/wst/common/snippets/internal/ui/SnippetsCustomizer.java =================================================================== RCS file: /cvsroot/webtools/common/plugins/org.eclipse.wst.common.snippets/src/org/eclipse/wst/common/snippets/internal/ui/SnippetsCustomizer.java,v retrieving revision 1.4 diff -u -r1.4 SnippetsCustomizer.java --- src/org/eclipse/wst/common/snippets/internal/ui/SnippetsCustomizer.java 10 Apr 2007 17:23:35 -0000 1.4 +++ src/org/eclipse/wst/common/snippets/internal/ui/SnippetsCustomizer.java 1 Sep 2009 21:50:26 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2009 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 @@ -10,9 +10,11 @@ *******************************************************************************/ package org.eclipse.wst.common.snippets.internal.ui; +import java.io.File; import java.util.ArrayList; import java.util.List; +import org.eclipse.core.runtime.IPath; import org.eclipse.gef.palette.PaletteContainer; import org.eclipse.gef.palette.PaletteDrawer; import org.eclipse.gef.palette.PaletteEntry; @@ -31,8 +33,10 @@ public class SnippetsCustomizer extends PaletteCustomizer { + protected List activeEditors = new ArrayList(); protected List factories = null; + private List deletedIds = new ArrayList(); public SnippetsCustomizer() { super(); @@ -117,6 +121,13 @@ Logger.logException(e); } } + + for (int i = 0; i < deletedIds.size(); i++) { + IPath path = SnippetManager.getInstance().getStorageLocation(deletedIds.get(i).toString()); + File folder = new File(path.toOSString()); + deleteFolders(folder); + } + deletedIds.clear(); activeEditors = new ArrayList(0); @@ -127,4 +138,25 @@ Logger.logException(e); } } + + private void deleteFolders(File folder) { + if (!folder.exists()){ + return; + } + File[] listFiles = folder.listFiles(); + for (int i = 0; i < listFiles.length; i++) { + if (listFiles[i].isDirectory()){ + deleteFolders(listFiles[i]); + } else { + listFiles[i].delete(); + } + } + folder.delete(); + } + + public void performDelete(PaletteEntry entry) { + deletedIds.add(entry.getId()); + super.performDelete(entry); + } + } Index: src/org/eclipse/wst/common/snippets/internal/ui/SnippetTemplateEntryPage.java =================================================================== RCS file: /cvsroot/webtools/common/plugins/org.eclipse.wst.common.snippets/src/org/eclipse/wst/common/snippets/internal/ui/SnippetTemplateEntryPage.java,v retrieving revision 1.5 diff -u -r1.5 SnippetTemplateEntryPage.java --- src/org/eclipse/wst/common/snippets/internal/ui/SnippetTemplateEntryPage.java 10 Apr 2007 17:23:35 -0000 1.5 +++ src/org/eclipse/wst/common/snippets/internal/ui/SnippetTemplateEntryPage.java 1 Sep 2009 21:50:26 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2009 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 @@ -38,17 +38,21 @@ editor.addModifyListener(this); editor.setItem((SnippetPaletteItem) entry); editor.createContents((Composite) getControl()); - // it can't be known in advance since the editor is unknown as - // well + /* + * Can't be known in advance since the editor content is unknown + */ ((Composite) getControl()).setTabList(null); } } protected ISnippetEditor getEditor(SnippetPaletteItem item) { ISnippetEditor snippetEditor = null; - if (item.getSourceType() != ISnippetsEntry.SNIPPET_SOURCE_PLUGINS) { + if (item.getSourceType() == ISnippetsEntry.SNIPPET_SOURCE_USER || item.getSourceType() == ISnippetsEntry.SNIPPET_SOURCE_WORKSPACE) { snippetEditor = new VariableItemEditor(); } + else if (item.getProvider() != null) { + // TODO: let a provider provide its own editor? + } return snippetEditor; } Index: src/org/eclipse/wst/common/snippets/internal/ui/SnippetsView.java =================================================================== RCS file: /cvsroot/webtools/common/plugins/org.eclipse.wst.common.snippets/src/org/eclipse/wst/common/snippets/internal/ui/SnippetsView.java,v retrieving revision 1.8 diff -u -r1.8 SnippetsView.java --- src/org/eclipse/wst/common/snippets/internal/ui/SnippetsView.java 9 Dec 2008 06:00:26 -0000 1.8 +++ src/org/eclipse/wst/common/snippets/internal/ui/SnippetsView.java 1 Sep 2009 21:50:26 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. + * Copyright (c) 2004, 2009 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 @@ -83,7 +83,6 @@ import org.eclipse.wst.common.snippets.internal.palette.SnippetPaletteRoot; import org.eclipse.wst.common.snippets.internal.util.UserDrawerSelector; import org.eclipse.wst.common.snippets.internal.util.VisibilityUtil; -import org.eclipse.wst.common.snippets.ui.DefaultSnippetInsertion; import org.eclipse.wst.common.snippets.ui.ISnippetInsertion; import org.osgi.framework.Bundle; @@ -199,8 +198,11 @@ } } } + if (insertion == null) { - insertion = new DefaultSnippetInsertion(); + if (item.getProvider()!= null){ + insertion = item.getProvider().getSnippetInsertion(); + } } return insertion; } @@ -828,6 +830,8 @@ insertion.setItem(item); insertion.setEditorPart(getSite().getPage().getActiveEditor()); supportedTypes = insertion.getTransfers(); + } else { + supportedTypes = new Transfer[]{TextTransfer.getInstance()}; } } else { Index: plugin.properties =================================================================== RCS file: /cvsroot/webtools/common/plugins/org.eclipse.wst.common.snippets/plugin.properties,v retrieving revision 1.4 diff -u -r1.4 plugin.properties --- plugin.properties 10 Apr 2007 17:23:36 -0000 1.4 +++ plugin.properties 1 Sep 2009 21:50:26 -0000 @@ -13,3 +13,5 @@ Snippets.name=Snippets Snippets_View_Contributions_Extension.name=Snippets View Contributions Extension Add_to_Snippets.name=Add to Snippets... + +extension-point.name.0 = SnippetProvider \ No newline at end of file Index: plugin.xml =================================================================== RCS file: /cvsroot/webtools/common/plugins/org.eclipse.wst.common.snippets/plugin.xml,v retrieving revision 1.9 diff -u -r1.9 plugin.xml --- plugin.xml 30 Apr 2007 19:32:42 -0000 1.9 +++ plugin.xml 1 Sep 2009 21:50:26 -0000 @@ -6,6 +6,11 @@ id="SnippetContributions" name="%Snippets_View_Contributions_Extension.name" schema="schema/SnippetContributions.exsd" /> + + @@ -175,4 +180,17 @@ + + + + + + + + + + + Index: src/org/eclipse/wst/common/snippets/internal/actions/AddToSnippetsEditorActionDelegate.java =================================================================== RCS file: /cvsroot/webtools/common/plugins/org.eclipse.wst.common.snippets/src/org/eclipse/wst/common/snippets/internal/actions/AddToSnippetsEditorActionDelegate.java,v retrieving revision 1.5 diff -u -r1.5 AddToSnippetsEditorActionDelegate.java --- src/org/eclipse/wst/common/snippets/internal/actions/AddToSnippetsEditorActionDelegate.java 10 Apr 2007 17:23:36 -0000 1.5 +++ src/org/eclipse/wst/common/snippets/internal/actions/AddToSnippetsEditorActionDelegate.java 1 Sep 2009 21:50:26 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2009 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 @@ -10,35 +10,29 @@ *******************************************************************************/ package org.eclipse.wst.common.snippets.internal.actions; +import org.eclipse.core.runtime.CoreException; import org.eclipse.gef.palette.PaletteDrawer; import org.eclipse.gef.ui.palette.customize.PaletteCustomizerDialog; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.IEditorActionDelegate; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IViewActionDelegate; import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.PartInitException; -import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.wst.common.snippets.core.ISnippetProvider; import org.eclipse.wst.common.snippets.internal.Logger; import org.eclipse.wst.common.snippets.internal.SnippetsPlugin; import org.eclipse.wst.common.snippets.internal.palette.SnippetPaletteItem; -import org.eclipse.wst.common.snippets.internal.palette.SnippetPaletteItemFactory; import org.eclipse.wst.common.snippets.internal.ui.SnippetsView; -import org.eclipse.wst.common.snippets.internal.util.StringUtils; +import org.eclipse.wst.common.snippets.internal.util.SnippetProviderManager; import org.eclipse.wst.common.snippets.internal.util.UserDrawerSelector; public class AddToSnippetsEditorActionDelegate implements IEditorActionDelegate, IViewActionDelegate { - private IAction fAction; private IEditorPart fEditorPart; - private IViewPart fViewPart = null; + private ISnippetProvider snippetProvider; /** * @@ -47,35 +41,6 @@ super(); } - public IDocument getDocument() { - return getTextEditor().getDocumentProvider().getDocument(fEditorPart.getEditorInput()); - } - - protected ITextSelection getSelection() { - ITextEditor editor = getTextEditor(); - if (editor != null) { - ISelection selection = editor.getSelectionProvider().getSelection(); - if (selection instanceof ITextSelection) { - return (ITextSelection) selection; - } - } - return new TextSelection(0, 0); - } - - protected ITextEditor getTextEditor() { - ITextEditor editor = null; - IWorkbenchPart activePart = fViewPart; - if (activePart == null) { - activePart = fEditorPart; - } - if (activePart instanceof ITextEditor) { - editor = (ITextEditor) activePart; - } - if (editor == null) { - editor = (ITextEditor) activePart.getAdapter(ITextEditor.class); - } - return editor; - } /** * Prompts the user as needed to obtain a category to contain the new @@ -90,15 +55,10 @@ return drawer; } - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart) - */ public void init(IViewPart view) { - fViewPart = view; } + /* * (non-Javadoc) * @@ -108,25 +68,23 @@ PaletteDrawer drawer = getUserDrawer(); if (drawer != null) { - ITextSelection selection = getSelection(); - String selectedText = null; + if (snippetProvider ==null){ + snippetProvider = SnippetProviderManager.getApplicableProvider(fEditorPart); + if (snippetProvider ==null){ + return; + } + } + try { - selectedText = getDocument().get(selection.getOffset(), selection.getLength()); - - SnippetPaletteItem item = (SnippetPaletteItem) new SnippetPaletteItemFactory().createNewEntry(fEditorPart.getSite().getShell(), drawer); - item.setDescription(StringUtils.firstLineOf(selectedText).trim() + "..."); //$NON-NLS-1$ - item.setContentString(selectedText); - - IViewPart snippets = fEditorPart.getEditorSite().getPage().showView(SnippetsPlugin.NAMES.VIEW_ID); //$NON-NLS-1$ + SnippetPaletteItem item = snippetProvider.createSnippet(drawer); + IViewPart snippets = fEditorPart.getEditorSite().getPage().showView(SnippetsPlugin.NAMES.VIEW_ID); PaletteCustomizerDialog dialog = ((SnippetsView) snippets).getViewer().getCustomizerDialog(); dialog.setDefaultSelection(item); dialog.open(); - } - catch (BadLocationException e) { + } catch (PartInitException e) { + Logger.logException(e); + } catch (CoreException e) { Logger.logException(e); - } - catch (PartInitException e1) { - Logger.logException(e1); } } } @@ -138,8 +96,11 @@ * org.eclipse.jface.viewers.ISelection) */ public void selectionChanged(IAction action, ISelection selection) { - fAction = action; - updateWith(selection); + if (selection != null && fEditorPart != null && snippetProvider != null) { + action.setEnabled(snippetProvider.isActionEnabled(selection)); + } + else + action.setEnabled(false); } /* @@ -150,26 +111,11 @@ */ public void setActiveEditor(IAction action, IEditorPart targetEditor) { fEditorPart = targetEditor; - fAction = action; - if (targetEditor != null && targetEditor.getEditorSite() != null && targetEditor.getEditorSite().getSelectionProvider() != null) { - updateWith(targetEditor.getEditorSite().getSelectionProvider().getSelection()); - } + action.setEnabled(fEditorPart != null); + if (fEditorPart != null) + snippetProvider = SnippetProviderManager.getApplicableProvider(fEditorPart); + else + snippetProvider = null; } - public void updateWith(ISelection selection) { - if (fAction != null) { - boolean enable = false; - if (selection != null) { - if (selection instanceof ITextSelection) { - if (((ITextSelection) selection).getLength() > 0) { - enable = true; - } - } - else { - enable = !selection.isEmpty(); - } - } - fAction.setEnabled(enable); - } - } } Index: .settings/org.eclipse.pde.prefs =================================================================== RCS file: /cvsroot/webtools/common/plugins/org.eclipse.wst.common.snippets/.settings/org.eclipse.pde.prefs,v retrieving revision 1.6 diff -u -r1.6 org.eclipse.pde.prefs --- .settings/org.eclipse.pde.prefs 20 Aug 2006 01:15:35 -0000 1.6 +++ .settings/org.eclipse.pde.prefs 1 Sep 2009 21:50:26 -0000 @@ -1,16 +1,28 @@ -#Mon Apr 17 02:01:33 EDT 2006 +#Mon Aug 31 15:06:59 EDT 2009 +compilers.f.unresolved-features=1 +compilers.f.unresolved-plugins=1 compilers.incompatible-environment=0 compilers.p.build=0 compilers.p.deprecated=1 +compilers.p.discouraged-class=1 compilers.p.illegal-att-value=0 +compilers.p.internal=1 +compilers.p.missing-packages=0 +compilers.p.missing-version-export-package=2 +compilers.p.missing-version-import-package=2 +compilers.p.missing-version-require-bundle=0 compilers.p.no-required-att=0 compilers.p.not-externalized-att=0 compilers.p.unknown-attribute=0 compilers.p.unknown-class=0 compilers.p.unknown-element=0 +compilers.p.unknown-identifier=1 compilers.p.unknown-resource=0 compilers.p.unresolved-ex-points=0 compilers.p.unresolved-import=0 compilers.p.unused-element-or-attribute=0 +compilers.s.create-docs=false +compilers.s.doc-folder=doc +compilers.s.open-tags=1 compilers.use-project=true eclipse.preferences.version=1 Index: .settings/org.eclipse.jdt.core.prefs =================================================================== RCS file: /cvsroot/webtools/common/plugins/org.eclipse.wst.common.snippets/.settings/org.eclipse.jdt.core.prefs,v retrieving revision 1.7 diff -u -r1.7 org.eclipse.jdt.core.prefs --- .settings/org.eclipse.jdt.core.prefs 28 Mar 2007 07:13:53 -0000 1.7 +++ .settings/org.eclipse.jdt.core.prefs 1 Sep 2009 21:50:26 -0000 @@ -1,4 +1,4 @@ -#Wed Mar 28 03:12:48 EDT 2007 +#Mon Aug 31 15:11:18 EDT 2009 eclipse.preferences.version=1 org.eclipse.jdt.core.builder.cleanOutputFolder=clean org.eclipse.jdt.core.builder.duplicateResourceTask=warning @@ -7,7 +7,7 @@ org.eclipse.jdt.core.circularClasspath=error org.eclipse.jdt.core.classpath.exclusionPatterns=enabled org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.4 Index: src/org/eclipse/wst/common/snippets/internal/SnippetsPlugin.java =================================================================== RCS file: /cvsroot/webtools/common/plugins/org.eclipse.wst.common.snippets/src/org/eclipse/wst/common/snippets/internal/SnippetsPlugin.java,v retrieving revision 1.5 diff -u -r1.5 SnippetsPlugin.java --- src/org/eclipse/wst/common/snippets/internal/SnippetsPlugin.java 10 Apr 2007 17:23:35 -0000 1.5 +++ src/org/eclipse/wst/common/snippets/internal/SnippetsPlugin.java 1 Sep 2009 21:50:26 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2009 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 @@ -43,6 +43,7 @@ String VARIABLES = "variables"; //$NON-NLS-1$ String VERSION = "version"; //$NON-NLS-1$ String VIEW_ID = "org.eclipse.wst.common.snippets.internal.ui.SnippetsView"; //$NON-NLS-1$ + String PROVIDER_ID = "snippetProvider";//$NON-NLS-1$ } public static final String BUNDLE_ID = "org.eclipse.wst.common.snippets"; //$NON-NLS-1$ Index: src/org/eclipse/wst/common/snippets/internal/model/SnippetManager.java =================================================================== RCS file: /cvsroot/webtools/common/plugins/org.eclipse.wst.common.snippets/src/org/eclipse/wst/common/snippets/internal/model/SnippetManager.java,v retrieving revision 1.6 diff -u -r1.6 SnippetManager.java --- src/org/eclipse/wst/common/snippets/internal/model/SnippetManager.java 18 Dec 2007 06:05:17 -0000 1.6 +++ src/org/eclipse/wst/common/snippets/internal/model/SnippetManager.java 1 Sep 2009 21:50:26 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2009 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 @@ -13,9 +13,12 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; @@ -23,6 +26,15 @@ import javax.xml.parsers.DocumentBuilder; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; import org.eclipse.gef.palette.PaletteContainer; import org.eclipse.wst.common.snippets.core.ISnippetCategory; import org.eclipse.wst.common.snippets.core.ISnippetsEntry; @@ -40,6 +52,7 @@ import org.eclipse.wst.common.snippets.internal.palette.WorkspaceModelDumper; import org.eclipse.wst.common.snippets.internal.team.CategoryFileInfo; import org.eclipse.wst.common.snippets.internal.util.CommonXML; +import org.osgi.framework.Bundle; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -55,6 +68,8 @@ */ public class SnippetManager implements ISnippetManager, PropertyChangeListener { + private static final String STORAGE_FOLDER_NAME = "storage"; //$NON-NLS-1$ + private static File hiddenStateFile = new File("/hidden.xml"); //$NON-NLS-1$ private static SnippetManager instance = null; @@ -63,11 +78,19 @@ if (instance == null) { instance = new SnippetManager(); try { - hiddenStateFile = SnippetsPlugin.getDefault().getStateLocation().append("hidden.xml").toFile(); //$NON-NLS-1$ + hiddenStateFile = SnippetsPlugin.getDefault().getStateLocation().append("hidden.xml").toFile(); } catch (Exception e) { hiddenStateFile = new File("/hidden.xml"); //$NON-NLS-1$ } + + try { + File storageLocation = SnippetsPlugin.getDefault().getStateLocation().append(STORAGE_FOLDER_NAME).toFile(); + storageLocation.mkdirs(); + } + catch (SecurityException e) { + Logger.logException(e); + } // hook resource listener and load categories from workspace // nsd_TODO: disable in-workspace support until fully stabilized // SnippetsPlugin.getDefault().initializeResourceChangeListener(); @@ -407,5 +430,92 @@ Logger.logException(e); } } + + /** + * @param id + * @return the computed storage location for a snippet with this ID + */ + public IPath getStorageLocation(String id) { + Bundle bundle = Platform.getBundle(SnippetsPlugin.BUNDLE_ID); + return Platform.getStateLocation(bundle).append(STORAGE_FOLDER_NAME).addTrailingSeparator().append(id); + } + + /** + * Helper method for saving resources in designated snippet resource folder. + * + * @param snippetId - UID of the snippet that is saving content. + * @param pathList - Project relative path list. The resources are copied in the same structure + * in the storage path. e.g. having test.jsp file in project root will result in + * test.jsp in the storage root. If the jsp is in [Project Root]/resources/test.jsp + * this will result in [Snippet Storage Root]/resources/test.jsp + * @return + */ + public IStatus moveFilesInStorageFolder(IPath snippetStorage, IPath[] pathList, IProject project){ + File storageFolder = new File(snippetStorage.toOSString()); + if (!storageFolder.exists()){ + if (!storageFolder.mkdirs()){ + return createErrorStatus("Could not create snippet storage folder.", null); + } + } + for (int i = 0; i < pathList.length; i++) { + IFile file = project.getFile(pathList[i]); + IPath destPath = snippetStorage.append(pathList[i]); + File destination = new File(destPath.toOSString()); + if (!destination.getParentFile().exists()){ + if (!destination.getParentFile().mkdirs()){ + return createErrorStatus("Could not create snippet storage folder.", null); + } + } + try { + copy(file, destination); + } catch (FileNotFoundException e) { + return createErrorStatus(e.getLocalizedMessage(), e); + } catch (IOException e) { + return createErrorStatus(e.getLocalizedMessage(), e); + } catch (CoreException e) { + return e.getStatus(); + } + } + + return Status.OK_STATUS; + } + + public IStatus moveFilesInWorkspace(File[] fileList, IProject target, IPath storagePath) { + for (int i = 0; i < fileList.length; i++) { + String fileRelativePath = fileList[i].getAbsolutePath().substring(storagePath.toOSString().length()); + IFile ifile = target.getFile(new Path(fileRelativePath)); + try { + ifile.create(new FileInputStream(fileList[i]), true, new NullProgressMonitor()); + } catch (FileNotFoundException e) { + return createErrorStatus(e.getLocalizedMessage(), e); + } catch (CoreException e) { + return createErrorStatus(e.getLocalizedMessage(), e); + } + } + + return Status.OK_STATUS; + } + + private void copy(IFile source, File destination) throws FileNotFoundException, IOException, CoreException{ + copy(source.getContents(), new FileOutputStream(destination)); + } + + private void copy(InputStream in, OutputStream out) throws IOException { + byte[] buffer = new byte[4096]; + try { + int n = in.read(buffer); + while (n > 0) { + out.write(buffer, 0, n); + n = in.read(buffer); + } + } finally { + in.close(); + out.close(); + } + } + + private IStatus createErrorStatus(String msg, Exception e) { + return new Status(IStatus.ERROR, SnippetsPlugin.BUNDLE_ID, msg, e); + } } Index: schema/SnippetProvider.exsd =================================================================== RCS file: schema/SnippetProvider.exsd diff -N schema/SnippetProvider.exsd --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ schema/SnippetProvider.exsd 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,115 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 highest +100 lowest + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + Index: src/org/eclipse/wst/common/snippets/internal/AbstractSnippetProvider.java =================================================================== RCS file: src/org/eclipse/wst/common/snippets/internal/AbstractSnippetProvider.java diff -N src/org/eclipse/wst/common/snippets/internal/AbstractSnippetProvider.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/common/snippets/internal/AbstractSnippetProvider.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2009 SAP AG 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: + * SAP AG - initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.common.snippets.internal; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.gef.palette.PaletteEntry; +import org.eclipse.ui.IEditorPart; +import org.eclipse.wst.common.snippets.core.ISnippetProvider; +import org.eclipse.wst.common.snippets.internal.palette.SnippetPaletteItem; +import org.eclipse.wst.common.snippets.internal.palette.SnippetPaletteItemFactory; + +public abstract class AbstractSnippetProvider implements ISnippetProvider { + + protected IEditorPart fEditorPart; + + public void setEditor(IEditorPart editor) { + fEditorPart = editor; + + } + + public SnippetPaletteItem createSnippet(PaletteEntry drawer) throws CoreException { + SnippetPaletteItem snippet = createSnippetMetadata(drawer); + return snippet; + } + + protected SnippetPaletteItem createSnippetMetadata(PaletteEntry drawer) throws CoreException { + SnippetPaletteItem item = (SnippetPaletteItem) new SnippetPaletteItemFactory().createNewEntry(fEditorPart.getSite().getShell(), drawer); +// item.setSourceType(ISnippetsEntry.SNIPPET_SOURCE_PLUGINS); + item.setProvider(this); + IStatus status = saveAdditionalContent(item.getStorageLocation()); + if (status!= null && status.getSeverity() == IStatus.ERROR){ + throw new CoreException(status); + } + return item; + } + +} Index: src/org/eclipse/wst/common/snippets/internal/SnippetContributor.java =================================================================== RCS file: src/org/eclipse/wst/common/snippets/internal/SnippetContributor.java diff -N src/org/eclipse/wst/common/snippets/internal/SnippetContributor.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/common/snippets/internal/SnippetContributor.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2009 SAP AG 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: + * SAP AG - initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.common.snippets.internal; + +import org.eclipse.core.expressions.EvaluationContext; +import org.eclipse.core.expressions.EvaluationResult; +import org.eclipse.core.expressions.Expression; +import org.eclipse.core.expressions.ExpressionConverter; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.wst.common.snippets.core.ISnippetProvider; + +public class SnippetContributor { + + public static final String ID_EXTENSION_POINT_PROVIDER = SnippetsPlugin.BUNDLE_ID + ".SnippetProvider"; //$NON-NLS-1$ + public static final String CLASS = "class"; //$NON-NLS-1$ + public static final String PRIO = "priority"; //$NON-NLS-1$ + public static final String ENABLEMENT = "enablement"; //$NON-NLS-1$ + + private ISnippetProvider provider; + private IConfigurationElement extPointElement; + // 100 = lowest, 0 = highest + private byte priority; + + private boolean initExecuted = false; + + + public SnippetContributor(IConfigurationElement extPointElement) { + super(); + this.extPointElement = extPointElement; + initPriority(); + } + + private void initPriority() { + if (extPointElement.getAttribute(PRIO) != null){ + try{ + priority = (byte) Integer.parseInt(extPointElement.getAttribute(PRIO)); + if(priority < 0 || priority >100){ + priority = 100; + } + }catch (NumberFormatException e){ + priority = 100; + Logger.logException(e); + } + } + } + + private void initProvider() { + initExecuted = true; + try { + provider = (ISnippetProvider) extPointElement.createExecutableExtension(CLASS); + } catch (CoreException e) { + Logger.logException(e); + } + + + } + + + public boolean isApplicable(Object o) { + IConfigurationElement[] configurationElements = extPointElement.getChildren(ENABLEMENT); + boolean enabled = false; + for (int i = 0; i < configurationElements.length; i++) { + try { + enabled |= testEnablement(configurationElements[i], o); + } catch (CoreException e) { + //nothing to do testEnablement fails. + return false; + } + } + return enabled; + } + + private boolean testEnablement(IConfigurationElement enable, Object o) throws CoreException{ + Expression exp= ExpressionConverter.getDefault().perform(enable); + EvaluationContext context = new EvaluationContext(null, o); + context.setAllowPluginActivation(true); + return EvaluationResult.TRUE == exp.evaluate(context); + } + + + public ISnippetProvider getProvider() { + if (!initExecuted){ + initProvider(); + } + return provider; + } + + public byte getPriority() { + return priority; + } + + public String toString() { + return super.toString() + ":" + extPointElement.getAttribute(CLASS); + } +} Index: src/org/eclipse/wst/common/snippets/internal/dnd/SnippetTransfer.java =================================================================== RCS file: src/org/eclipse/wst/common/snippets/internal/dnd/SnippetTransfer.java diff -N src/org/eclipse/wst/common/snippets/internal/dnd/SnippetTransfer.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/common/snippets/internal/dnd/SnippetTransfer.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2009 SAP AG 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: + * SAP AG - initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.common.snippets.internal.dnd; + + +import org.eclipse.swt.dnd.ByteArrayTransfer; +import org.eclipse.swt.dnd.TransferData; + + +/** + * This derived implementation of a byte array transfer short circuits the transfer process + * so that a local transfer does not serialize the object + * and hence can and will return the original object, not just a clone. + * You only really need ever know about {@link #getInstance ObjectTransfer.getInstance()}, + * so that you can include it in when adding drag support to a viewer. + * See {@link EditingDomainViewerDropAdapter} and {@link ViewerDragAdapter} for more details. + *

+ * As an addded guard, the time is recorded and serialized in javaToNative + * to that navive to java can ensure that it's returns the value that was really to have been transferred. + */ +public class SnippetTransfer extends ByteArrayTransfer +{ + /** + * This is the register transfer type name. + */ + protected static final String TYPE_NAME = "local-transfer-format"; + + /** + * This is the ID that is registered to the name. + */ + protected static final int TYPE_ID = registerType(TYPE_NAME); + + /** + * This is initialized and returned by {@link #getInstance}. + */ + protected static SnippetTransfer instance; + + /** + * This returns the one instance of this transfer agent. + */ + public static SnippetTransfer getInstance() + { + if (instance == null) + { + instance = new SnippetTransfer(); + } + + return instance; + } + + /** + * This records the time at which the transfer data was recorded. + */ + protected long startTime; + + /** + * This records the data being transferred. + */ + protected Object object; + + /** + * This creates an instance; typically you get one from {@link #getInstance}. + */ + protected SnippetTransfer() + { + } + + /** + * This returns the transfer ids that this agent supports. + */ + protected int[] getTypeIds() + { + return new int[] { TYPE_ID }; + } + + /** + * This returns the transfer names that this agent supports. + */ + public String[] getTypeNames() + { + return new String[] { TYPE_NAME }; + } + + /** + * This records the object and current time and encodes only the current time into the transfer data. + */ + public void javaToNative(Object object, TransferData transferData) + { + startTime = System.currentTimeMillis(); + this.object = object; + if (transferData != null) + { + super.javaToNative(String.valueOf(startTime).getBytes(), transferData); + } + } + + /** + * This decodes the time of the transfer and returns the recorded the object if the recorded time and the decoded time match. + */ + public Object nativeToJava(TransferData transferData) + { + long startTime = Long.valueOf(new String((byte[])super.nativeToJava(transferData))).longValue(); + return + this.startTime == startTime ? + object : + null; + } +} Index: src/org/eclipse/wst/common/snippets/ui/TextSnippetProvider.java =================================================================== RCS file: src/org/eclipse/wst/common/snippets/ui/TextSnippetProvider.java diff -N src/org/eclipse/wst/common/snippets/ui/TextSnippetProvider.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/common/snippets/ui/TextSnippetProvider.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2009 SAP AG 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: + * SAP AG - initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.common.snippets.ui; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.gef.palette.PaletteEntry; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.wst.common.snippets.core.ISnippetProvider; +import org.eclipse.wst.common.snippets.internal.AbstractSnippetProvider; +import org.eclipse.wst.common.snippets.internal.Logger; +import org.eclipse.wst.common.snippets.internal.palette.SnippetPaletteItem; +import org.eclipse.wst.common.snippets.internal.util.StringUtils; + +public class TextSnippetProvider extends AbstractSnippetProvider implements ISnippetProvider { + + public SnippetPaletteItem createSnippet(PaletteEntry drawer) throws CoreException { + SnippetPaletteItem item = super.createSnippet(drawer); + ITextSelection selection = getTextSelection(); + try { + String selectedText = getDocument().get(selection.getOffset(), selection.getLength()); + item.setDescription(StringUtils.firstLineOf(selectedText).trim() + "..."); //$NON-NLS-1$ + item.setContentString(selectedText); + } + catch (BadLocationException e) { + Logger.logException(e); + } + return item; + } + + + protected ITextSelection getTextSelection() { + ITextEditor editor = getTextEditor(); + if (editor != null) { + ISelection selection = editor.getSelectionProvider().getSelection(); + if (selection instanceof ITextSelection) { + return (ITextSelection) selection; + } + } + return null; + } + + protected ITextEditor getTextEditor() { + ITextEditor editor = null; + IWorkbenchPart activePart = fEditorPart; + + if (activePart instanceof ITextEditor) { + editor = (ITextEditor) activePart; + } + if (editor == null) { + editor = (ITextEditor) activePart.getAdapter(ITextEditor.class); + } + return editor; + } + + public boolean isActionEnabled(ISelection selection) { + boolean enable = false; + if (selection != null) { + if (selection instanceof ITextSelection) { + if (((ITextSelection) selection).getLength() > 0) { + enable = true; + } + } + else { + enable = !selection.isEmpty(); + } + } + return enable; + } + + public IDocument getDocument() { + return getTextEditor().getDocumentProvider().getDocument(fEditorPart.getEditorInput()); + } + + public IStatus saveAdditionalContent(IPath path) { + return Status.OK_STATUS; + } + + + public ISnippetInsertion getSnippetInsertion() { + return new DefaultSnippetInsertion(); + } + + + public String getId() { + return TextSnippetProvider.class.getName(); + } + +} Index: src/org/eclipse/wst/common/snippets/internal/util/SnippetProviderManager.java =================================================================== RCS file: src/org/eclipse/wst/common/snippets/internal/util/SnippetProviderManager.java diff -N src/org/eclipse/wst/common/snippets/internal/util/SnippetProviderManager.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/common/snippets/internal/util/SnippetProviderManager.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2009 SAP AG 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: + * SAP AG - initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.common.snippets.internal.util; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.Platform; +import org.eclipse.ui.IEditorPart; +import org.eclipse.wst.common.snippets.core.ISnippetProvider; +import org.eclipse.wst.common.snippets.internal.SnippetContributor; +import org.eclipse.wst.common.snippets.ui.TextSnippetProvider; + + +public class SnippetProviderManager { + + private static ISnippetProvider[] getProviders() { + IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(SnippetContributor.ID_EXTENSION_POINT_PROVIDER); + IExtension[] extensions = extensionPoint.getExtensions(); + List providerList = new ArrayList(); + for (int i = 0; i < extensions.length; i++) { + IConfigurationElement[] configurationElements = extensions[i].getConfigurationElements(); + for (int j = 0; j < configurationElements.length; j++) { + SnippetContributor sc = new SnippetContributor(configurationElements[j]); + if (sc.getProvider() != null){ + providerList.add(sc.getProvider()); + } + } + + } + return (ISnippetProvider[]) providerList.toArray(new ISnippetProvider[providerList.size()]); + } + + public static ISnippetProvider findProvider(String id) { + Assert.isNotNull(id); + ISnippetProvider[] providers = getProviders(); + for (int i = 0; i < providers.length; i++) { + if(id.equals(providers[i].getId())) + return providers[i]; + } + + return new TextSnippetProvider(); + } + + public static ISnippetProvider getApplicableProvider(IEditorPart targetEditor) { + SnippetContributor applicableContributor = null; + IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(SnippetContributor.ID_EXTENSION_POINT_PROVIDER); + if (extensionPoint != null) { + IExtension[] extensions = extensionPoint.getExtensions(); + for (int i = 0; i < extensions.length; i++) { + IConfigurationElement[] configurationElements = extensions[i].getConfigurationElements(); + for (int j = 0; j < configurationElements.length; j++) { + SnippetContributor sc = new SnippetContributor(configurationElements[j]); + if (sc.isApplicable(targetEditor)) { + if (applicableContributor == null || applicableContributor.getPriority() > sc.getPriority()) { + applicableContributor = sc; + } + } + } + } + } + if (applicableContributor == null){ + return null; + } + ISnippetProvider provider = applicableContributor.getProvider(); + // a null provider is an error condition + if (provider != null) { + provider.setEditor(targetEditor); + } + return provider; + } + + + + +} Index: src/org/eclipse/wst/common/snippets/core/ISnippetProvider.java =================================================================== RCS file: src/org/eclipse/wst/common/snippets/core/ISnippetProvider.java diff -N src/org/eclipse/wst/common/snippets/core/ISnippetProvider.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/common/snippets/core/ISnippetProvider.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,26 @@ +package org.eclipse.wst.common.snippets.core; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.gef.palette.PaletteEntry; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IEditorPart; +import org.eclipse.wst.common.snippets.internal.palette.SnippetPaletteItem; +import org.eclipse.wst.common.snippets.ui.ISnippetInsertion; + +public interface ISnippetProvider { + + public SnippetPaletteItem createSnippet(PaletteEntry drawer) throws CoreException ; + + public boolean isActionEnabled(ISelection selection); + + public IStatus saveAdditionalContent(IPath path); + + public ISnippetInsertion getSnippetInsertion(); + + public String getId(); + + public void setEditor(IEditorPart editor); + +} #P org.eclipse.wst.common.snippets.tests Index: META-INF/MANIFEST.MF =================================================================== RCS file: /cvsroot/webtools/common/tests/org.eclipse.wst.common.snippets.tests/META-INF/MANIFEST.MF,v retrieving revision 1.9 diff -u -r1.9 MANIFEST.MF --- META-INF/MANIFEST.MF 1 Jun 2008 07:24:12 -0000 1.9 +++ META-INF/MANIFEST.MF 1 Sep 2009 21:50:27 -0000 @@ -17,6 +17,7 @@ org.eclipse.ui, org.eclipse.wst.common.snippets, org.eclipse.ui.ide, - org.eclipse.ui.workbench.texteditor + org.eclipse.ui.workbench.texteditor, + org.eclipse.gef Eclipse-LazyStart: true Bundle-RequiredExecutionEnvironment: J2SE-1.4 Index: src/org/eclipse/wst/common/snippets/tests/AllTests.java =================================================================== RCS file: /cvsroot/webtools/common/tests/org.eclipse.wst.common.snippets.tests/src/org/eclipse/wst/common/snippets/tests/AllTests.java,v retrieving revision 1.1 diff -u -r1.1 AllTests.java --- src/org/eclipse/wst/common/snippets/tests/AllTests.java 30 Nov 2005 11:36:42 -0000 1.1 +++ src/org/eclipse/wst/common/snippets/tests/AllTests.java 1 Sep 2009 21:50:27 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. + * Copyright (c) 2005, 2009 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 @@ -15,6 +15,9 @@ import junit.framework.TestSuite; import org.eclipse.wst.common.snippets.core.tests.SnippetCoreTests; +import org.eclipse.wst.common.snippets.tests.providers.SnippetProviderExtensionTests; +import org.eclipse.wst.common.snippets.tests.providers.TextProviderTests; +import org.eclipse.wst.common.snippets.tests.scenarios.ObjectOrientedSnippetScenario; import org.eclipse.wst.common.snippets.ui.tests.SnippetUITests; @@ -27,6 +30,9 @@ public AllTests() { super(); addTest(new TestSuite(SnippetCoreTests.class)); + addTest(new TestSuite(SnippetProviderExtensionTests.class)); + addTest(new TestSuite(TextProviderTests.class)); addTest(new TestSuite(SnippetUITests.class)); + addTest(new TestSuite(ObjectOrientedSnippetScenario.class)); } } Index: src/org/eclipse/wst/common/snippets/tests/TestsPlugin.java =================================================================== RCS file: /cvsroot/webtools/common/tests/org.eclipse.wst.common.snippets.tests/src/org/eclipse/wst/common/snippets/tests/TestsPlugin.java,v retrieving revision 1.1 diff -u -r1.1 TestsPlugin.java --- src/org/eclipse/wst/common/snippets/tests/TestsPlugin.java 30 Nov 2005 11:36:42 -0000 1.1 +++ src/org/eclipse/wst/common/snippets/tests/TestsPlugin.java 1 Sep 2009 21:50:27 -0000 @@ -9,6 +9,7 @@ */ public class TestsPlugin extends AbstractUIPlugin { + public static final String PLUGIN_ID = "org.eclipse.wst.common.snippets.tests"; //The shared instance. private static TestsPlugin plugin; Index: plugin.xml =================================================================== RCS file: /cvsroot/webtools/common/tests/org.eclipse.wst.common.snippets.tests/plugin.xml,v retrieving revision 1.5 diff -u -r1.5 plugin.xml --- plugin.xml 27 Feb 2006 09:18:56 -0000 1.5 +++ plugin.xml 1 Sep 2009 21:50:27 -0000 @@ -29,5 +29,33 @@ + + + + + + + + + + + + + + + + + + Index: .settings/org.eclipse.pde.prefs =================================================================== RCS file: /cvsroot/webtools/common/tests/org.eclipse.wst.common.snippets.tests/.settings/org.eclipse.pde.prefs,v retrieving revision 1.1 diff -u -r1.1 org.eclipse.pde.prefs --- .settings/org.eclipse.pde.prefs 16 Apr 2006 19:36:43 -0000 1.1 +++ .settings/org.eclipse.pde.prefs 1 Sep 2009 21:50:27 -0000 @@ -1,15 +1,28 @@ -#Sun Apr 16 14:05:29 EDT 2006 +#Mon Aug 31 16:56:48 EDT 2009 +compilers.f.unresolved-features=1 +compilers.f.unresolved-plugins=1 +compilers.incompatible-environment=1 compilers.p.build=0 compilers.p.deprecated=1 +compilers.p.discouraged-class=1 compilers.p.illegal-att-value=0 +compilers.p.internal=1 +compilers.p.missing-packages=2 +compilers.p.missing-version-export-package=2 +compilers.p.missing-version-import-package=2 +compilers.p.missing-version-require-bundle=2 compilers.p.no-required-att=0 compilers.p.not-externalized-att=0 compilers.p.unknown-attribute=0 compilers.p.unknown-class=0 compilers.p.unknown-element=0 +compilers.p.unknown-identifier=1 compilers.p.unknown-resource=0 compilers.p.unresolved-ex-points=0 compilers.p.unresolved-import=0 compilers.p.unused-element-or-attribute=0 +compilers.s.create-docs=false +compilers.s.doc-folder=doc +compilers.s.open-tags=1 compilers.use-project=true eclipse.preferences.version=1 Index: src/org/eclipse/wst/common/snippets/tests/helpers/DummyProvider.java =================================================================== RCS file: src/org/eclipse/wst/common/snippets/tests/helpers/DummyProvider.java diff -N src/org/eclipse/wst/common/snippets/tests/helpers/DummyProvider.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/common/snippets/tests/helpers/DummyProvider.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,27 @@ +package org.eclipse.wst.common.snippets.tests.helpers; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.wst.common.snippets.internal.AbstractSnippetProvider; +import org.eclipse.wst.common.snippets.ui.ISnippetInsertion; + +public class DummyProvider extends AbstractSnippetProvider { + + public String getId() { + return "dummy"; + } + + public ISnippetInsertion getSnippetInsertion() { + return null; + } + + public boolean isActionEnabled(ISelection selection) { + return false; + } + + public IStatus saveAdditionalContent(IPath path) { + return null; + } + +} Index: src/org/eclipse/wst/common/snippets/tests/helpers/SApplicableEditor.java =================================================================== RCS file: src/org/eclipse/wst/common/snippets/tests/helpers/SApplicableEditor.java diff -N src/org/eclipse/wst/common/snippets/tests/helpers/SApplicableEditor.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/common/snippets/tests/helpers/SApplicableEditor.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,103 @@ +package org.eclipse.wst.common.snippets.tests.helpers; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.IPropertyListener; +import org.eclipse.ui.IWorkbenchPartSite; +import org.eclipse.ui.PartInitException; + +public class SApplicableEditor implements IEditorPart { + + public IEditorInput getEditorInput() { + return null; + } + + public IEditorSite getEditorSite() { + return null; + } + + public void init(IEditorSite site, IEditorInput input) + throws PartInitException { + + } + + public void addPropertyListener(IPropertyListener listener) { + // TODO Auto-generated method stub + + } + + public void createPartControl(Composite parent) { + // TODO Auto-generated method stub + + } + + public void dispose() { + // TODO Auto-generated method stub + + } + + public IWorkbenchPartSite getSite() { + // TODO Auto-generated method stub + return null; + } + + public String getTitle() { + // TODO Auto-generated method stub + return null; + } + + public Image getTitleImage() { + // TODO Auto-generated method stub + return null; + } + + public String getTitleToolTip() { + // TODO Auto-generated method stub + return null; + } + + public void removePropertyListener(IPropertyListener listener) { + // TODO Auto-generated method stub + + } + + public void setFocus() { + // TODO Auto-generated method stub + + } + + public Object getAdapter(Class adapter) { + // TODO Auto-generated method stub + return null; + } + + public void doSave(IProgressMonitor monitor) { + // TODO Auto-generated method stub + + } + + public void doSaveAs() { + // TODO Auto-generated method stub + + } + + public boolean isDirty() { + // TODO Auto-generated method stub + return false; + } + + public boolean isSaveAsAllowed() { + // TODO Auto-generated method stub + return false; + } + + public boolean isSaveOnCloseNeeded() { + // TODO Auto-generated method stub + return false; + } + +} Index: src/org/eclipse/wst/common/snippets/tests/scenarios/ObjectOrientedSnippetScenario.java =================================================================== RCS file: src/org/eclipse/wst/common/snippets/tests/scenarios/ObjectOrientedSnippetScenario.java diff -N src/org/eclipse/wst/common/snippets/tests/scenarios/ObjectOrientedSnippetScenario.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/common/snippets/tests/scenarios/ObjectOrientedSnippetScenario.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,130 @@ +package org.eclipse.wst.common.snippets.tests.scenarios; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +import junit.framework.TestCase; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.gef.palette.PaletteDrawer; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; +import org.eclipse.wst.common.snippets.core.ISnippetsEntry; +import org.eclipse.wst.common.snippets.internal.SnippetsPlugin; +import org.eclipse.wst.common.snippets.internal.palette.SnippetPaletteDrawerFactory; +import org.eclipse.wst.common.snippets.internal.palette.SnippetPaletteItem; +import org.eclipse.wst.common.snippets.internal.palette.SnippetPaletteRoot; +import org.eclipse.wst.common.snippets.internal.ui.SnippetsView; +import org.eclipse.wst.common.snippets.tests.helpers.ComplexProvider; + +public class ObjectOrientedSnippetScenario extends TestCase { + + + private IFile file; + + protected void setUp() throws Exception { + super.setUp(); + String projectName = System.currentTimeMillis() + ""; + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + if (!project.exists()){ + project.create(new NullProgressMonitor()); + } + if (!project.isOpen()){ + project.open(new NullProgressMonitor()); + } + file = project.getFile("testTextSnippet.txt"); + if (!file.exists()){ + ByteArrayInputStream sr = new ByteArrayInputStream("test Text Snippet Provider".getBytes()); + file.create(sr, true, new NullProgressMonitor()); + } + } + + public void testSave() throws Exception { + SnippetsView view; + SnippetPaletteRoot anchor = null; + view = (SnippetsView) SnippetsPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(SnippetsPlugin.NAMES.VIEW_ID); + if (view == null) { + view = (SnippetsView) SnippetsPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(SnippetsPlugin.NAMES.VIEW_ID); + } + if (view != null) { + anchor = view.getRoot(); + } + Shell activeShell = Display.getDefault().getActiveShell(); + assertNotNull(activeShell); + PaletteDrawer drawer = (PaletteDrawer) new SnippetPaletteDrawerFactory().createNewEntry(activeShell, anchor); + drawer.setLabel("testName"); + + ComplexProvider provider = new ComplexProvider(); + IEditorPart openEditor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); + provider.setEditor(openEditor); + SnippetPaletteItem createSnippet = provider.createSnippet(drawer); + assertNotNull(createSnippet); + File f = new File (createSnippet.getStorageLocation().toOSString()); + assertTrue(f.exists()); + assertEquals(1, f.list().length); + assertEquals(ComplexProvider.TEST_TXT, f.listFiles()[0].getName()); + assertEquals(ComplexProvider.TESTING.trim(), getContents(f.listFiles()[0]).trim()); +} + + public void testProviderBasedSourceType() throws Exception { + SnippetsView view; + SnippetPaletteRoot anchor = null; + view = (SnippetsView) SnippetsPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(SnippetsPlugin.NAMES.VIEW_ID); + if (view == null) { + view = (SnippetsView) SnippetsPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(SnippetsPlugin.NAMES.VIEW_ID); + } + if (view != null) { + anchor = view.getRoot(); + } + Shell activeShell = Display.getDefault().getActiveShell(); + assertNotNull(activeShell); + PaletteDrawer drawer = (PaletteDrawer) new SnippetPaletteDrawerFactory().createNewEntry(activeShell, anchor); + drawer.setLabel(getName()); + + ComplexProvider provider = new ComplexProvider(); + IEditorPart openEditor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); + provider.setEditor(openEditor); + SnippetPaletteItem createSnippet = provider.createSnippet(drawer); + assertNotNull(createSnippet); + File f = new File (createSnippet.getStorageLocation().toOSString()); + assertTrue(f.exists()); + assertEquals(1, f.list().length); + assertEquals(ComplexProvider.TEST_TXT, f.listFiles()[0].getName()); + assertEquals(ComplexProvider.TESTING.trim(), getContents(f.listFiles()[0]).trim()); + + assertEquals(ISnippetsEntry.SNIPPET_SOURCE_PLUGINS, createSnippet.getSourceType()); +} + + + public String getContents(File aFile) { + StringBuffer contents = new StringBuffer(); + + try { + BufferedReader input = new BufferedReader(new FileReader(aFile)); + try { + String line = null; //not declared within while loop + while (( line = input.readLine()) != null){ + contents.append(line); + contents.append(System.getProperty("line.separator")); + } + } + finally { + input.close(); + } + } + catch (IOException ex){ + ex.printStackTrace(); + } + + return contents.toString(); + } +} Index: src/org/eclipse/wst/common/snippets/tests/providers/SnippetProviderExtensionTests.java =================================================================== RCS file: src/org/eclipse/wst/common/snippets/tests/providers/SnippetProviderExtensionTests.java diff -N src/org/eclipse/wst/common/snippets/tests/providers/SnippetProviderExtensionTests.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/common/snippets/tests/providers/SnippetProviderExtensionTests.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,39 @@ +package org.eclipse.wst.common.snippets.tests.providers; + +import junit.framework.TestCase; + +import org.eclipse.ui.texteditor.AbstractTextEditor; +import org.eclipse.wst.common.snippets.core.ISnippetProvider; +import org.eclipse.wst.common.snippets.internal.util.SnippetProviderManager; +import org.eclipse.wst.common.snippets.tests.helpers.CommonApplicableInterface; +import org.eclipse.wst.common.snippets.tests.helpers.TextSnippetProvider2; +import org.eclipse.wst.common.snippets.ui.TextSnippetProvider; + +public class SnippetProviderExtensionTests extends TestCase { + + public void testEnablement() throws Exception { + ISnippetProvider applicableProvider = SnippetProviderManager.getApplicableProvider(new AbstractTextEditor(){}); + assertNotNull(applicableProvider); + applicableProvider = SnippetProviderManager.getApplicableProvider(new CommonApplicableInterface(){}); + assertNotNull(applicableProvider); + assertEquals("dummy", applicableProvider.getId()); + + } + + public void testDefaultTextSnippetProviderRegistration() throws Exception { + ISnippetProvider applicableProvider = SnippetProviderManager.getApplicableProvider(new AbstractTextEditor(){}); + assertNotNull(applicableProvider); + assertEquals(applicableProvider.getClass(), TextSnippetProvider.class); + } + + + public void testPriority() throws Exception { + ISnippetProvider applicableProvider = SnippetProviderManager.getApplicableProvider(new AbstractTextEditor(){}); + assertNotNull(applicableProvider); + assertEquals(applicableProvider.getClass(), TextSnippetProvider.class); + assertNotNull(SnippetProviderManager.findProvider(TextSnippetProvider2.class.getName())); + } + + + +} Index: src/org/eclipse/wst/common/snippets/tests/helpers/ComplexInsertion.java =================================================================== RCS file: src/org/eclipse/wst/common/snippets/tests/helpers/ComplexInsertion.java diff -N src/org/eclipse/wst/common/snippets/tests/helpers/ComplexInsertion.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/common/snippets/tests/helpers/ComplexInsertion.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,36 @@ +package org.eclipse.wst.common.snippets.tests.helpers; + +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.ui.IEditorPart; +import org.eclipse.wst.common.snippets.core.ISnippetItem; +import org.eclipse.wst.common.snippets.ui.ISnippetInsertion; + +public class ComplexInsertion implements ISnippetInsertion { + + public void dragSetData(DragSourceEvent event, ISnippetItem item) { + // TODO Auto-generated method stub + + } + + public Transfer[] getTransfers() { + // TODO Auto-generated method stub + return new Transfer[0]; + } + + public void insert(IEditorPart editorPart) { + // TODO Auto-generated method stub + + } + + public void setEditorPart(IEditorPart targetPart) { + // TODO Auto-generated method stub + + } + + public void setItem(ISnippetItem item) { + // TODO Auto-generated method stub + + } + +} Index: src/org/eclipse/wst/common/snippets/tests/providers/TextProviderTests.java =================================================================== RCS file: src/org/eclipse/wst/common/snippets/tests/providers/TextProviderTests.java diff -N src/org/eclipse/wst/common/snippets/tests/providers/TextProviderTests.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/common/snippets/tests/providers/TextProviderTests.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,76 @@ +package org.eclipse.wst.common.snippets.tests.providers; + +import java.io.ByteArrayInputStream; + +import junit.framework.TestCase; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.gef.palette.PaletteDrawer; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.wst.common.snippets.internal.SnippetsPlugin; +import org.eclipse.wst.common.snippets.internal.palette.SnippetPaletteDrawerFactory; +import org.eclipse.wst.common.snippets.internal.palette.SnippetPaletteItem; +import org.eclipse.wst.common.snippets.internal.palette.SnippetPaletteRoot; +import org.eclipse.wst.common.snippets.internal.ui.SnippetsView; +import org.eclipse.wst.common.snippets.ui.TextSnippetProvider; + +public class TextProviderTests extends TestCase { + + private IFile file; + + protected void setUp() throws Exception { + super.setUp(); + String projectName = System.currentTimeMillis() + ""; + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + if (!project.exists()){ + project.create(new NullProgressMonitor()); + } + if (!project.isOpen()){ + project.open(new NullProgressMonitor()); + } + file = project.getFile("testTextSnippet.txt"); + if (!file.exists()){ + ByteArrayInputStream sr = new ByteArrayInputStream("test Text Snippet Provider".getBytes()); + file.create(sr, true, new NullProgressMonitor()); + } + } + + public void testTextSnippetCreation() throws Exception { + SnippetsView view; + SnippetPaletteRoot anchor = null; + view = (SnippetsView) SnippetsPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(SnippetsPlugin.NAMES.VIEW_ID); + if (view == null) { + view = (SnippetsView) SnippetsPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(SnippetsPlugin.NAMES.VIEW_ID); + } + if (view != null) { + anchor = view.getRoot(); + } + Shell activeShell = Display.getDefault().getActiveShell(); + assertNotNull(activeShell); + PaletteDrawer drawer = (PaletteDrawer) new SnippetPaletteDrawerFactory().createNewEntry(activeShell, anchor); + drawer.setLabel("testName"); + TextSnippetProvider textSnippetProvider = new TextSnippetProvider(); + IEditorPart openEditor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); + assertNotNull(openEditor); + textSnippetProvider.setEditor(openEditor); + + + SnippetPaletteItem createSnippet = textSnippetProvider.createSnippet(drawer); + assertNotNull(createSnippet); + ITextEditor editor = (ITextEditor) openEditor; + editor.selectAndReveal(0, 5); + + assertFalse(textSnippetProvider.isActionEnabled(null)); + assertTrue(textSnippetProvider.isActionEnabled(editor.getSelectionProvider().getSelection())); + editor.selectAndReveal(0, 0); + assertFalse(textSnippetProvider.isActionEnabled(editor.getSelectionProvider().getSelection())); + } +} Index: src/org/eclipse/wst/common/snippets/tests/helpers/ComplexProvider.java =================================================================== RCS file: src/org/eclipse/wst/common/snippets/tests/helpers/ComplexProvider.java diff -N src/org/eclipse/wst/common/snippets/tests/helpers/ComplexProvider.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/common/snippets/tests/helpers/ComplexProvider.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,66 @@ +package org.eclipse.wst.common.snippets.tests.helpers; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.wst.common.snippets.internal.AbstractSnippetProvider; +import org.eclipse.wst.common.snippets.tests.TestsPlugin; +import org.eclipse.wst.common.snippets.ui.ISnippetInsertion; + +public class ComplexProvider extends AbstractSnippetProvider { + + public static final String TEST_TXT = "test.txt"; + public static final String TESTING = "testing 1, 2, 3, 4, 5, 6"; + + public String getId() { + return "Complex_Example"; + } + + public ISnippetInsertion getSnippetInsertion() { + return new ComplexInsertion(); + } + + public boolean isActionEnabled(ISelection selection) { + return true; + } + + public IStatus saveAdditionalContent(IPath path) { + if (path == null){ + throw new IllegalArgumentException("path is null"); + } + File f = new File(path.toOSString()); + if (!f.exists()){ + f.mkdir(); + } + File testSave = new File(f, TEST_TXT); + try { + saveTextFile(testSave); + } catch (IOException e) { + return new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID, "could not save file"); + } + return Status.OK_STATUS; + } + + private void saveTextFile(File testSave) throws IOException { + BufferedWriter bw = null; + try { + bw = new BufferedWriter(new FileWriter(testSave)); + bw.write(TESTING); + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } finally { + if (bw != null){ + bw.close(); + } + } + } + +} Index: src/org/eclipse/wst/common/snippets/tests/helpers/TextSnippetProvider2.java =================================================================== RCS file: src/org/eclipse/wst/common/snippets/tests/helpers/TextSnippetProvider2.java diff -N src/org/eclipse/wst/common/snippets/tests/helpers/TextSnippetProvider2.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/common/snippets/tests/helpers/TextSnippetProvider2.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,8 @@ +package org.eclipse.wst.common.snippets.tests.helpers; + +import org.eclipse.wst.common.snippets.ui.TextSnippetProvider; + +public class TextSnippetProvider2 extends TextSnippetProvider { + + +} Index: src/org/eclipse/wst/common/snippets/tests/helpers/CommonApplicableInterface.java =================================================================== RCS file: src/org/eclipse/wst/common/snippets/tests/helpers/CommonApplicableInterface.java diff -N src/org/eclipse/wst/common/snippets/tests/helpers/CommonApplicableInterface.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/common/snippets/tests/helpers/CommonApplicableInterface.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,106 @@ +package org.eclipse.wst.common.snippets.tests.helpers; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.IPropertyListener; +import org.eclipse.ui.IWorkbenchPartSite; +import org.eclipse.ui.PartInitException; + +public class CommonApplicableInterface implements IEditorPart{ + + public IEditorInput getEditorInput() { + // TODO Auto-generated method stub + return null; + } + + public IEditorSite getEditorSite() { + // TODO Auto-generated method stub + return null; + } + + public void init(IEditorSite site, IEditorInput input) + throws PartInitException { + // TODO Auto-generated method stub + + } + + public void addPropertyListener(IPropertyListener listener) { + // TODO Auto-generated method stub + + } + + public void createPartControl(Composite parent) { + // TODO Auto-generated method stub + + } + + public void dispose() { + // TODO Auto-generated method stub + + } + + public IWorkbenchPartSite getSite() { + // TODO Auto-generated method stub + return null; + } + + public String getTitle() { + // TODO Auto-generated method stub + return null; + } + + public Image getTitleImage() { + // TODO Auto-generated method stub + return null; + } + + public String getTitleToolTip() { + // TODO Auto-generated method stub + return null; + } + + public void removePropertyListener(IPropertyListener listener) { + // TODO Auto-generated method stub + + } + + public void setFocus() { + // TODO Auto-generated method stub + + } + + public Object getAdapter(Class adapter) { + // TODO Auto-generated method stub + return null; + } + + public void doSave(IProgressMonitor monitor) { + // TODO Auto-generated method stub + + } + + public void doSaveAs() { + // TODO Auto-generated method stub + + } + + public boolean isDirty() { + // TODO Auto-generated method stub + return false; + } + + public boolean isSaveAsAllowed() { + // TODO Auto-generated method stub + return false; + } + + public boolean isSaveOnCloseNeeded() { + // TODO Auto-generated method stub + return false; + } + +}