Source Code Cross Referenced for WizardPreferencesImportPage1.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » wizards » preferences » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » ui workbench » org.eclipse.ui.internal.wizards.preferences 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2005, 2007 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.internal.wizards.preferences;
011:
012:        import java.io.File;
013:        import java.io.FileInputStream;
014:        import java.io.FileNotFoundException;
015:        import java.io.IOException;
016:
017:        import org.eclipse.core.runtime.CoreException;
018:        import org.eclipse.core.runtime.Platform;
019:        import org.eclipse.core.runtime.preferences.IExportedPreferences;
020:        import org.eclipse.core.runtime.preferences.IPreferenceFilter;
021:        import org.eclipse.core.runtime.preferences.IPreferencesService;
022:        import org.eclipse.jface.dialogs.MessageDialog;
023:        import org.eclipse.swt.SWT;
024:        import org.eclipse.swt.widgets.Composite;
025:        import org.eclipse.swt.widgets.Event;
026:        import org.eclipse.ui.internal.WorkbenchPlugin;
027:        import org.eclipse.ui.internal.preferences.PreferenceTransferElement;
028:
029:        /**
030:         * Page 1 of the base preference import Wizard
031:         * 
032:         * 
033:         * @since 3.1
034:         */
035:        public class WizardPreferencesImportPage1 extends WizardPreferencesPage {
036:
037:            /**
038:             * Create a new instance of the receiver with name pageName.
039:             * @param pageName
040:             */
041:            protected WizardPreferencesImportPage1(String pageName) {
042:                super (pageName);
043:                setTitle(PreferencesMessages.WizardPreferencesImportPage1_importTitle);
044:                setDescription(PreferencesMessages.WizardPreferencesImportPage1_importDescription);
045:            }
046:
047:            /**
048:             * Create an instance of this class
049:             */
050:            public WizardPreferencesImportPage1() {
051:                this ("preferencesImportPage1");//$NON-NLS-1$
052:            }
053:
054:            /* (non-Javadoc)
055:             * @see org.eclipse.ui.internal.wizards.preferences.WizardPreferencesPage#getAllButtonText()
056:             */
057:            protected String getAllButtonText() {
058:                return PreferencesMessages.WizardPreferencesImportPage1_all;
059:            }
060:
061:            /* (non-Javadoc)
062:             * @see org.eclipse.ui.internal.wizards.preferences.WizardPreferencesPage#getChooseButtonText()
063:             */
064:            protected String getChooseButtonText() {
065:                return PreferencesMessages.WizardPreferencesImportPage1_choose;
066:            }
067:
068:            /* (non-Javadoc)
069:             * @see org.eclipse.ui.internal.wizards.preferences.WizardPreferencesPage#getTransfers()
070:             */
071:            protected PreferenceTransferElement[] getTransfers() {
072:                if (validFromFile()) {
073:                    FileInputStream fis;
074:
075:                    try {
076:                        fis = new FileInputStream(getDestinationValue());
077:                    } catch (FileNotFoundException e) {
078:                        WorkbenchPlugin.log(e.getMessage(), e);
079:                        return new PreferenceTransferElement[0];
080:                    }
081:                    IPreferencesService service = Platform
082:                            .getPreferencesService();
083:                    try {
084:                        IExportedPreferences prefs;
085:                        prefs = service.readPreferences(fis);
086:                        PreferenceTransferElement[] transfers = super 
087:                                .getTransfers();
088:                        IPreferenceFilter[] filters = new IPreferenceFilter[transfers.length];
089:                        for (int i = 0; i < transfers.length; i++) {
090:                            PreferenceTransferElement transfer = transfers[i];
091:                            filters[i] = transfer.getFilter();
092:                        }
093:                        IPreferenceFilter[] matches = service.matches(prefs,
094:                                filters);
095:                        PreferenceTransferElement[] returnTransfers = new PreferenceTransferElement[matches.length];
096:                        int index = 0;
097:                        for (int i = 0; i < matches.length; i++) {
098:                            IPreferenceFilter filter = matches[i];
099:                            for (int j = 0; j < transfers.length; j++) {
100:                                PreferenceTransferElement element = transfers[j];
101:                                if (element.getFilter().equals(filter)) {
102:                                    returnTransfers[index++] = element;
103:                                }
104:                            }
105:                        }
106:
107:                        PreferenceTransferElement[] destTransfers = new PreferenceTransferElement[index];
108:                        System.arraycopy(returnTransfers, 0, destTransfers, 0,
109:                                index);
110:                        return destTransfers;
111:                    } catch (CoreException e) {
112:                        //Do not log core exceptions, they indicate the chosen file is not valid
113:                        //WorkbenchPlugin.log(e.getMessage(), e);
114:                    } finally {
115:                        try {
116:                            fis.close();
117:                        } catch (IOException e) {
118:                            WorkbenchPlugin.log(e.getMessage(), e);
119:                        }
120:                    }
121:                }
122:
123:                return new PreferenceTransferElement[0];
124:            }
125:
126:            /**
127:             * Return whether or not the file is valid.
128:             * @return <code>true</code> of the file is an existing
129:             * file and not a directory
130:             */
131:            private boolean validFromFile() {
132:                File fromFile = new File(getDestinationValue());
133:                return fromFile.exists() && !fromFile.isDirectory();
134:            }
135:
136:            protected void setPreferenceTransfers() {
137:                super .setPreferenceTransfers();
138:
139:                if (validFromFile() && (transfersTable.getItemCount() == 0)) {
140:                    text
141:                            .setText(PreferencesMessages.WizardPreferences_noSpecificPreferenceDescription);
142:                } else {
143:                    text.setText(""); //$NON-NLS-1$
144:                }
145:            }
146:
147:            /* (non-Javadoc)
148:             * @see org.eclipse.ui.internal.wizards.preferences.WizardPreferencesPage#createTransferArea(org.eclipse.swt.widgets.Composite)
149:             */
150:            protected void createTransferArea(Composite composite) {
151:                createDestinationGroup(composite);
152:                createTransfersList(composite);
153:            }
154:
155:            /**
156:             * Answer the string to display in self as the destination type
157:             * 
158:             * @return java.lang.String
159:             */
160:            protected String getDestinationLabel() {
161:                return PreferencesMessages.WizardPreferencesImportPage1_file;
162:            }
163:
164:            /**
165:             * @param filters
166:             * @return <code>true</code> if the transfer was succesful, and
167:             *         <code>false</code> otherwise
168:             */
169:            protected boolean transfer(IPreferenceFilter[] filters) {
170:                File importFile = new File(getDestinationValue());
171:                FileInputStream fis = null;
172:                try {
173:                    if (filters.length > 0) {
174:                        try {
175:                            fis = new FileInputStream(importFile);
176:                        } catch (FileNotFoundException e) {
177:                            WorkbenchPlugin.log(e.getMessage(), e);
178:                            MessageDialog.openError(getControl().getShell(),
179:                                    new String(), e.getLocalizedMessage());
180:                            return false;
181:                        }
182:                        IPreferencesService service = Platform
183:                                .getPreferencesService();
184:                        try {
185:                            IExportedPreferences prefs = service
186:                                    .readPreferences(fis);
187:
188:                            service.applyPreferences(prefs, filters);
189:                        } catch (CoreException e) {
190:                            WorkbenchPlugin.log(e.getMessage(), e);
191:                            MessageDialog.openError(getControl().getShell(),
192:                                    new String(), e.getLocalizedMessage());
193:                            return false;
194:                        }
195:                    }
196:                } finally {
197:                    if (fis != null) {
198:                        try {
199:                            fis.close();
200:                        } catch (IOException e) {
201:                            WorkbenchPlugin.log(e.getMessage(), e);
202:                            MessageDialog.openError(getControl().getShell(),
203:                                    new String(), e.getLocalizedMessage());
204:                        }
205:                    }
206:                }
207:                return true;
208:            }
209:
210:            /**
211:             * Handle events and enablements for widgets in this page
212:             * 
213:             * @param e
214:             *            Event
215:             */
216:            public void handleEvent(Event e) {
217:                if (e.widget == destinationNameField) {
218:                    setPreferenceTransfers();
219:                }
220:
221:                super .handleEvent(e);
222:            }
223:
224:            /* (non-Javadoc)
225:             * @see org.eclipse.ui.internal.wizards.preferences.WizardPreferencesPage#getFileDialogTitle()
226:             */
227:            protected String getFileDialogTitle() {
228:                return PreferencesMessages.WizardPreferencesImportPage1_title;
229:            }
230:
231:            /* (non-Javadoc)
232:             * @see org.eclipse.ui.internal.wizards.preferences.WizardPreferencesPage#getFileDialogStyle()
233:             */
234:            protected int getFileDialogStyle() {
235:                return SWT.OPEN;
236:            }
237:
238:            /* (non-Javadoc)
239:             * @see org.eclipse.ui.internal.wizards.preferences.WizardPreferencesPage#validDestination()
240:             */
241:            protected boolean validDestination() {
242:                return super .validDestination() && validFromFile();
243:            }
244:
245:            /* (non-Javadoc)
246:             * @see org.eclipse.ui.internal.wizards.preferences.WizardPreferencesPage#getInvalidDestinationMessage()
247:             */
248:            protected String getInvalidDestinationMessage() {
249:                return PreferencesMessages.WizardPreferencesImportPage1_invalidPrefFile;
250:            }
251:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.