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


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 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.pde.internal.ui.editor.site;
011:
012:        import org.eclipse.core.resources.IFolder;
013:        import org.eclipse.core.runtime.CoreException;
014:        import org.eclipse.jface.action.Action;
015:        import org.eclipse.jface.action.IMenuListener;
016:        import org.eclipse.jface.action.IMenuManager;
017:        import org.eclipse.jface.action.MenuManager;
018:        import org.eclipse.jface.action.Separator;
019:        import org.eclipse.jface.viewers.ColumnWeightData;
020:        import org.eclipse.jface.viewers.ISelection;
021:        import org.eclipse.jface.viewers.ISelectionChangedListener;
022:        import org.eclipse.jface.viewers.IStructuredContentProvider;
023:        import org.eclipse.jface.viewers.IStructuredSelection;
024:        import org.eclipse.jface.viewers.ITableLabelProvider;
025:        import org.eclipse.jface.viewers.LabelProvider;
026:        import org.eclipse.jface.viewers.SelectionChangedEvent;
027:        import org.eclipse.jface.viewers.StructuredSelection;
028:        import org.eclipse.jface.viewers.TableLayout;
029:        import org.eclipse.jface.viewers.TableViewer;
030:        import org.eclipse.pde.core.IModelChangedEvent;
031:        import org.eclipse.pde.internal.core.isite.ISite;
032:        import org.eclipse.pde.internal.core.isite.ISiteArchive;
033:        import org.eclipse.pde.internal.core.isite.ISiteModel;
034:        import org.eclipse.pde.internal.ui.PDEUIMessages;
035:        import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
036:        import org.eclipse.pde.internal.ui.editor.PDEFormEditorContributor;
037:        import org.eclipse.pde.internal.ui.editor.PDEFormPage;
038:        import org.eclipse.pde.internal.ui.editor.PDESection;
039:        import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
040:        import org.eclipse.pde.internal.ui.util.SWTUtil;
041:        import org.eclipse.swt.SWT;
042:        import org.eclipse.swt.custom.BusyIndicator;
043:        import org.eclipse.swt.events.SelectionAdapter;
044:        import org.eclipse.swt.events.SelectionEvent;
045:        import org.eclipse.swt.graphics.Image;
046:        import org.eclipse.swt.layout.GridData;
047:        import org.eclipse.swt.layout.GridLayout;
048:        import org.eclipse.swt.widgets.Button;
049:        import org.eclipse.swt.widgets.Composite;
050:        import org.eclipse.swt.widgets.Control;
051:        import org.eclipse.swt.widgets.Table;
052:        import org.eclipse.swt.widgets.TableColumn;
053:        import org.eclipse.ui.actions.ActionFactory;
054:        import org.eclipse.ui.forms.widgets.FormToolkit;
055:        import org.eclipse.ui.forms.widgets.Section;
056:        import org.eclipse.ui.model.WorkbenchContentProvider;
057:
058:        /**
059:         * 
060:         */
061:        public class ArchiveSection extends PDESection {
062:            private Table fTable;
063:            private TableViewer fViewer;
064:            private ISiteModel fModel;
065:            private Button fAddButton;
066:            private Button fEditButton;
067:            private Button fRemoveButton;
068:
069:            class FolderProvider extends WorkbenchContentProvider {
070:                public boolean hasChildren(Object element) {
071:                    Object[] children = getChildren(element);
072:                    for (int i = 0; i < children.length; i++) {
073:                        if (children[i] instanceof  IFolder) {
074:                            return true;
075:                        }
076:                    }
077:                    return false;
078:                }
079:            }
080:
081:            class ContentProvider extends DefaultContentProvider implements 
082:                    IStructuredContentProvider {
083:                public Object[] getElements(Object parent) {
084:                    ISiteModel model = (ISiteModel) parent;
085:                    return model.getSite().getArchives();
086:                }
087:            }
088:
089:            class ArchiveLabelProvider extends LabelProvider implements 
090:                    ITableLabelProvider {
091:                public String getColumnText(Object obj, int index) {
092:                    ISiteArchive archive = (ISiteArchive) obj;
093:                    switch (index) {
094:                    case 0:
095:                        return archive.getPath();
096:                    case 1:
097:                        return archive.getURL();
098:                    }
099:                    return ""; //$NON-NLS-1$
100:                }
101:
102:                public Image getColumnImage(Object obj, int index) {
103:                    return null;
104:                }
105:            }
106:
107:            /**
108:             * @param formPage
109:             */
110:            public ArchiveSection(PDEFormPage formPage, Composite parent) {
111:                super (formPage, parent, Section.DESCRIPTION);
112:                getSection().setText(
113:                        PDEUIMessages.SiteEditor_ArchiveSection_header);
114:                getSection().setDescription(
115:                        PDEUIMessages.SiteEditor_ArchiveSection_instruction);
116:                createClient(getSection(), formPage.getManagedForm()
117:                        .getToolkit());
118:            }
119:
120:            /*
121:             * (non-Javadoc)
122:             * 
123:             * @see org.eclipse.update.ui.forms.internal.FormSection#createClient(org.eclipse.swt.widgets.Composite,
124:             *      org.eclipse.update.ui.forms.internal.FormWidgetFactory)
125:             */
126:            public void createClient(Section section, FormToolkit toolkit) {
127:                fModel = (ISiteModel) getPage().getModel();
128:                fModel.addModelChangedListener(this );
129:
130:                section.setLayout(FormLayoutFactory.createClearGridLayout(
131:                        false, 1));
132:                Composite container = toolkit.createComposite(section);
133:                container.setLayout(FormLayoutFactory
134:                        .createSectionClientGridLayout(false, 2));
135:                container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
136:
137:                GridData data = new GridData(GridData.FILL_BOTH);
138:                section.setLayoutData(data);
139:
140:                createTable(container, toolkit);
141:                createTableViewer();
142:                createButtons(container, toolkit);
143:                toolkit.paintBordersFor(container);
144:                section.setClient(container);
145:                initialize();
146:            }
147:
148:            /* (non-Javadoc)
149:             * @see org.eclipse.ui.forms.AbstractFormPart#dispose()
150:             */
151:            public void dispose() {
152:                fModel.removeModelChangedListener(this );
153:                super .dispose();
154:            }
155:
156:            private void createButtons(Composite parent, FormToolkit toolkit) {
157:                Composite container = toolkit.createComposite(parent);
158:                GridLayout layout = new GridLayout();
159:                layout.marginHeight = 10;
160:                container.setLayout(layout);
161:                container.setLayoutData(new GridData(
162:                        GridData.VERTICAL_ALIGN_BEGINNING));
163:                fAddButton = toolkit.createButton(container,
164:                        PDEUIMessages.SiteEditor_add, SWT.PUSH);
165:                fAddButton
166:                        .setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
167:                fAddButton.addSelectionListener(new SelectionAdapter() {
168:                    public void widgetSelected(SelectionEvent e) {
169:                        showDialog(null);
170:                    }
171:                });
172:                fAddButton.setEnabled(isEditable());
173:                fEditButton = toolkit.createButton(container,
174:                        PDEUIMessages.SiteEditor_edit, SWT.PUSH);
175:                fEditButton
176:                        .setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
177:                fEditButton.addSelectionListener(new SelectionAdapter() {
178:                    public void widgetSelected(SelectionEvent e) {
179:                        IStructuredSelection ssel = (IStructuredSelection) fViewer
180:                                .getSelection();
181:                        if (ssel != null && ssel.size() == 1)
182:                            showDialog((ISiteArchive) ssel.getFirstElement());
183:                    }
184:                });
185:                fRemoveButton = toolkit.createButton(container,
186:                        PDEUIMessages.SiteEditor_remove, SWT.PUSH);
187:                fRemoveButton.setLayoutData(new GridData(
188:                        GridData.FILL_HORIZONTAL));
189:                fRemoveButton.addSelectionListener(new SelectionAdapter() {
190:                    public void widgetSelected(SelectionEvent e) {
191:                        handleDelete();
192:                    }
193:                });
194:                fRemoveButton.setEnabled(false);
195:                fEditButton.setEnabled(false);
196:                toolkit.paintBordersFor(container);
197:            }
198:
199:            private void createTable(Composite container, FormToolkit toolkit) {
200:                fTable = toolkit.createTable(container, SWT.FULL_SELECTION);
201:                GridData gd = new GridData(GridData.FILL_BOTH);
202:                gd.heightHint = 100;
203:                fTable.setLayoutData(gd);
204:                TableColumn col1 = new TableColumn(fTable, SWT.NULL);
205:                col1.setText(PDEUIMessages.SiteEditor_ArchiveSection_col1);
206:                TableColumn col2 = new TableColumn(fTable, SWT.NULL);
207:                col2.setText(PDEUIMessages.SiteEditor_ArchiveSection_col2);
208:                TableLayout tlayout = new TableLayout();
209:                tlayout.addColumnData(new ColumnWeightData(50, 200));
210:                tlayout.addColumnData(new ColumnWeightData(50, 200));
211:                fTable.setLayout(tlayout);
212:                fTable.setHeaderVisible(true);
213:                createContextMenu(fTable);
214:            }
215:
216:            private void createTableViewer() {
217:                fViewer = new TableViewer(fTable);
218:                fViewer.setContentProvider(new ContentProvider());
219:                fViewer.setLabelProvider(new ArchiveLabelProvider());
220:                fViewer.setInput(getPage().getModel());
221:                fViewer
222:                        .addSelectionChangedListener(new ISelectionChangedListener() {
223:                            public void selectionChanged(
224:                                    SelectionChangedEvent event) {
225:                                handleSelectionChanged();
226:                            }
227:                        });
228:            }
229:
230:            private void handleSelectionChanged() {
231:                ISelection selection = fViewer.getSelection();
232:                getManagedForm().fireSelectionChanged(this , selection);
233:                getPage().getPDEEditor().setSelection(selection);
234:                if (!isEditable()) {
235:                    return;
236:                }
237:                if (selection != null
238:                        && selection instanceof  IStructuredSelection) {
239:                    IStructuredSelection ssel = (IStructuredSelection) selection;
240:                    fRemoveButton.setEnabled(ssel.size() > 0);
241:                    fEditButton.setEnabled(ssel.size() == 1);
242:                } else {
243:                    fRemoveButton.setEnabled(false);
244:                    fEditButton.setEnabled(false);
245:                }
246:            }
247:
248:            private void showDialog(final ISiteArchive archive) {
249:                final ISiteModel model = (ISiteModel) getPage().getModel();
250:                BusyIndicator.showWhile(fTable.getDisplay(), new Runnable() {
251:                    public void run() {
252:                        NewArchiveDialog dialog = new NewArchiveDialog(fTable
253:                                .getShell(), model, archive);
254:                        dialog.create();
255:                        SWTUtil.setDialogSize(dialog, 400, -1);
256:                        dialog.open();
257:                    }
258:                });
259:            }
260:
261:            private void handleDelete() {
262:                try {
263:                    ISelection selection = fViewer.getSelection();
264:                    if (selection != null
265:                            && selection instanceof  IStructuredSelection) {
266:                        IStructuredSelection ssel = (IStructuredSelection) selection;
267:                        if (ssel.size() > 0) {
268:                            ISiteArchive[] array = (ISiteArchive[]) ssel
269:                                    .toList().toArray(
270:                                            new ISiteArchive[ssel.size()]);
271:                            ISite site = ((ISiteModel) getPage().getModel())
272:                                    .getSite();
273:                            site.removeArchives(array);
274:                        }
275:                    }
276:                } catch (CoreException e) {
277:                }
278:            }
279:
280:            /*
281:             * (non-Javadoc)
282:             * 
283:             * @see org.eclipse.update.ui.forms.internal.FormSection#doGlobalAction(java.lang.String)
284:             */
285:            public boolean doGlobalAction(String actionId) {
286:                if (actionId.equals(ActionFactory.DELETE.getId())) {
287:                    BusyIndicator.showWhile(fTable.getDisplay(),
288:                            new Runnable() {
289:                                public void run() {
290:                                    handleDelete();
291:                                }
292:                            });
293:                    return true;
294:                }
295:                return false;
296:            }
297:
298:            public void refresh() {
299:                fViewer.refresh();
300:                super .refresh();
301:            }
302:
303:            public void initialize() {
304:                refresh();
305:            }
306:
307:            public void modelChanged(IModelChangedEvent e) {
308:                markStale();
309:            }
310:
311:            private void createContextMenu(Control control) {
312:                MenuManager popupMenuManager = new MenuManager();
313:                IMenuListener listener = new IMenuListener() {
314:                    public void menuAboutToShow(IMenuManager mng) {
315:                        Action removeAction = new Action(
316:                                PDEUIMessages.SiteEditor_remove) {
317:                            public void run() {
318:                                doGlobalAction(ActionFactory.DELETE.getId());
319:                            }
320:                        };
321:                        removeAction.setEnabled(isEditable());
322:                        mng.add(removeAction);
323:                        mng.add(new Separator());
324:                        PDEFormEditorContributor contributor = getPage()
325:                                .getPDEEditor().getContributor();
326:                        contributor.contextMenuAboutToShow(mng);
327:                    }
328:                };
329:                popupMenuManager.addMenuListener(listener);
330:                popupMenuManager.setRemoveAllWhenShown(true);
331:                control.setMenu(popupMenuManager.createContextMenu(control));
332:            }
333:
334:            /* (non-Javadoc)
335:             * @see org.eclipse.ui.forms.AbstractFormPart#setFormInput(java.lang.Object)
336:             */
337:            public boolean setFormInput(Object input) {
338:                if (input instanceof  ISiteArchive) {
339:                    fViewer.setSelection(new StructuredSelection(input), true);
340:                    return true;
341:                }
342:                return super.setFormInput(input);
343:            }
344:        }
ww_w___._j_av__a___2s___._co__m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.