diff --git a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/propertypages/UniversalPreferencePage.java b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/propertypages/UniversalPreferencePage.java index eb88b26f309..535e4dbc314 100644 --- a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/propertypages/UniversalPreferencePage.java +++ b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/propertypages/UniversalPreferencePage.java @@ -13,6 +13,7 @@ * Contributors: * Martin Oberhuber (Wind River) - [177523] Unify singleton getter methods * David McKnight (IBM) - [207178] changing list APIs for file service and subsystems + * David McKnight (IBM) - [208951] no longer used editor registry for file type associations ********************************************************************************/ package org.eclipse.rse.internal.files.ui.propertypages; @@ -35,6 +36,7 @@ import org.eclipse.rse.internal.subsystems.files.core.ISystemFilePreferencesCons import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager; import org.eclipse.rse.services.clientserver.messages.SystemMessage; import org.eclipse.rse.services.clientserver.messages.SystemMessageFile; +import org.eclipse.rse.subsystems.files.core.model.ISystemFileTransferModeMapping; import org.eclipse.rse.subsystems.files.core.model.SystemFileTransferModeMapping; import org.eclipse.rse.subsystems.files.core.model.SystemFileTransferModeRegistry; import org.eclipse.rse.ui.ISystemMessages; @@ -65,12 +67,12 @@ import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IEditorRegistry; import org.eclipse.ui.IFileEditorMapping; import org.eclipse.ui.IPropertyListener; +import org.eclipse.ui.ISharedImages; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.internal.WorkbenchImages; import org.eclipse.ui.internal.dialogs.FileExtensionDialog; -import org.eclipse.ui.internal.registry.EditorRegistry; -import org.eclipse.ui.internal.registry.FileEditorMapping; /** * "Files" Preference page within the Remote Systems preference node. @@ -96,10 +98,8 @@ public class UniversalPreferencePage protected Button defaultTextButton; protected SystemFileTransferModeRegistry modeRegistry; - protected IEditorRegistry editorRegistry; protected ArrayList modeMappings; - protected ArrayList editorMappings; protected ArrayList imagesToDispose; protected Combo archiveTypeCombo; @@ -129,10 +129,9 @@ public class UniversalPreferencePage protected void createFieldEditors() { modeRegistry = SystemFileTransferModeRegistry.getInstance(); - editorRegistry = PlatformUI.getWorkbench().getEditorRegistry(); + //editorRegistry = PlatformUI.getWorkbench().getEditorRegistry(); modeMappings = new ArrayList(); - editorMappings = new ArrayList(); imagesToDispose = new ArrayList(); Composite parent = getFieldEditorParent(); @@ -428,11 +427,11 @@ public class UniversalPreferencePage tableCol = new TableColumn(resourceTypeTable, SWT.NONE); tableCol.setResizable(false); tableCol.setText(FileResources.RESID_PREF_UNIVERSAL_FILES_FILETYPES_TABLECOL_LABEL); + + ISystemFileTransferModeMapping[] mappings = modeRegistry.getModeMappings(); - IFileEditorMapping[] mappingArray = editorRegistry.getFileEditorMappings(); - - for (int i = 0; i < mappingArray.length; i++) { - newResourceTableItem(mappingArray[i], i, false); + for (int i = 0; i < mappings.length; i++) { + newResourceTableItem(mappings[i], i, false); } int defaultFileTransferMode = getFileTransferModeDefaultPreference(); @@ -452,16 +451,14 @@ public class UniversalPreferencePage protected void resetResourceTypeTable() { //clear table and reload defaults - editorMappings.clear(); modeMappings.clear(); resourceTypeTable.setRedraw(false); resourceTypeTable.removeAll(); - - - IFileEditorMapping[] mappingArray = editorRegistry.getFileEditorMappings(); - for (int i = 0; i < mappingArray.length; i++) + + ISystemFileTransferModeMapping[] mappings = modeRegistry.getModeMappings(); + for (int i = 0; i < mappings.length; i++) { - newResourceTableItem(mappingArray[i], i, false); + newResourceTableItem(mappings[i], i, false); } resourceTypeTable.setRedraw(true); @@ -493,16 +490,22 @@ public class UniversalPreferencePage uploadBufferSize.setText(ISystemFilePreferencesConstants.DEFAULT_DOWNLOAD_BUFFER_SIZE + ""); //$NON-NLS-1$ } + private Image getImageDescriptor(ISystemFileTransferModeMapping mapping) + { + //String extension = mapping.getExtension(); + // for now just always using the same image + return WorkbenchImages.getImageDescriptor(ISharedImages.IMG_OBJ_FILE).createImage(); + } + /** * Create a new TableItem to represent the resource * type editor description supplied. */ - protected TableItem newResourceTableItem(IFileEditorMapping mapping, int index, boolean selected) { + protected TableItem newResourceTableItem(ISystemFileTransferModeMapping mapping, int index, boolean selected) { - editorMappings.add(index, ((FileEditorMapping)mapping).clone()); - modeMappings.add(index, modeRegistry.getMapping(mapping).clone()); - - Image image = mapping.getImageDescriptor().createImage(false); + modeMappings.add(index, mapping); + + Image image = getImageDescriptor(mapping); if (image != null) imagesToDispose.add(image); @@ -513,7 +516,7 @@ public class UniversalPreferencePage if (selected) resourceTypeTable.setSelection(index); - + return item; } @@ -614,7 +617,6 @@ public class UniversalPreferencePage int index = resourceTypeTable.getSelectionIndex(); - editorMappings.remove(index); modeMappings.remove(index); TableItem[] items = resourceTypeTable.getSelection(); @@ -662,15 +664,16 @@ public class UniversalPreferencePage newFileName = (newName + "." + newExtension).toUpperCase(); //$NON-NLS-1$ } - IFileEditorMapping resourceType; + boolean found = false; int i = 0; + SystemFileTransferModeMapping mapping = null; - while (i < editorMappings.size() && !found) { + while (i < modeMappings.size() && !found) { - resourceType = (FileEditorMapping)(editorMappings.get(i)); + mapping = (SystemFileTransferModeMapping)(modeMappings.get(i)); - int result = newFileName.compareTo(resourceType.getLabel().toUpperCase()); + int result = newFileName.compareTo(mapping.getLabel().toUpperCase()); // if the type already exists if (result == 0) { @@ -680,18 +683,25 @@ public class UniversalPreferencePage FileResources.FileEditorPreference_existsTitle, // TODO: Cannot use WorkbenchMessages -- it's internal FileResources.FileEditorPreference_existsMessage); + + // select the existing mapping + resourceTypeTable.select(i); return; } if (result < 0) + { found = true; + } else i++; } + // Create the new type and insert it - resourceType = new FileEditorMapping(newName, newExtension); - newResourceTableItem(resourceType, i, true); + mapping = new SystemFileTransferModeMapping(newName,newExtension); + newResourceTableItem(mapping, i, true); + resourceTypeTable.setFocus(); fillMode(); } @@ -778,7 +788,7 @@ public class UniversalPreferencePage super.performOk(); if (modeMappings != null) { - IFileEditorMapping[] originalMappingArray = editorRegistry.getFileEditorMappings(); + //IFileEditorMapping[] originalMappingArray = editorRegistry.getFileEditorMappings(); // first save the transfer mode registry Object[] array1 = modeMappings.toArray(); @@ -789,19 +799,7 @@ public class UniversalPreferencePage } modeRegistry.setModeMappings(mappingArray1); - modeRegistry.saveAssociations(); - - // then save the editor registry - Object[] array2 = editorMappings.toArray(); - FileEditorMapping[] mappingArray2 = new FileEditorMapping[array2.length]; - - for (int j = 0; j < array2.length; j++) { - mappingArray2[j] = (FileEditorMapping)(array2[j]); - } - - ((EditorRegistry)editorRegistry).setFileEditorMappings(mappingArray2); - ((EditorRegistry)editorRegistry).saveAssociations(); - + modeRegistry.saveAssociations(); // editorRegistry.removePropertyListener(this); int defaultFileTransferMode = ISystemFilePreferencesConstants.FILETRANSFERMODE_BINARY; diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/META-INF/MANIFEST.MF b/rse/plugins/org.eclipse.rse.subsystems.files.core/META-INF/MANIFEST.MF index d8a18232c01..090e92f18b3 100644 --- a/rse/plugins/org.eclipse.rse.subsystems.files.core/META-INF/MANIFEST.MF +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName -Bundle-SymbolicName: org.eclipse.rse.subsystems.files.core +Bundle-SymbolicName: org.eclipse.rse.subsystems.files.core;singleton:=true Bundle-Version: 3.0.0.qualifier Bundle-Activator: org.eclipse.rse.internal.subsystems.files.core.Activator Bundle-Localization: plugin diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/plugin.xml b/rse/plugins/org.eclipse.rse.subsystems.files.core/plugin.xml new file mode 100644 index 00000000000..801151b71b2 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/plugin.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/schema/remoteFileTypes.exsd b/rse/plugins/org.eclipse.rse.subsystems.files.core/schema/remoteFileTypes.exsd new file mode 100644 index 00000000000..13b359fe7a1 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/schema/remoteFileTypes.exsd @@ -0,0 +1,120 @@ + + + + + + + + + This extension point is used to register information about whether particular file types should be considered text or binary. This information is important as it will determine how files will be transferred. + +Providers may provide an extension for this extension point. No code beyond the XML extension declaration is required. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 3.0 + + + + + + + + + <extension point="org.eclipse.rse.subsystems.files.core.remoteFileTypes"> + <remoteFileTypes extension="txt" type="text"/> + <remoteFileTypes extension="gif" type="binary"/> +</extension> + + + + + + + + + There is no code to implement for this extension point. + + + + + + + + + + + + + + + + + + Copyright (c) 2006, 2007 IBM Corporation. All Rights Reserved. +This program and the accompanying materials are made available under the terms +of the Eclipse Public License v1.0 which accompanies this distribution, and is +available at http://www.eclipse.org/legal/epl-v10.html + +Contributors: +IBM Corporation - initial API and implementation + + + + diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemFileTransferModeRegistry.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemFileTransferModeRegistry.java index 91d80818751..ded0db4567f 100644 --- a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemFileTransferModeRegistry.java +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/ISystemFileTransferModeRegistry.java @@ -13,6 +13,7 @@ * * Contributors: * {Name} (company) - description of contribution. + * David McKnight (IBM) - [208951] Don't use hard-coded file type defaults *******************************************************************************/ package org.eclipse.rse.subsystems.files.core.model; @@ -26,64 +27,7 @@ import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; public interface ISystemFileTransferModeRegistry extends ISystemFileTypes { - - // Default text file names - public static final String[] DEFAULT_TEXT_FILE_NAMES = {"application.xml", "build.properties", "fragment.xml", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - "install.xml", "plugin.xml", "server-cfg.xml", "web.xml"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - - // Default text file types - public static final String[] DEFAULT_TEXT_FILE_EXTENSIONS = {"conxmi", "css", "dad", "dadx", "dbxmi", "dtd", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ - "ent", "htm", "html", "html-ss", "jardesc", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ - "java", "jhtml", "jpage", "jsp", "nst", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ - "properties", "schxmi", "shtm", "shtml", "tblxmi", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ - "tld", "txt", "wsdl", "xhtml", "xmi", "xml", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ - "xsd", "xsl"}; //$NON-NLS-1$ //$NON-NLS-2$ - - // Default text file types that only we recognize through LPEX - public static final String[] DEFAULT_LPEX_TEXT_FILE_EXTENSIONS = {"app", "asm", "c", "c++", "cbl", "cc", "ccs", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ - "cmd", "cpp", "cpy", "cxx", "f", "f90", "f95", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ - "h", "h++", "hh", "hla", "hpp", "htm", "html", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ - "hxx", "inc", "inl", "jav", "java", "jcl", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ - "jj", "lx", "lxl", "lxu", "mac", "pli", "pro", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ - "properties", "rc", "rex", "rexx", "s", "sqc", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ - "sql", "sqlj", "xml", "xsl"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - - // the following need to match what is in plugin.xml! */ - /* scrubbed by phil 10/16/2002... removed old code/400 extensions not used anymore, and added .cpy for cobol on ifs - public static final String[] DEFAULT_ISERIES_LPEX_TEXT_FILE_EXTENSIONS = {"c", "cbl", "cblle", "cicsc", - "cicscbl", "cicscblle", "cicssqlcbl", - "cl", "cle", "clle", "clp", "cmd", - "cpp", "cpple", "dsp", "dspf", - "dspf400", "icf", "icff", "icff400", - "irp", "lf", "lf4", "lf400", "mnudds", - "pf", "pf4", "pf400", "pnlgrp", "prt", - "prtf", "prtf400", "rpg", "rpg36", - "rpg38", "rpgle", "rpgleinc", "rpt", - "sir", "sqlc", "sqlcbl", "sqlcblle", - "sqlcpple", "sqlrpg", "sqlrpgle", - "srg"}; */ - public static final String[] DEFAULT_ISERIES_LPEX_TEXT_FILE_EXTENSIONS = {"c", "cbl", "cblle", "cicsc", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - "cicscbl", "cicscblle", "cicssqlcbl", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - "cl", "cle", "clle", "clp", "cmd", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ - "cob", //$NON-NLS-1$ - "cpp", "cpple", "cpy", "dspf", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - "icff", //$NON-NLS-1$ - "lf", "mbr", "mnudds", //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - "pcml", //$NON-NLS-1$ - "pf", "pnlgrp", //$NON-NLS-1$ //$NON-NLS-2$ - "prtf", "rpg", "rpg36", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - "rpg38", "rpgle", "rpgleinc", "rpt", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - "sqlc", "sqlcbl", "sqlcblle", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - "sqlcpple", "sqlrpg", "sqlrpgle", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - }; - /* added by phil 10/16/2002... */ - public static final String[] DEFAULT_UNIX_LPEX_TEXT_FILE_EXTENSIONS = {"csh", "ksh", "mak", "pl", "profile", "py", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ - }; - - public static final String[] DEFAULT_BINARY_FILE_EXTENSIONS = {"xml", "jar", "zip", "tar", "exe", "gz", "z", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ - "gif","jpg"}; //$NON-NLS-1$ //$NON-NLS-2$ - - + // Get all file transfer mode mappings public ISystemFileTransferModeMapping[] getModeMappings(); diff --git a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/SystemFileTransferModeRegistry.java b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/SystemFileTransferModeRegistry.java index 88f7c38026a..17f7dda8827 100644 --- a/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/SystemFileTransferModeRegistry.java +++ b/rse/plugins/org.eclipse.rse.subsystems.files.core/src/org/eclipse/rse/subsystems/files/core/model/SystemFileTransferModeRegistry.java @@ -13,6 +13,7 @@ * * Contributors: * Martin Oberhuber (Wind River) - [168870] refactor org.eclipse.rse.core package of the UI plugin + * David McKnight (IBM) - [208951] Use remoteFileTypes extension point to determine file types *******************************************************************************/ package org.eclipse.rse.subsystems.files.core.model; @@ -29,20 +30,19 @@ import java.util.Iterator; import java.util.List; import java.util.SortedSet; import java.util.TreeSet; +import java.util.Vector; import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.rse.internal.subsystems.files.core.ISystemFilePreferencesConstants; import org.eclipse.rse.services.clientserver.SystemEncodingUtil; import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; import org.eclipse.rse.ui.RSEUIPlugin; import org.eclipse.rse.ui.SystemBasePlugin; -import org.eclipse.ui.IEditorRegistry; -import org.eclipse.ui.IFileEditorMapping; import org.eclipse.ui.IMemento; -import org.eclipse.ui.IPropertyListener; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.PlatformUI; import org.eclipse.ui.XMLMemento; @@ -51,7 +51,7 @@ import org.eclipse.ui.XMLMemento; * An internal class. Clients must not instantiate or subclass it. */ -public class SystemFileTransferModeRegistry implements ISystemFileTransferModeRegistry, IPropertyListener { +public class SystemFileTransferModeRegistry implements ISystemFileTransferModeRegistry { private static SystemFileTransferModeRegistry instance; @@ -70,6 +70,7 @@ public class SystemFileTransferModeRegistry implements ISystemFileTransferModeRe private static final String BINARY_VALUE = "binary"; //$NON-NLS-1$ private static final String TEXT_VALUE = "text"; //$NON-NLS-1$ + /** * Constructor for SystemFileTransferModeRegistry @@ -102,66 +103,106 @@ public class SystemFileTransferModeRegistry implements ISystemFileTransferModeRe // load our current associations (if any) loadAssociations(); - // now we need to ensure that our mapping is in sync with the - // editor registry. We can be out of sync because we may not have - // been listening for editor registry changes (e.g. if our plugin wasn't - // started while those changes were made). - IWorkbench wb = null; - try { - wb = PlatformUI.getWorkbench(); - } - // exception occurs if this is initialized before workbench has started - // TODO: we need to listen for workbench start to complete, then reinitialize - catch (Exception e) { - wb = null; + // lists to hold the information from the extensions to our + // extension point + Vector extTextList = new Vector(); + Vector extBinaryList = new Vector(); + + // get reference to the extension registry + IExtensionRegistry extRegistry = Platform.getExtensionRegistry(); + + // get extensions to our extension point + IConfigurationElement[] elements = extRegistry.getConfigurationElementsFor("org.eclipse.rse.subsystems.files.core", "remoteFileTypes"); //$NON-NLS-1$ //$NON-NLS-2$ + + // go through all extensions + for (int i = 0; i < elements.length; i++) { + IConfigurationElement element = elements[i]; + + // get the extension attribute value + String extension = element.getAttribute("extension"); //$NON-NLS-1$ + + if (extension != null && !extension.equals("")) { //$NON-NLS-1$ + + // get the type attribute value + String type = element.getAttribute("type"); //$NON-NLS-1$ + + if (type != null && !type.equals("")) { //$NON-NLS-1$ + + // add extension to list of text types + if (type.equalsIgnoreCase("text")) { //$NON-NLS-1$ + + // if the extension is not already part of our text + // types list + if (!extTextList.contains(extension)) { + + // add to list + extTextList.add(extension); + + // create an editor mapping + // FileEditorMapping mapping = new FileEditorMapping("*", extension); + + // add to editor mapping list + // editorMappings.add(mapping); + } + } + // add extension to list of binary types + if (type.equalsIgnoreCase("binary")) { //$NON-NLS-1$ + + // if the extension is not already part of our + // binary types list + if (!extBinaryList.contains(extension)) { + + // add to list + extBinaryList.add(extension); + + // create an editor mapping + // FileEditorMapping mapping = new FileEditorMapping("*", extension); + + // add to editor mapping list + // editorMappings.add(mapping); + } + } + else { + continue; + } + } + } + else { + continue; + } } - if (wb != null) + // add text extension to the mappings list + for (int t = 0; t < extTextList.size(); t++) { - IEditorRegistry registry = wb.getEditorRegistry(); - syncWithEditorRegistry(registry); - - registry.addPropertyListener(this); + String extension = (String)extTextList.get(t); + SystemFileTransferModeMapping mapping = new SystemFileTransferModeMapping(extension); + + String key = getMappingKey(mapping); + if (!typeModeMappings.containsKey(key)) + { + mapping.setAsText(); + typeModeMappings.put(key, mapping); + } } + + // add binary extension to the mappings list + for (int b = 0; b < extBinaryList.size(); b++) + { + String extension = (String)extBinaryList.get(b); + SystemFileTransferModeMapping mapping = new SystemFileTransferModeMapping(extension); + + + String key = getMappingKey(mapping); + if (!typeModeMappings.containsKey(key)) + { + mapping.setAsBinary(); + typeModeMappings.put(key, mapping); + } + } } - - /** - * Listen for changes to the Editor Registry content. - * Update our registry by changing the hashmap and saving the new - * mappings on disk. - * @see org.eclipse.ui.IPropertyListener#propertyChanged(Object, int) - */ - public void propertyChanged(Object source, int propId) { - - if ((source instanceof IEditorRegistry) && (propId == IEditorRegistry.PROP_CONTENTS)) { - IEditorRegistry registry = (IEditorRegistry)source; - syncWithEditorRegistry(registry); - } - } - - - /** - * Ensures that our registry is in sync with the editor registry, e.g. - * we have exactly the same types as in the editor registry. We can be - * out of sync if changes are made to the registry while we are not listening. - */ - private void syncWithEditorRegistry(IEditorRegistry registry) { - - IFileEditorMapping[] editorMappings = registry.getFileEditorMappings(); - - SystemFileTransferModeMapping[] modeMappings = new SystemFileTransferModeMapping[editorMappings.length]; - - for (int i = 0; i < editorMappings.length; i++) { - modeMappings[i] = getMapping(editorMappings[i]); - } - - setModeMappings(modeMappings); // set new mappings - saveAssociations(); // now save associations - } - - /** * @see ISystemFileTransferModeRegistry#getModeMappings() */ @@ -274,15 +315,7 @@ public class SystemFileTransferModeRegistry implements ISystemFileTransferModeRe */ public boolean isText(IRemoteFile remoteFile) { return isText(remoteFile.getName()); - } - - - /** - * Get a mode mapping given a file editor mapping - */ - public SystemFileTransferModeMapping getMapping(IFileEditorMapping editorMapping) { - return getMapping(editorMapping.getLabel()); - } + } /** @@ -383,84 +416,8 @@ public class SystemFileTransferModeRegistry implements ISystemFileTransferModeRe extension = fileName.substring(extIndex + 1); } - SystemFileTransferModeMapping mapping = new SystemFileTransferModeMapping(name, extension); - - - // check if it's a default text file name - for (int i = 0; i < DEFAULT_TEXT_FILE_NAMES.length; i++) - { - if (fileName.equalsIgnoreCase(DEFAULT_TEXT_FILE_NAMES[i])) - { - mapping.setAsText(); - return mapping; - } - } - - // DKM - // no longer default to text - instead we default based on preferences - // after the if (extension != null), we pick up preferences for default - /* - if (extension == null) - { - // DY mapping.setAsBinary(); - mapping.setAsText(); - return mapping; - } */ - - - if (extension != null) - { - // check if it's a default text file extension - for (int i = 0; i < DEFAULT_TEXT_FILE_EXTENSIONS.length; i++) - { - if (extension.equalsIgnoreCase(DEFAULT_TEXT_FILE_EXTENSIONS[i])) - { - mapping.setAsText(); - return mapping; - } - } - - // check if it's a default LPEX text file extension - for (int i = 0; i < DEFAULT_LPEX_TEXT_FILE_EXTENSIONS.length; i++) - { - if (extension.equalsIgnoreCase(DEFAULT_LPEX_TEXT_FILE_EXTENSIONS[i])) - { - mapping.setAsText(); - return mapping; - } - } - - // check if it's a default iSeries LPEX text file extension - for (int i = 0; i < DEFAULT_ISERIES_LPEX_TEXT_FILE_EXTENSIONS.length; i++) - { - if (extension.equalsIgnoreCase(DEFAULT_ISERIES_LPEX_TEXT_FILE_EXTENSIONS[i])) - { - mapping.setAsText(); - return mapping; - } - } - - // check if it's a default Universal LPEX text file extension (Phil 10/16/2002) - for (int i = 0; i < DEFAULT_UNIX_LPEX_TEXT_FILE_EXTENSIONS.length; i++) - { - if (extension.equalsIgnoreCase(DEFAULT_UNIX_LPEX_TEXT_FILE_EXTENSIONS[i])) - { - mapping.setAsText(); - return mapping; - } - } - - // check for known binary types - for (int i = 0; i < DEFAULT_BINARY_FILE_EXTENSIONS.length; i++) - { - if (extension.equalsIgnoreCase(DEFAULT_BINARY_FILE_EXTENSIONS[i])) - { - mapping.setAsBinary(); - return mapping; - } - } - } + SystemFileTransferModeMapping mapping = new SystemFileTransferModeMapping(name, extension); // default int defaultFileTransferMode = getFileTransferModeDefaultPreference();