Source Code Cross Referenced for AboutSystemDialog.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » dialogs » 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.dialogs 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2003, 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.dialogs;
011:
012:        import java.io.File;
013:        import java.io.FileNotFoundException;
014:        import java.io.FileReader;
015:        import java.io.FileWriter;
016:        import java.io.IOException;
017:        import java.io.PrintWriter;
018:        import java.io.StringWriter;
019:        import java.util.Arrays;
020:        import java.util.Comparator;
021:        import java.util.Date;
022:        import java.util.Locale;
023:
024:        import org.eclipse.core.runtime.CoreException;
025:        import org.eclipse.core.runtime.IConfigurationElement;
026:        import org.eclipse.core.runtime.IPath;
027:        import org.eclipse.core.runtime.Platform;
028:        import org.eclipse.jface.dialogs.IDialogConstants;
029:        import org.eclipse.jface.dialogs.MessageDialog;
030:        import org.eclipse.jface.resource.JFaceResources;
031:        import org.eclipse.osgi.util.NLS;
032:        import org.eclipse.swt.SWT;
033:        import org.eclipse.swt.dnd.Clipboard;
034:        import org.eclipse.swt.dnd.TextTransfer;
035:        import org.eclipse.swt.dnd.Transfer;
036:        import org.eclipse.swt.layout.GridData;
037:        import org.eclipse.swt.layout.GridLayout;
038:        import org.eclipse.swt.widgets.Button;
039:        import org.eclipse.swt.widgets.Composite;
040:        import org.eclipse.swt.widgets.Control;
041:        import org.eclipse.swt.widgets.Label;
042:        import org.eclipse.swt.widgets.Shell;
043:        import org.eclipse.swt.widgets.Text;
044:        import org.eclipse.ui.PlatformUI;
045:        import org.eclipse.ui.about.ISystemSummarySection;
046:        import org.eclipse.ui.internal.IWorkbenchConstants;
047:        import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
048:        import org.eclipse.ui.internal.WorkbenchMessages;
049:        import org.eclipse.ui.internal.WorkbenchPlugin;
050:        import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
051:
052:        import com.ibm.icu.text.Collator;
053:        import com.ibm.icu.text.DateFormat;
054:
055:        /**
056:         * Displays system information about the eclipse application.  The content of
057:         * what is displayed is selectable through the
058:         * <code>org.eclipse.ui.systemSummaryExtensions</code> extension point.
059:         */
060:        public final class AboutSystemDialog extends ProductInfoDialog {
061:
062:            private Text text;
063:
064:            private final static int BROWSE_ERROR_LOG_BUTTON = IDialogConstants.CLIENT_ID;
065:
066:            private final static int COPY_TO_CLIPBOARD_BUTTON = IDialogConstants.CLIENT_ID + 1;
067:
068:            private final static String ERROR_LOG_COPY_FILENAME = "log"; //$NON-NLS-1$
069:
070:            /**
071:             * Create an instance of this dialog.
072:             * 
073:             * @param parentShell the parent shell
074:             */
075:            public AboutSystemDialog(Shell parentShell) {
076:                super (parentShell);
077:            }
078:
079:            /* (non-Javadoc)
080:             * Method declared on Window.
081:             */
082:            protected void configureShell(Shell newShell) {
083:                super .configureShell(newShell);
084:                newShell.setText(WorkbenchMessages.SystemSummary_title);
085:                PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell,
086:                        IWorkbenchHelpContextIds.SYSTEM_SUMMARY_DIALOG);
087:            }
088:
089:            /* (non-Javadoc)
090:             * Method declared on Dialog.
091:             */
092:            protected void createButtonsForButtonBar(Composite parent) {
093:                parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
094:
095:                Button button = createButton(parent, BROWSE_ERROR_LOG_BUTTON,
096:                        WorkbenchMessages.AboutSystemDialog_browseErrorLogName,
097:                        false);
098:                String filename = Platform.getLogFileLocation().toOSString();
099:                button.setEnabled(new File(filename).exists());
100:
101:                createButton(
102:                        parent,
103:                        COPY_TO_CLIPBOARD_BUTTON,
104:                        WorkbenchMessages.AboutSystemDialog_copyToClipboardName,
105:                        false);
106:
107:                new Label(parent, SWT.NONE).setLayoutData(new GridData(
108:                        GridData.FILL_HORIZONTAL));
109:                GridLayout layout = (GridLayout) parent.getLayout();
110:                layout.numColumns++;
111:                layout.makeColumnsEqualWidth = false;
112:
113:                createButton(parent, IDialogConstants.CLOSE_ID,
114:                        IDialogConstants.CLOSE_LABEL, true);
115:            }
116:
117:            /* (non-Javadoc)
118:             * Method declared on Dialog.
119:             */
120:            protected Control createDialogArea(Composite parent) {
121:                Composite outer = (Composite) super .createDialogArea(parent);
122:
123:                text = new Text(outer, SWT.MULTI | SWT.BORDER | SWT.READ_ONLY
124:                        | SWT.V_SCROLL | SWT.NO_FOCUS | SWT.H_SCROLL);
125:                text.setBackground(parent.getDisplay().getSystemColor(
126:                        SWT.COLOR_LIST_BACKGROUND));
127:                GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL
128:                        | GridData.VERTICAL_ALIGN_FILL);
129:                gridData.grabExcessVerticalSpace = true;
130:                gridData.grabExcessHorizontalSpace = true;
131:                gridData.heightHint = convertVerticalDLUsToPixels(300);
132:                gridData.widthHint = convertHorizontalDLUsToPixels(400);
133:                text.setLayoutData(gridData);
134:                text.setText(getSystemSummary());
135:                text.setFont(JFaceResources.getTextFont());
136:                return outer;
137:            }
138:
139:            private String getSystemSummary() {
140:                StringWriter out = new StringWriter();
141:                PrintWriter writer = new PrintWriter(out);
142:                writer.println(NLS.bind(
143:                        WorkbenchMessages.SystemSummary_timeStamp, DateFormat
144:                                .getDateTimeInstance(DateFormat.FULL,
145:                                        DateFormat.FULL).format(new Date())));
146:
147:                appendExtensions(writer);
148:                writer.close();
149:                return out.toString();
150:            }
151:
152:            /*
153:             * Appends the contents of all extentions to the configurationLogSections
154:             * extension point. 
155:             */
156:            private void appendExtensions(PrintWriter writer) {
157:                IConfigurationElement[] configElements = getSortedExtensions();
158:                for (int i = 0; i < configElements.length; ++i) {
159:                    IConfigurationElement element = configElements[i];
160:
161:                    Object obj = null;
162:                    try {
163:                        obj = WorkbenchPlugin.createExtension(element,
164:                                IWorkbenchConstants.TAG_CLASS);
165:                    } catch (CoreException e) {
166:                        WorkbenchPlugin
167:                                .log(
168:                                        "could not create class attribute for extension", //$NON-NLS-1$
169:                                        e.getStatus());
170:                    }
171:
172:                    writer.println();
173:                    writer.println(NLS.bind(
174:                            WorkbenchMessages.SystemSummary_sectionTitle,
175:                            element.getAttribute("sectionTitle"))); //$NON-NLS-1$
176:
177:                    if (obj instanceof  ISystemSummarySection) {
178:                        ISystemSummarySection logSection = (ISystemSummarySection) obj;
179:                        logSection.write(writer);
180:                    } else {
181:                        writer
182:                                .println(WorkbenchMessages.SystemSummary_sectionError);
183:                    }
184:                }
185:            }
186:
187:            private IConfigurationElement[] getSortedExtensions() {
188:                IConfigurationElement[] configElements = Platform
189:                        .getExtensionRegistry()
190:                        .getConfigurationElementsFor(
191:                                PlatformUI.PLUGIN_ID,
192:                                IWorkbenchRegistryConstants.PL_SYSTEM_SUMMARY_SECTIONS);
193:
194:                Arrays.sort(configElements, new Comparator() {
195:                    Collator collator = Collator.getInstance(Locale
196:                            .getDefault());
197:
198:                    public int compare(Object a, Object b) {
199:                        IConfigurationElement element1 = (IConfigurationElement) a;
200:                        IConfigurationElement element2 = (IConfigurationElement) b;
201:
202:                        String id1 = element1.getAttribute("id"); //$NON-NLS-1$
203:                        String id2 = element2.getAttribute("id"); //$NON-NLS-1$
204:
205:                        if (id1 != null && id2 != null && !id1.equals(id2)) {
206:                            return collator.compare(id1, id2);
207:                        }
208:
209:                        String title1 = element1.getAttribute("sectionTitle"); //$NON-NLS-1$ 
210:                        String title2 = element2.getAttribute("sectionTitle"); //$NON-NLS-1$
211:
212:                        if (title1 == null) {
213:                            title1 = ""; //$NON-NLS-1$
214:                        }
215:                        if (title2 == null) {
216:                            title2 = ""; //$NON-NLS-1$
217:                        }
218:
219:                        return collator.compare(title1, title2);
220:                    }
221:                });
222:
223:                return configElements;
224:            }
225:
226:            /* (non-Javadoc)
227:             * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
228:             */
229:            protected void buttonPressed(int buttonId) {
230:                switch (buttonId) {
231:                case IDialogConstants.CLOSE_ID:
232:                    close();
233:                    break;
234:                case BROWSE_ERROR_LOG_BUTTON:
235:                    openErrorLogBrowser();
236:                    break;
237:                case COPY_TO_CLIPBOARD_BUTTON:
238:                    runCopyToClipboard();
239:                    break;
240:                }
241:                super .buttonPressed(buttonId);
242:            }
243:
244:            private void openErrorLogBrowser() {
245:                String filename = Platform.getLogFileLocation().toOSString();
246:
247:                File log = new File(filename);
248:                if (log.exists()) {
249:                    // Make a copy of the file with a temporary name.
250:                    // Working around an issue with windows file associations/browser malfunction
251:                    // whereby the browser doesn't open on ".log" and we aren't returned an error.
252:                    // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=97783
253:                    File logCopy = makeDisplayCopy(log);
254:                    if (logCopy != null) {
255:                        openLink("file:///" + logCopy.getAbsolutePath()); //$NON-NLS-1$
256:                        return;
257:                    }
258:                    // Couldn't make copy, try to open the original log.
259:                    // We try the original in this case rather than putting up an error,
260:                    // because the copy could fail due to an I/O or out of space problem.
261:                    // In that case we may still be able to show the original log,
262:                    // depending on the platform.  The risk is that users with configurations
263:                    // that have bug #97783 will still get nothing (vs. an error) but we'd rather
264:                    // try again than put up an error dialog on platforms where the ability to
265:                    // view the original log works just fine.
266:                    openLink("file:///" + filename); //$NON-NLS-1$
267:                    return;
268:                }
269:                MessageDialog
270:                        .openInformation(
271:                                getShell(),
272:                                WorkbenchMessages.AboutSystemDialog_noLogTitle,
273:                                NLS
274:                                        .bind(
275:                                                WorkbenchMessages.AboutSystemDialog_noLogMessage,
276:                                                filename));
277:            }
278:
279:            /**
280:             * Returns a copy of the given file to be used for display in
281:             * a browser.
282:             * 
283:             * @return the file, or <code>null</code>
284:             */
285:            private File makeDisplayCopy(File file) {
286:                IPath path = WorkbenchPlugin.getDefault().getDataLocation();
287:                if (path == null) {
288:                    return null;
289:                }
290:                path = path.append(ERROR_LOG_COPY_FILENAME);
291:                File copy = path.toFile();
292:                FileReader in = null;
293:                FileWriter out = null;
294:                try {
295:                    in = new FileReader(file);
296:                    // don't append data, overwrite what was there
297:                    out = new FileWriter(copy);
298:                    char buffer[] = new char[4096];
299:                    int count;
300:                    while ((count = in.read(buffer, 0, buffer.length)) > 0) {
301:                        out.write(buffer, 0, count);
302:                    }
303:                } catch (FileNotFoundException e) {
304:                    return null;
305:                } catch (IOException e) {
306:                    return null;
307:                } finally {
308:                    try {
309:                        if (in != null) {
310:                            in.close();
311:                        }
312:                        if (out != null) {
313:                            out.close();
314:                        }
315:                    } catch (IOException e) {
316:                        return null;
317:                    }
318:                }
319:                return copy;
320:
321:            }
322:
323:            private void runCopyToClipboard() {
324:                if (text == null) {
325:                    return;
326:                }
327:
328:                Clipboard clipboard = null;
329:                try {
330:                    clipboard = new Clipboard(getShell().getDisplay());
331:                    clipboard.setContents(new Object[] { text.getText() },
332:                            new Transfer[] { TextTransfer.getInstance() });
333:                } finally {
334:                    if (clipboard != null) {
335:                        clipboard.dispose();
336:                    }
337:                }
338:            }
339:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.