Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 119066 Details for
Bug 253860
[fiximprove]: workspace level Symbol Set import/export/duplicate
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Patch to import SymbolDefinitionsSet
eclipseme-patch-bug253860-import-2.txt (text/plain), 35.95 KB, created by
Ales Milan
on 2008-11-29 03:09:40 EST
(
hide
)
Description:
Patch to import SymbolDefinitionsSet
Filename:
MIME Type:
Creator:
Ales Milan
Created:
2008-11-29 03:09:40 EST
Size:
35.95 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.mtj.core >Index: src/org/eclipse/mtj/core/model/device/preprocess/DeviceSymbolDefinitionSetFactory.java >=================================================================== >--- src/org/eclipse/mtj/core/model/device/preprocess/DeviceSymbolDefinitionSetFactory.java (revision 681) >+++ src/org/eclipse/mtj/core/model/device/preprocess/DeviceSymbolDefinitionSetFactory.java (working copy) >@@ -11,15 +11,32 @@ > */ > package org.eclipse.mtj.core.model.device.preprocess; > >+import java.io.IOException; >+import java.io.InputStream; >+import java.util.HashMap; > import java.util.Iterator; > import java.util.Map; > import java.util.Properties; >+import java.util.StringTokenizer; >+import java.util.Vector; >+ >+import javax.xml.parsers.DocumentBuilder; >+import javax.xml.parsers.DocumentBuilderFactory; >+import javax.xml.parsers.ParserConfigurationException; > >+import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.IStatus; >+import org.eclipse.mtj.core.MTJCoreStrings; > import org.eclipse.mtj.core.internal.MTJCorePlugin; > import org.eclipse.mtj.core.model.device.IDevice; > import org.eclipse.mtj.core.model.library.ILibrary; > import org.eclipse.mtj.core.model.preprocessor.SymbolDefinitionSet; >+import org.eclipse.mtj.core.model.preprocessor.SymbolDefinitionSetRegistry; >+import org.eclipse.mtj.core.persistence.PersistenceException; >+import org.w3c.dom.Document; >+import org.w3c.dom.Element; >+import org.w3c.dom.NodeList; >+import org.xml.sax.SAXException; > > /** > * This class is responsible for generate {@link SymbolDefinitionSet}'s based >@@ -29,6 +46,12 @@ > */ > public class DeviceSymbolDefinitionSetFactory { > >+ private static final String J2MEPOLISH_CAPABILITY_SEPARATOR = ","; >+ >+ >+ public static final String J2MEPOLISH_FILENAME_XML_DEVICES = "devices.xml"; >+ public static final String J2MEPOLISH_FILENAME_XML_GROUPS = "groups.xml"; >+ > /** > * Generate {@link SymbolDefinitionSet}'s based on the device information. > * <p> >@@ -43,6 +66,7 @@ > * > * @param device the device used as base > * @return the {@link SymbolDefinitionSet} based on the device information. >+ * @author Ales "afro" Milan > */ > public static SymbolDefinitionSet createSymbolDefinitionSet(IDevice device) { > >@@ -92,4 +116,269 @@ > > return definitionSet; > } >+ >+ /** >+ * Create SymbolDefinitionSet from Map of properties. >+ * >+ * @param name >+ * @param symbols >+ * @author Ales "afro" Milan >+ * @return >+ */ >+ public static SymbolDefinitionSet createSymbolDefinitionSet(String name, HashMap<String, String> symbols) { >+ >+ SymbolDefinitionSet definitionSet = new SymbolDefinitionSet(name); >+ definitionSet.define(name); >+ >+ for (Iterator<String> iterator = symbols.keySet().iterator(); iterator.hasNext();) { >+ String key = iterator.next(); >+ try { >+ String value = symbols.get(key); >+ definitionSet.define(key, value); >+ } >+ catch (RuntimeException e) { >+ MTJCorePlugin.log(IStatus.ERROR, e); >+ } >+ } >+ >+ return definitionSet; >+ } >+ >+ /** >+ * >+ * Import and create array of SymbosDefinitionSet from J2ME polish XML files (devices.xml & groups.xml). >+ * >+ * @param monitor Progress monitor, inform user about process of import. Null is allowed. >+ * @param devicesInputStream Input stream of device.xml file. >+ * @param groupsInputStream Input stream of groups.xml file. >+ * @return >+ * @throws PersistenceException >+ * @throws ParserConfigurationException >+ * @throws SAXException >+ * @throws IOException >+ * @author Ales "afro" Milan >+ * >+ */ >+ public static SymbolDefinitionSet[] importFromJ2MEPolishFormat(IProgressMonitor monitor, >+ InputStream devicesInputStream, >+ InputStream groupsInputStream) >+ throws PersistenceException, ParserConfigurationException, SAXException, IOException { >+ >+ Vector<SymbolDefinitionSet> result = new Vector<SymbolDefinitionSet>(); >+ >+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); >+ DocumentBuilder db = dbf.newDocumentBuilder(); >+ >+ Document devicesDOM = db.parse(devicesInputStream); >+ Document groupsDOM = db.parse(groupsInputStream); >+ >+ HashMap<String, Element> groups = prepareGroups(groupsDOM); >+ >+ NodeList nl = devicesDOM.getElementsByTagName("device"); >+ if(monitor != null) { >+ monitor.beginTask(MTJCoreStrings.getString("model.device.preprocess.DeviceSymbolDefinitionSetFactory.importing"), nl.getLength()); >+ } >+ for(int i = 0; i < nl.getLength(); i++) { >+ >+ HashMap<String, String> capabilities = new HashMap<String, String>(); >+ HashMap<String, String> groupCapabilities; >+ String features; >+ >+ Element deviceElement = (Element) nl.item(i); >+ String name = ((Element) deviceElement.getElementsByTagName("identifier").item(0)).getTextContent(); >+ >+ Element featuresElement = (Element) deviceElement.getElementsByTagName("features").item(0); >+ if(featuresElement != null) { >+ features = featuresElement.getTextContent(); >+ capabilities.put("features", features); >+ } >+ >+ Element groupElement = (Element) deviceElement.getElementsByTagName("groups").item(0); >+ if(groupElement != null) { >+ StringTokenizer st = new StringTokenizer(groupElement.getTextContent(), J2MEPOLISH_CAPABILITY_SEPARATOR); >+ while(st.hasMoreTokens()) { >+ String group = st.nextToken().trim(); >+ groupCapabilities = getGroupCapabilities(groups, group); >+ copyCapabilities(capabilities, groupCapabilities); >+ } >+ capabilities.put("groups", groupElement.getTextContent().toLowerCase()); >+ } >+ >+ NodeList capabilitiesNL = deviceElement.getElementsByTagName("capability"); >+ for(int j = 0; j < capabilitiesNL.getLength(); j++) { >+ Element capabilityElement = (Element) capabilitiesNL.item(j); >+ copyCapability(capabilities, capabilityElement.getAttribute("name"), capabilityElement.getAttribute("value")); >+ } >+ >+ capabilities.put(name, "true"); >+ >+ StringTokenizer st = new StringTokenizer(name, J2MEPOLISH_CAPABILITY_SEPARATOR); >+ while(st.hasMoreTokens()) { >+ String device = st.nextToken().trim(); >+ device = device.replace('/', '_'); >+ device = device.replace('(', '_'); >+ device = device.replace(')', '_'); >+ >+ SymbolDefinitionSet definitionSet = DeviceSymbolDefinitionSetFactory.createSymbolDefinitionSet(device, capabilities); >+ SymbolDefinitionSetRegistry.singleton.addDefinitionSet(definitionSet); >+ } >+ if(monitor != null) { >+ monitor.worked(1); >+ } >+ } >+ if(monitor != null) { >+ monitor.done(); >+ } >+ >+ if(result.size() != 0) { >+ SymbolDefinitionSet[] res = new SymbolDefinitionSet[result.size()]; >+ result.copyInto(res); >+ return res; >+ } >+ return null; >+ } >+ >+ /** >+ * Prepare device groups elements to Map. >+ * >+ * @param groupsDOM XML document which contain Device Groups >+ * <p> >+ * Example of XML document: >+ * <code> >+ * <groups> >+ * <group> >+ * <name>name of group</name> >+ * <description>...</description> >+ * <features>feature1, feature2, ...</features> >+ * <parent>nameOfParrentGroup</parent> >+ * <capability name="capabilityA" value="valueA" /> >+ * <capability name="capabilityB" value="valueB" /> >+ * ... >+ * </group> >+ * <group> >+ * ... >+ * </group> >+ * </groups> >+ * </code> >+ * </p> >+ * @return return map of XML elements >+ */ >+ private static HashMap<String, Element> prepareGroups(Document groupsDOM) { >+ >+ HashMap<String, Element> result = new HashMap<String, Element>(); >+ >+ NodeList nl = groupsDOM.getElementsByTagName("group"); >+ for(int i = 0; i < nl.getLength(); i++) { >+ Element groupElement = (Element) nl.item(i); >+ String name = ((Element) groupElement.getElementsByTagName("name").item(0)).getTextContent(); >+ result.put(name, groupElement); >+ } >+ >+ return result; >+ } >+ >+ >+ /** >+ * Return capabilities for specified group. >+ * >+ * @param groups map of groups XML elements >+ * @param name group name >+ * @return map of capabilities, key/value >+ */ >+ private static HashMap<String, String> getGroupCapabilities(HashMap<String, Element> groups, String name) { >+ >+ Element groupElement = groups.get(name); >+ >+ HashMap<String, String> result = new HashMap<String, String>(); >+ >+ NodeList nl = groupElement.getElementsByTagName("parent"); >+ if(nl != null && nl.getLength() > 0) { >+ Element parent = (Element) nl.item(0); >+ String parentValue = parent.getTextContent(); >+ if(parentValue != null && !parent.getTextContent().equals("")) { >+ HashMap<String, String> parentCapabilities = getGroupCapabilities(groups, parent.getTextContent()); >+ copyCapabilities(result, parentCapabilities); >+ } >+ } >+ >+ >+ nl = groupElement.getElementsByTagName("capability"); >+ for(int i = 0; i < nl.getLength(); i++) { >+ Element capabilityElement = (Element) nl.item(i); >+ result.put(capabilityElement.getAttribute("name"), capabilityElement.getAttribute("value")); >+ } >+ >+ return result; >+ >+ } >+ >+ /** >+ * Copy capabilities from Map to other Map. >+ * >+ * @param capabilities dest map >+ * @param parentCapabilities source map, records from this map will be copied to dest map >+ */ >+ private static void copyCapabilities(HashMap<String, String> capabilities, HashMap<String, String> parentCapabilities) { >+ Iterator<String> i = parentCapabilities.keySet().iterator(); >+ while(i.hasNext()) { >+ String capability = i.next(); >+ copyCapability(capabilities, capability, parentCapabilities.get(capability)); >+ } >+ } >+ >+ /** >+ * Copy capability. If exist in dest map capability with same key, then >+ * new capability value will be merged to exist capability. >+ * >+ * @param capabilities dest map of capabilities >+ * @param name key of capability >+ * @param capability new capability, this capability value is added or merged to map >+ */ >+ private static void copyCapability(HashMap<String, String> capabilities, String name, String capability) { >+ >+ String currentCapabilityValue = capabilities.get(name); >+ if(currentCapabilityValue == null || currentCapabilityValue.equals("")) { >+ capabilities.put(name, capability); >+ } >+ else { >+ String mergedCapabilities = mergeCapabilities(currentCapabilityValue, capability); >+ capabilities.put(name, mergedCapabilities); >+ } >+ >+ } >+ >+ /** >+ * Merge two capabilities to one string. Function ignore duplicity >+ * >+ * @param currentCapability >+ * @param newCapability >+ * @return merged capabilities >+ */ >+ private static String mergeCapabilities(String currentCapability, String newCapability) { >+ >+ Vector<String> v = new Vector<String>(); >+ StringTokenizer st = new StringTokenizer(currentCapability, J2MEPOLISH_CAPABILITY_SEPARATOR); >+ while(st.hasMoreTokens()) { >+ v.add(st.nextToken().trim()); >+ } >+ st = new StringTokenizer(newCapability, J2MEPOLISH_CAPABILITY_SEPARATOR); >+ while(st.hasMoreTokens()) { >+ String capability = st.nextToken().trim(); >+ if(v.indexOf(capability) == -1) { >+ v.add(capability); >+ } >+ } >+ String result = ""; >+ for(int i = 0; i < v.size(); i++) { >+ if(i > 0) { >+ result = result.concat(","); >+ } >+ result = result.concat(v.elementAt(i)); >+ } >+ >+ return result; >+ } >+ >+ >+ > } >Index: src/org/eclipse/mtj/core/model/preprocessor/SymbolDefinitionSetRegistry.java >=================================================================== >--- src/org/eclipse/mtj/core/model/preprocessor/SymbolDefinitionSetRegistry.java (revision 681) >+++ src/org/eclipse/mtj/core/model/preprocessor/SymbolDefinitionSetRegistry.java (working copy) >@@ -189,6 +189,7 @@ > public void loadUsing(IPersistenceProvider persistenceProvider) > throws PersistenceException { > if (registryMap != null) { >+ registryMap.clear(); > String keysString = persistenceProvider.loadString("mtjKeys"); > if ((keysString != null) && (keysString.length() > 0)) { > String[] keys = keysString.split(","); >Index: src/org/eclipse/mtj/core/MTJPluginResources.properties >=================================================================== >--- src/org/eclipse/mtj/core/MTJPluginResources.properties (revision 681) >+++ src/org/eclipse/mtj/core/MTJPluginResources.properties (working copy) >@@ -67,3 +67,13 @@ > #################################################################### > > MTJCoreError.InternalTemplate: Internal Error {0,number,0} >+ >+ >+#################################################################### >+# >+# This section of the file contains other strings associated with >+# DeviceSymbolDefinitionSetFactory. >+# >+#################################################################### >+model.device.preprocess.DeviceSymbolDefinitionSetFactory.importing=Importing... >+ >Index: src/org/eclipse/mtj/core/model/preprocessor/SymbolDefinitionSet.java >=================================================================== >--- src/org/eclipse/mtj/core/model/preprocessor/SymbolDefinitionSet.java (revision 681) >+++ src/org/eclipse/mtj/core/model/preprocessor/SymbolDefinitionSet.java (working copy) >@@ -18,6 +18,7 @@ > import java.util.HashMap; > import java.util.Iterator; > import java.util.Map; >+import java.util.Properties; > > import org.eclipse.mtj.core.model.preprocessor.symbol.SymbolUtils; > import org.eclipse.mtj.core.persistence.IPersistable; >@@ -163,6 +164,17 @@ > map.put(key, value); > } > } >+ >+ Properties properties = persistenceProvider.loadProperties(KEYS_KEY); >+ if(properties != null) { >+ Iterator<?> iterator = properties.keySet().iterator(); >+ while(iterator.hasNext()) { >+ String key = (String) iterator.next(); >+ String value = properties.getProperty(key); >+ map.put(key, value); >+ } >+ } >+ > } > > /** >@@ -194,24 +206,15 @@ > // Store off the entries in the object > StringBuffer sb = new StringBuffer(); > Iterator<?> entries = map.entrySet().iterator(); >+ Properties properties = new Properties(); > while (entries.hasNext()) { > Map.Entry<?, ?> entry = (Map.Entry<?, ?>) entries.next(); > >- // Add the key to the list of keys >- String key = (String) entry.getKey(); >- sb.append(key); >- if (entries.hasNext()) { >- sb.append(","); >- } >- >- // Add the entry to the object >- persistenceProvider.storeString(key, entry.getValue().toString()); >+ properties.put(entry.getKey(), entry.getValue()); > } > >- // Store the list of the keys that can be used to reconstruct >- // this object as a comma-separated list >- persistenceProvider.storeString(KEYS_KEY + getStorableName(), sb >- .toString()); >+ persistenceProvider.storeProperties(KEYS_KEY, properties); >+ > } > > /** >#P org.eclipse.mtj.ui >Index: src/org/eclipse/mtj/ui/MTJUIPluginResources.properties >=================================================================== >--- src/org/eclipse/mtj/ui/MTJUIPluginResources.properties (revision 681) >+++ src/org/eclipse/mtj/ui/MTJUIPluginResources.properties (working copy) >@@ -169,6 +169,23 @@ > J2MEProjectPropertiesPage.JarFileName=JAR file name: > J2MEProjectPropertiesPage.JADFileName=JAD file name: > >+#################################################################### >+# >+# SymbolDefinitionsImportWizardPage >+# >+#################################################################### >+SymbolDefinitionsImportWizardPage.title=Import Symbol Definitions Set >+SymbolDefinitionsImportWizardPage.importFromAntennaJarFile=Import from Antenna.jar library >+SymbolDefinitionsImportWizardPage.importFromXMLFiles=Import from XML files (devices.xml, groups.xml) >+SymbolDefinitionsImportWizardPage.specifyDirectory=Specify Directory: >+SymbolDefinitionsImportWizardPage.browse=Browse... >+SymbolDefinitionsImportWizardPage.from=From >+SymbolDefinitionsImportWizardPage.description=Import existing Symbol Definition Set. >+ >+SymbolDefinitionsImportWizardPage.error=Error Occurred >+SymbolDefinitionsImportWizardPage.error.antennaLibraryIsNotSpecified=Antenna.jar library is not specified. >+SymbolDefinitionsImportWizardPage.error.directoryDoesNotContaintFiles=Directory doesn''t contain files {0} and {1}. >+SymbolDefinitionsImportWizardPage.error.errorDuringImportSymbolDefinitionSet=Error during import Symbol Definition Set. > > #################################################################### > # >Index: src/org/eclipse/mtj/ui/internal/preferences/SymbolDefinitionsPreferencePage.java >=================================================================== >--- src/org/eclipse/mtj/ui/internal/preferences/SymbolDefinitionsPreferencePage.java (revision 681) >+++ src/org/eclipse/mtj/ui/internal/preferences/SymbolDefinitionsPreferencePage.java (working copy) >@@ -52,7 +52,11 @@ > import org.eclipse.jface.viewers.TextCellEditor; > import org.eclipse.jface.viewers.Viewer; > import org.eclipse.jface.viewers.ViewerSorter; >+import org.eclipse.jface.window.Window; >+import org.eclipse.jface.wizard.WizardDialog; > import org.eclipse.mtj.core.internal.MTJCorePlugin; >+import org.eclipse.mtj.core.model.device.DeviceRegistry; >+import org.eclipse.mtj.core.model.device.IDevice; > import org.eclipse.mtj.core.model.preprocessor.ISymbolDefinitionSetChangeListener; > import org.eclipse.mtj.core.model.preprocessor.SymbolDefinitionSet; > import org.eclipse.mtj.core.model.preprocessor.SymbolDefinitionSetRegistry; >@@ -456,6 +460,7 @@ > > private Button addSetButton; > private Button addSymbolButton; >+ private Button importSetButton; > // Tracks the current definitions in the table viewer until they > // are committed back to the underlying model > private ArrayList<SymbolDefinition> currentDefinitions; >@@ -642,6 +647,26 @@ > } > > /** >+ * The import set button has been selected. >+ */ >+ private void handleImportSetButton() { >+ >+ SymbolDefinitionsImportWizard wizard = new SymbolDefinitionsImportWizard(); >+ >+ WizardDialog dialog = new WizardDialog(this.getShell(), wizard); >+ if(dialog.open() == Window.OK) { >+ definitionsComboViewer.refresh(); >+ } >+ //try { >+ >+ //} >+ //catch(PersistenceException e) { >+ // handleException("Error import definition set", e); >+ //} >+ >+ } >+ >+ /** > * The add symbol button has been selected. > */ > private void handleAddSymbolButton() { >@@ -812,22 +837,24 @@ > handleException("Error retrieving symbol definitions", e1); > } > >+ > SymbolDefinitionSetRegistry.singleton > .addSymbolDefinitionSetChangeListener(new ISymbolDefinitionSetChangeListener() { >- > /* > * (non-Javadoc) > * @seeorg.eclipse.mtj.core.model.preprocessor. > * ISymbolDefinitionSetChangeListener > * #symbolDefinitionSetChanged() > */ >- public void symbolDefinitionSetChanged() { >+ >+ public void symbolDefinitionSetChanged() { >+ > try { > definitionSetsinput = SymbolDefinitionSetRegistry.singleton > .getAllSetDefinitions(); >- if ((definitionsComboViewer != null) >- && (!definitionsComboViewer.getControl() >- .isDisposed())) { >+ if ((definitionsComboViewer != null) && >+ (!definitionsComboViewer.getControl().isDisposed()) && >+ workbench.getActiveWorkbenchWindow() != null) { > > definitionsComboViewer.refresh(); > } >@@ -838,6 +865,7 @@ > > } > }); >+ > > Composite composite = new Composite(parent, SWT.NONE); > composite.setLayout(new GridLayout(1, true)); >@@ -892,6 +920,17 @@ > handleRemoveSetButton(); > } > }); >+ >+ importSetButton = new Button(nameButtonComposite, SWT.PUSH); >+ importSetButton.setText("Import"); >+ importSetButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ importSetButton.addSelectionListener(new SelectionAdapter() { >+ @Override >+ public void widgetSelected(SelectionEvent e) { >+ handleImportSetButton(); >+ } >+ }); >+ > > symbolsGroup = new Group(composite, SWT.FILL); > symbolsGroup.setLayout(new GridLayout(2, false)); >Index: src/org/eclipse/mtj/ui/internal/preferences/SymbolDefinitionsImportWizard.java >=================================================================== >--- src/org/eclipse/mtj/ui/internal/preferences/SymbolDefinitionsImportWizard.java (revision 0) >+++ src/org/eclipse/mtj/ui/internal/preferences/SymbolDefinitionsImportWizard.java (revision 0) >@@ -0,0 +1,203 @@ >+/** >+ * Copyright (c) 2003,2008 Ales Milan 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 >+ * >+ */ >+ >+package org.eclipse.mtj.ui.internal.preferences; >+ >+import java.io.File; >+import java.io.FileInputStream; >+import java.io.IOException; >+import java.io.InputStream; >+import java.lang.reflect.InvocationTargetException; >+import java.util.Enumeration; >+import java.util.jar.JarEntry; >+import java.util.jar.JarFile; >+ >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.jface.dialogs.MessageDialog; >+import org.eclipse.jface.operation.IRunnableWithProgress; >+import org.eclipse.jface.preference.IPreferenceStore; >+import org.eclipse.jface.wizard.Wizard; >+import org.eclipse.mtj.core.IMTJCoreConstants; >+import org.eclipse.mtj.core.internal.MTJCorePlugin; >+import org.eclipse.mtj.core.model.device.preprocess.DeviceSymbolDefinitionSetFactory; >+import org.eclipse.mtj.ui.MTJUIStrings; >+import org.eclipse.mtj.ui.internal.MTJUIPlugin; >+ >+/** >+ * Wizard for importing SymbolDefinitionSets. >+ * >+ * @author Ales "afro" Milan >+ */ >+public class SymbolDefinitionsImportWizard extends Wizard { >+ >+ >+ >+ private SymbolDefinitionsImportWizardPage wizardPage; >+ >+ private String importDirectory = null; >+ >+ public SymbolDefinitionsImportWizard() { >+ >+ super(); >+ setNeedsProgressMonitor(true); >+ setWindowTitle(MTJUIStrings.getString("SymbolDefinitionsImportWizardPage.title")); >+ >+ } >+ >+ >+ @Override >+ public boolean performFinish() { >+ >+ switch(wizardPage.getImportType()) { >+ case SymbolDefinitionsImportWizardPage.IMPORT_FROM_ANTENNA_JAR: >+ try { >+ getContainer().run(true, true, getProcessImportFromAntennaJarFile()); >+ } >+ catch (InvocationTargetException e) { >+ e.printStackTrace(); >+ } >+ catch (InterruptedException e) { >+ e.printStackTrace(); >+ } >+ break; >+ >+ case SymbolDefinitionsImportWizardPage.IMPORT_J2MEPOLISH_FORMAT: >+ importDirectory = wizardPage.getDirectory(); >+ try { >+ getContainer().run(true, true, getProcessImportFromXMLFiles()); >+ } >+ catch (InvocationTargetException e) { >+ e.printStackTrace(); >+ } >+ catch (InterruptedException e) { >+ e.printStackTrace(); >+ } >+ break; >+ case SymbolDefinitionsImportWizardPage.IMPORT_MTJ_FORMAT: >+ >+ break; >+ } >+ return true; >+ } >+ >+ >+ @Override >+ public void addPages() { >+ wizardPage = new SymbolDefinitionsImportWizardPage(); >+ addPage(wizardPage); >+ } >+ >+ >+ private IRunnableWithProgress getProcessImportFromAntennaJarFile() { >+ >+ // The runnable to do import definitions >+ return new IRunnableWithProgress() { >+ public void run(IProgressMonitor monitor) { >+ JarFile antennaFileJar = null; >+ try { >+ IPreferenceStore preferenceStore = MTJUIPlugin.getDefault().getCorePreferenceStore(); >+ String antennaFile = preferenceStore.getString(IMTJCoreConstants.PREF_ANTENNA_JAR); >+ >+ // search devices.xml & groups.xml from Antenna Jar file >+ InputStream devicesInputStream = null; >+ InputStream groupsInputStream = null; >+ antennaFileJar = new JarFile(new File(antennaFile)); >+ Enumeration<JarEntry> e = antennaFileJar.entries(); >+ while(e.hasMoreElements()) { >+ JarEntry entry = e.nextElement(); >+ if(entry.getName().toLowerCase().equals(DeviceSymbolDefinitionSetFactory.J2MEPOLISH_FILENAME_XML_DEVICES)) { >+ devicesInputStream = antennaFileJar.getInputStream(entry); >+ } >+ if(entry.getName().toLowerCase().equals(DeviceSymbolDefinitionSetFactory.J2MEPOLISH_FILENAME_XML_GROUPS)) { >+ groupsInputStream = antennaFileJar.getInputStream(entry); >+ } >+ } >+ if(devicesInputStream != null && groupsInputStream != null) { >+ try { >+ DeviceSymbolDefinitionSetFactory.importFromJ2MEPolishFormat(monitor, devicesInputStream, groupsInputStream); >+ } >+ catch(Exception ex) { >+ handleException(MTJUIStrings.getString("SymbolDefinitionsImportWizardPage.error.errorDuringImportSymbolDefinitionSet"), ex); >+ } >+ } >+ } >+ catch (IOException e) { >+ e.printStackTrace(); >+ } >+ finally { >+ try { >+ antennaFileJar.close(); >+ } >+ catch(Exception e) { >+ } >+ } >+ >+ } >+ }; >+ >+ } >+ >+ private IRunnableWithProgress getProcessImportFromXMLFiles() { >+ >+ // The runnable to do import definitions >+ return new IRunnableWithProgress() { >+ public void run(IProgressMonitor monitor) { >+ InputStream devicesInputStream = null; >+ InputStream groupsInputStream = null; >+ try { >+ // search devices.xml & groups.xml from Antenna Jar file >+ devicesInputStream = new FileInputStream(new File(importDirectory + File.separator + DeviceSymbolDefinitionSetFactory.J2MEPOLISH_FILENAME_XML_DEVICES)); >+ groupsInputStream = new FileInputStream(new File(importDirectory + File.separator + DeviceSymbolDefinitionSetFactory.J2MEPOLISH_FILENAME_XML_GROUPS)); >+ if(devicesInputStream != null && groupsInputStream != null) { >+ try { >+ DeviceSymbolDefinitionSetFactory.importFromJ2MEPolishFormat(monitor, devicesInputStream, groupsInputStream); >+ } >+ catch(Exception ex) { >+ handleException(MTJUIStrings.getString("SymbolDefinitionsImportWizardPage.error.errorDuringImportSymbolDefinitionSet"), ex); >+ } >+ } >+ } >+ catch (IOException e) { >+ e.printStackTrace(); >+ } >+ finally { >+ try { >+ devicesInputStream.close(); >+ } >+ catch(Exception e) { >+ } >+ try { >+ groupsInputStream.close(); >+ } >+ catch(Exception e) { >+ } >+ } >+ >+ } >+ }; >+ >+ } >+ >+ >+ /** >+ * An exception has occurred. Handle it appropriately. >+ * >+ * @param t >+ */ >+ private void handleException(String message, Throwable t) { >+ MTJCorePlugin.log(IStatus.WARNING, message, t); >+ MessageDialog.openError(getShell(), >+ MTJUIStrings.getString("SymbolDefinitionsImportWizardPage.error"), >+ message); >+ } >+ >+ >+} >Index: src/org/eclipse/mtj/ui/internal/preferences/SymbolDefinitionsImportWizardPage.java >=================================================================== >--- src/org/eclipse/mtj/ui/internal/preferences/SymbolDefinitionsImportWizardPage.java (revision 0) >+++ src/org/eclipse/mtj/ui/internal/preferences/SymbolDefinitionsImportWizardPage.java (revision 0) >@@ -0,0 +1,254 @@ >+package org.eclipse.mtj.ui.internal.preferences; >+ >+import java.io.File; >+import java.text.MessageFormat; >+ >+import javax.sql.rowset.Predicate; >+ >+import org.eclipse.jface.dialogs.IDialogSettings; >+import org.eclipse.jface.preference.FieldEditor; >+import org.eclipse.jface.preference.FileFieldEditor; >+import org.eclipse.jface.preference.IPreferenceStore; >+import org.eclipse.jface.wizard.WizardPage; >+import org.eclipse.mtj.core.IMTJCoreConstants; >+import org.eclipse.mtj.core.model.device.preprocess.DeviceSymbolDefinitionSetFactory; >+import org.eclipse.mtj.ui.MTJUIStrings; >+import org.eclipse.mtj.ui.internal.MTJUIPlugin; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.ControlAdapter; >+import org.eclipse.swt.events.ControlEvent; >+import org.eclipse.swt.events.ModifyEvent; >+import org.eclipse.swt.events.ModifyListener; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Button; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.DirectoryDialog; >+import org.eclipse.swt.widgets.FileDialog; >+import org.eclipse.swt.widgets.Group; >+import org.eclipse.swt.widgets.Label; >+import org.eclipse.swt.widgets.Text; >+ >+/** >+ * Wizard for importing SymbolDefinitionSets. >+ * >+ * @author Ales "afro" Milan >+ */ >+public class SymbolDefinitionsImportWizardPage extends WizardPage { >+ >+ public static final int IMPORT_FROM_ANTENNA_JAR = 0; >+ public static final int IMPORT_J2MEPOLISH_FORMAT = 1; >+ public static final int IMPORT_MTJ_FORMAT = 2; >+ >+ public static final String NAME = "symbolDefinitionsImportPage"; >+ >+ private static final String KEY_WIDTH = "dialogWidth"; >+ private static final String KEY_HEIGHT = "dialogHeight"; >+ >+ private Button[] importTypeRadios; >+ private Label importFileLabel; >+ private Text importDirectory; >+ private Button importFileBrowseButton; >+ private String antennaFile; >+ >+ >+ /** >+ * Constructor >+ * >+ */ >+ public SymbolDefinitionsImportWizardPage() { >+ >+ super(NAME, MTJUIStrings.getString("SymbolDefinitionsImportWizardPage.title"), null); >+ setPageComplete(true); >+ setDescription(MTJUIStrings.getString("SymbolDefinitionsImportWizardPage.description")); >+ } >+ >+ @Override >+ public void createControl(Composite parent) { >+ >+ parent.setLayoutData(new GridData(GridData.FILL_BOTH)); >+ >+ final Composite composite = new Composite(parent, SWT.NONE); >+ >+ composite.setLayout(new GridLayout(1, false)); >+ composite.setLayoutData(new GridData(GridData.FILL_BOTH)); >+ composite.addControlListener(new ControlAdapter() { >+ @Override >+ public void controlResized(ControlEvent e) { >+ storeSize(); >+ } >+ }); >+ setControl(composite); >+ >+ IPreferenceStore preferenceStore = MTJUIPlugin.getDefault().getCorePreferenceStore(); >+ antennaFile = preferenceStore.getString(IMTJCoreConstants.PREF_ANTENNA_JAR); >+ >+ addImportSelectorControls(composite); >+ >+ // Set the size if previously stored away >+ >+ Point size = retrieveSize(); >+ if (size != null) { >+ composite.setSize(size); >+ } >+ >+ } >+ >+ /** >+ * Add the controls that allow the user to select the type of import. >+ * >+ * @param parent >+ */ >+ private void addImportSelectorControls(Composite parent) { >+ >+ Group importTypeGroup = new Group(parent, SWT.NONE); >+ importTypeGroup.setText(" " + MTJUIStrings.getString("SymbolDefinitionsImportWizardPage.from") + " "); >+ importTypeGroup.setLayout(new GridLayout(1, false)); >+ importTypeGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ >+ importTypeRadios = new Button[2]; >+ >+ importTypeRadios[0] = new Button(importTypeGroup, SWT.RADIO); >+ importTypeRadios[0].setText(MTJUIStrings.getString("SymbolDefinitionsImportWizardPage.importFromAntennaJarFile")); >+ >+ importTypeRadios[1] = new Button(importTypeGroup, SWT.RADIO); >+ importTypeRadios[1].setText(MTJUIStrings.getString("SymbolDefinitionsImportWizardPage.importFromXMLFiles")); >+ // set default selection >+ importTypeRadios[0].setSelection(true); >+ >+ importTypeRadios[1].addSelectionListener(new SelectionAdapter() { >+ @Override >+ public void widgetSelected(SelectionEvent e) { >+ if(((Button) e.getSource()).getSelection()) { >+ updateControlEnable(true); >+ } >+ else { >+ updateControlEnable(false); >+ } >+ updateFinishButton(); >+ } >+ }); >+ >+ addChooseFileControl(importTypeGroup); >+ updateControlEnable(false); >+ updateFinishButton(); >+ >+ } >+ >+ >+ private void addChooseFileControl(Composite parent) { >+ >+ Composite composite = new Composite(parent, SWT.NONE); >+ composite.setLayout(new GridLayout(3, false)); >+ composite.setLayoutData(new GridData(GridData.FILL_BOTH)); >+ >+ importFileLabel = new Label(composite, SWT.NONE); >+ importFileLabel.setText(MTJUIStrings.getString("SymbolDefinitionsImportWizardPage.specifyDirectory")); >+ >+ importDirectory = new Text(composite, SWT.BORDER); >+ importDirectory.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); >+ importDirectory.addModifyListener(new ModifyListener() { >+ public void modifyText(ModifyEvent e) { >+ updateFinishButton(); >+ } >+ }); >+ >+ importFileBrowseButton = new Button(composite, SWT.PUSH); >+ importFileBrowseButton.setText(MTJUIStrings.getString("SymbolDefinitionsImportWizardPage.browse")); >+ importFileBrowseButton.addSelectionListener(new SelectionAdapter() { >+ @Override >+ public void widgetSelected(SelectionEvent e) { >+ handleBrowseButton(); >+ } >+ }); >+ >+ } >+ >+ public String getDirectory() { >+ return importDirectory.getText(); >+ } >+ >+ >+ /** >+ * Store off the size of the control in the dialog settings. >+ */ >+ private void storeSize() { >+ IDialogSettings settings = getDialogSettings(); >+ Point size = getControl().getSize(); >+ if(settings != null) { >+ settings.put(KEY_WIDTH, size.x); >+ settings.put(KEY_HEIGHT, size.y); >+ } >+ } >+ >+ /** >+ * Retrieve the previously stored size or <code>null</code> if not found. >+ * >+ * @return >+ */ >+ private Point retrieveSize() { >+ Point size = null; >+ IDialogSettings settings = getDialogSettings(); >+ if(settings != null && settings.get(KEY_WIDTH) != null) { >+ size = new Point(settings.getInt(KEY_WIDTH), settings.getInt(KEY_HEIGHT)); >+ } >+ return size; >+ } >+ >+ private void handleBrowseButton() { >+ >+ DirectoryDialog dialog = new DirectoryDialog(getShell()); >+ String directory = dialog.open(); >+ if (directory != null) { >+ importDirectory.setText(directory); >+ updateFinishButton(); >+ } >+ >+ } >+ >+ private void updateControlEnable(boolean value) { >+ >+ importFileLabel.setEnabled(value); >+ importFileBrowseButton.setEnabled(value); >+ importDirectory.setEnabled(value); >+ >+ } >+ >+ public void updateFinishButton() { >+ >+ if(importTypeRadios[0].getSelection()) { >+ if(!new File(antennaFile).exists()) { >+ setPageComplete(false); >+ setErrorMessage(MTJUIStrings.getString("SymbolDefinitionsImportWizardPage.error.antennaLibraryIsNotSpecified")); >+ return; >+ } >+ } >+ else if(importTypeRadios[1].getSelection()) { >+ String directory = importDirectory.getText().trim(); >+ if(!new File(directory + File.separator + DeviceSymbolDefinitionSetFactory.J2MEPOLISH_FILENAME_XML_DEVICES).exists() || >+ !new File(directory + File.separator + DeviceSymbolDefinitionSetFactory.J2MEPOLISH_FILENAME_XML_GROUPS).exists()) { >+ setPageComplete(false); >+ setErrorMessage(MessageFormat.format(MTJUIStrings.getString("SymbolDefinitionsImportWizardPage.error.directoryDoesNotContaintFiles"), >+ new Object[] { DeviceSymbolDefinitionSetFactory.J2MEPOLISH_FILENAME_XML_DEVICES, DeviceSymbolDefinitionSetFactory.J2MEPOLISH_FILENAME_XML_GROUPS} )); >+ return; >+ } >+ } >+ setErrorMessage(null); >+ setPageComplete(true); >+ } >+ >+ >+ public int getImportType() { >+ if(importTypeRadios[0].getSelection()) { >+ return IMPORT_FROM_ANTENNA_JAR; >+ } >+ else if(importTypeRadios[1].getSelection()) { >+ return IMPORT_J2MEPOLISH_FORMAT; >+ } >+ return IMPORT_MTJ_FORMAT; >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 253860
:
118568
|
119066
|
119238