Source Code Cross Referenced for SampleStandbyContent.java in  » IDE-Eclipse » Eclipse-plug-in-development » org » eclipse » pde » internal » ui » samples » 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 » Eclipse plug in development » org.eclipse.pde.internal.ui.samples 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 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.pde.internal.ui.samples;
011:
012:        import java.io.IOException;
013:        import java.io.InputStream;
014:        import java.util.ArrayList;
015:        import java.util.Properties;
016:
017:        import org.eclipse.core.resources.IFile;
018:        import org.eclipse.core.resources.IProject;
019:        import org.eclipse.core.resources.IResource;
020:        import org.eclipse.core.resources.IWorkspaceRoot;
021:        import org.eclipse.core.runtime.CoreException;
022:        import org.eclipse.core.runtime.IConfigurationElement;
023:        import org.eclipse.core.runtime.Platform;
024:        import org.eclipse.debug.core.ILaunchManager;
025:        import org.eclipse.debug.ui.ILaunchShortcut;
026:        import org.eclipse.jface.viewers.ISelection;
027:        import org.eclipse.jface.viewers.StructuredSelection;
028:        import org.eclipse.osgi.util.NLS;
029:        import org.eclipse.pde.internal.ui.PDEPlugin;
030:        import org.eclipse.pde.internal.ui.PDEPluginImages;
031:        import org.eclipse.pde.internal.ui.PDEUIMessages;
032:        import org.eclipse.pde.ui.launcher.EclipseLaunchShortcut;
033:        import org.eclipse.swt.SWT;
034:        import org.eclipse.swt.custom.BusyIndicator;
035:        import org.eclipse.swt.widgets.Composite;
036:        import org.eclipse.swt.widgets.Control;
037:        import org.eclipse.ui.IMemento;
038:        import org.eclipse.ui.ISharedImages;
039:        import org.eclipse.ui.IViewPart;
040:        import org.eclipse.ui.PlatformUI;
041:        import org.eclipse.ui.forms.events.HyperlinkAdapter;
042:        import org.eclipse.ui.forms.events.HyperlinkEvent;
043:        import org.eclipse.ui.forms.widgets.FormText;
044:        import org.eclipse.ui.forms.widgets.FormToolkit;
045:        import org.eclipse.ui.forms.widgets.Hyperlink;
046:        import org.eclipse.ui.forms.widgets.ScrolledForm;
047:        import org.eclipse.ui.forms.widgets.TableWrapData;
048:        import org.eclipse.ui.forms.widgets.TableWrapLayout;
049:        import org.eclipse.ui.intro.IIntroPart;
050:        import org.eclipse.ui.intro.config.IStandbyContentPart;
051:        import org.eclipse.ui.part.ISetSelectionTarget;
052:
053:        public class SampleStandbyContent implements  IStandbyContentPart {
054:            private ScrolledForm form;
055:            private Hyperlink moreLink;
056:            private String helpURL;
057:            private String launcher;
058:            private String launchTarget;
059:            private FormText descText;
060:            private FormText instText;
061:            private ILaunchShortcut defaultShortcut;
062:            private IConfigurationElement sample;
063:            // cached input.
064:            private String input;
065:
066:            private static String MEMENTO_SAMPLE_ID_ATT = "sampleId"; //$NON-NLS-1$
067:
068:            /**
069:             *  
070:             */
071:            public SampleStandbyContent() {
072:                defaultShortcut = new EclipseLaunchShortcut();
073:                PDEPlugin.getDefault().getLabelProvider().connect(this );
074:            }
075:
076:            /*
077:             * (non-Javadoc)
078:             * 
079:             * @see org.eclipse.ui.intro.internal.parts.IStandbyContentPart#createPartControl(org.eclipse.swt.widgets.Composite,
080:             *      org.eclipse.ui.forms.widgets.FormToolkit)
081:             */
082:            public void createPartControl(Composite parent, FormToolkit toolkit) {
083:                form = toolkit.createScrolledForm(parent);
084:                //form.setBackgroundImage(PDEPlugin.getDefault().getLabelProvider().get(
085:                //		PDEPluginImages.DESC_FORM_BANNER));
086:                TableWrapLayout layout = new TableWrapLayout();
087:                layout.verticalSpacing = 10;
088:                layout.topMargin = 10;
089:                layout.bottomMargin = 10;
090:                layout.leftMargin = 10;
091:                layout.rightMargin = 10;
092:                form.getBody().setLayout(layout);
093:                descText = toolkit.createFormText(form.getBody(), true);
094:                descText.setLayoutData(new TableWrapData(
095:                        TableWrapData.FILL_GRAB));
096:                descText.setText("", false, false); //$NON-NLS-1$
097:                moreLink = toolkit.createHyperlink(form.getBody(), "Read More", //$NON-NLS-1$
098:                        SWT.NULL);
099:                moreLink.addHyperlinkListener(new HyperlinkAdapter() {
100:                    public void linkActivated(HyperlinkEvent e) {
101:                        if (helpURL != null)
102:                            PlatformUI.getWorkbench().getHelpSystem()
103:                                    .displayHelpResource(helpURL);
104:                    }
105:                });
106:                instText = toolkit.createFormText(form.getBody(), true);
107:                instText.setLayoutData(new TableWrapData(
108:                        TableWrapData.FILL_GRAB));
109:                StringBuffer buf = new StringBuffer();
110:                buf.append(PDEUIMessages.SampleStandbyContent_content);
111:                instText.setText(buf.toString(), true, false);
112:                instText.addHyperlinkListener(new HyperlinkAdapter() {
113:                    public void linkActivated(HyperlinkEvent e) {
114:                        Object href = e.getHref();
115:                        if (href.equals("help")) { //$NON-NLS-1$
116:                            PlatformUI.getWorkbench().getHelpSystem()
117:                                    .displayHelpResource(helpURL);
118:                        } else if (href.equals("browse")) { //$NON-NLS-1$
119:                            doBrowse();
120:                        } else if (href.equals("run")) { //$NON-NLS-1$
121:                            doRun(launcher, launchTarget, false);
122:                        } else if (href.equals("debug")) { //$NON-NLS-1$
123:                            doRun(launcher, launchTarget, true);
124:                        }
125:                    }
126:                });
127:                instText.setImage(
128:                        "run", PDEPlugin.getDefault().getLabelProvider().get( //$NON-NLS-1$
129:                                PDEPluginImages.DESC_RUN_EXC));
130:                instText.setImage(
131:                        "debug", PDEPlugin.getDefault().getLabelProvider() //$NON-NLS-1$
132:                                .get(PDEPluginImages.DESC_DEBUG_EXC));
133:                instText.setImage(
134:                        "help", PlatformUI.getWorkbench().getSharedImages() //$NON-NLS-1$
135:                                .getImage(ISharedImages.IMG_OBJS_INFO_TSK));
136:            }
137:
138:            private void doRun(String launcher, String target,
139:                    final boolean debug) {
140:                ILaunchShortcut shortcut = defaultShortcut;
141:                final ISelection selection;
142:                if (target != null) {
143:                    selection = new StructuredSelection();
144:                } else
145:                    selection = new StructuredSelection();
146:                final ILaunchShortcut fshortcut = shortcut;
147:                BusyIndicator.showWhile(form.getDisplay(), new Runnable() {
148:                    public void run() {
149:                        fshortcut.launch(selection,
150:                                debug ? ILaunchManager.DEBUG_MODE
151:                                        : ILaunchManager.RUN_MODE);
152:                    }
153:                });
154:            }
155:
156:            private void doBrowse() {
157:                IWorkspaceRoot root = PDEPlugin.getWorkspace().getRoot();
158:                IProject[] projects = root.getProjects();
159:                ISetSelectionTarget target = findTarget();
160:                if (target == null)
161:                    return;
162:                String sid = sample.getAttribute("id"); //$NON-NLS-1$
163:                if (sid == null)
164:                    return;
165:                ArrayList items = new ArrayList();
166:                for (int i = 0; i < projects.length; i++) {
167:                    IProject project = projects[i];
168:                    if (!project.exists() || !project.isOpen())
169:                        continue;
170:                    IFile pfile = project.getFile("sample.properties"); //$NON-NLS-1$
171:                    if (pfile.exists()) {
172:                        try {
173:                            InputStream is = pfile.getContents();
174:                            Properties prop = new Properties();
175:                            prop.load(is);
176:                            is.close();
177:                            String id = prop.getProperty("id"); //$NON-NLS-1$
178:                            if (id != null && id.equals(sid)) {
179:                                //match
180:                                IResource res = findSelectReveal(project, prop
181:                                        .getProperty("projectName")); //$NON-NLS-1$
182:                                if (res != null)
183:                                    items.add(res);
184:                            }
185:                        } catch (IOException e) {
186:                            PDEPlugin.logException(e);
187:                        } catch (CoreException e) {
188:                            PDEPlugin.logException(e);
189:                        }
190:                    }
191:                }
192:                if (items.size() > 0)
193:                    target.selectReveal(new StructuredSelection(items));
194:            }
195:
196:            private ISetSelectionTarget findTarget() {
197:                String id = sample.getAttribute("targetViewId"); //$NON-NLS-1$
198:                if (id == null)
199:                    return null;
200:                IViewPart view = PDEPlugin.getActivePage().findView(id);
201:                if (view == null || !(view instanceof  ISetSelectionTarget))
202:                    return null;
203:                return (ISetSelectionTarget) view;
204:            }
205:
206:            private IResource findSelectReveal(IProject project,
207:                    String originalName) {
208:                IConfigurationElement[] projects = sample
209:                        .getChildren("project"); //$NON-NLS-1$
210:                for (int i = 0; i < projects.length; i++) {
211:                    if (originalName.equals(projects[i].getAttribute("name"))) { //$NON-NLS-1$
212:                        String path = projects[i].getAttribute("selectReveal"); //$NON-NLS-1$
213:                        if (path == null)
214:                            continue;
215:                        IResource res = project.findMember(path);
216:                        if (res.exists())
217:                            return res;
218:                    }
219:                }
220:                return null;
221:            }
222:
223:            /*
224:             * (non-Javadoc)
225:             * 
226:             * @see org.eclipse.ui.intro.internal.parts.IStandbyContentPart#getControl()
227:             */
228:            public Control getControl() {
229:                return form;
230:            }
231:
232:            /*
233:             * (non-Javadoc)
234:             * 
235:             * @see org.eclipse.ui.intro.internal.parts.IStandbyContentPart#init(org.eclipse.ui.intro.IIntroPart)
236:             */
237:            public void init(IIntroPart introPart) {
238:            }
239:
240:            /*
241:             * (non-Javadoc)
242:             * 
243:             * @see org.eclipse.ui.intro.internal.parts.IStandbyContentPart#setInput(java.lang.Object)
244:             */
245:            public void setInput(Object input) {
246:                // if the new input is null, use cached input from momento.
247:                if (input != null)
248:                    this .input = (String) input;
249:                String sampleId = this .input.toString();
250:                IConfigurationElement[] samples = Platform
251:                        .getExtensionRegistry().getConfigurationElementsFor(
252:                                "org.eclipse.pde.ui.samples"); //$NON-NLS-1$
253:                for (int i = 0; i < samples.length; i++) {
254:                    IConfigurationElement sample = samples[i];
255:                    String id = sample.getAttribute("id"); //$NON-NLS-1$
256:                    if (id != null && id.equals(sampleId)) {
257:                        update(sample);
258:                        return;
259:                    }
260:                }
261:                update(null);
262:            }
263:
264:            private void update(IConfigurationElement sample) {
265:                this .sample = sample;
266:                if (form == null)
267:                    return;
268:                String title = sample != null ? sample.getAttribute("name") : ""; //$NON-NLS-1$ //$NON-NLS-2$
269:                form.setText(title);
270:                if (sample != null) {
271:                    launcher = sample.getAttribute("launcher"); //$NON-NLS-1$
272:                    launchTarget = sample.getAttribute("launchTarget"); //$NON-NLS-1$
273:                } else {
274:                    launcher = null;
275:                    launchTarget = null;
276:                }
277:                IConfigurationElement[] descConfig = sample != null ? sample
278:                        .getChildren("description") : null; //$NON-NLS-1$
279:                if (descConfig != null && descConfig.length == 1) {
280:                    String desc = descConfig[0].getValue();
281:                    String content = NLS.bind(
282:                            PDEUIMessages.SampleStandbyContent_desc,
283:                            (desc != null ? desc : "")); //$NON-NLS-1$ 
284:                    helpURL = descConfig[0].getAttribute("helpHref"); //$NON-NLS-1$
285:                    moreLink.setVisible(helpURL != null);
286:                    descText.setText(content, true, false);
287:                } else {
288:                    moreLink.setVisible(false);
289:                    descText.setText("", false, false); //$NON-NLS-1$
290:                }
291:                form.reflow(true);
292:            } /*
293:             * (non-Javadoc)
294:             * 
295:             * @see org.eclipse.ui.intro.internal.parts.IStandbyContentPart#setFocus()
296:             */
297:
298:            public void setFocus() {
299:                form.setFocus();
300:            }
301:
302:            /*
303:             * (non-Javadoc)
304:             * 
305:             * @see org.eclipse.ui.intro.internal.parts.IStandbyContentPart#dispose()
306:             */
307:            public void dispose() {
308:                PDEPlugin.getDefault().getLabelProvider().disconnect(this );
309:            }
310:
311:            /* (non-Javadoc)
312:             * @see org.eclipse.ui.intro.config.IStandbyContentPart#init(org.eclipse.ui.intro.IIntroPart, org.eclipse.ui.IMemento)
313:             */
314:            public void init(IIntroPart introPart, IMemento memento) {
315:                // try to restore last state.
316:                input = getCachedInput(memento);
317:
318:            }
319:
320:            /**
321:             * Tries to create the last content part viewed, based on sample id.
322:             * 
323:             * @param memento
324:             * @return
325:             */
326:            private String getCachedInput(IMemento memento) {
327:                if (memento == null)
328:                    return null;
329:                return memento.getString(MEMENTO_SAMPLE_ID_ATT);
330:
331:            }
332:
333:            /* (non-Javadoc)
334:             * @see org.eclipse.ui.intro.config.IStandbyContentPart#saveState(org.eclipse.ui.IMemento)
335:             */
336:            public void saveState(IMemento memento) {
337:                String currentSampleId = input;
338:                if (input != null)
339:                    memento.putString(MEMENTO_SAMPLE_ID_ATT, currentSampleId);
340:
341:            }
342:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.