Source Code Cross Referenced for OverridableTabListContentProvider.java in  » IDE-Eclipse » ui » org » eclipse » ui » internal » views » properties » tabbed » view » 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 » org.eclipse.ui.internal.views.properties.tabbed.view 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 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.views.properties.tabbed.view;
011:
012:        import org.eclipse.core.runtime.Assert;
013:        import org.eclipse.jface.viewers.ISelection;
014:        import org.eclipse.jface.viewers.IStructuredSelection;
015:        import org.eclipse.jface.viewers.StructuredSelection;
016:        import org.eclipse.jface.viewers.Viewer;
017:        import org.eclipse.ui.IWorkbenchPart;
018:        import org.eclipse.ui.part.IContributedContentsView;
019:        import org.eclipse.ui.views.properties.IPropertySheetPage;
020:        import org.eclipse.ui.views.properties.tabbed.AbstractOverridableTabListPropertySection;
021:        import org.eclipse.ui.views.properties.tabbed.IOverridableTabListContentProvider;
022:        import org.eclipse.ui.views.properties.tabbed.ISection;
023:        import org.eclipse.ui.views.properties.tabbed.ITabDescriptor;
024:        import org.eclipse.ui.views.properties.tabbed.ITabItem;
025:        import org.eclipse.ui.views.properties.tabbed.ITabSelectionListener;
026:        import org.eclipse.ui.views.properties.tabbed.TabContents;
027:        import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
028:
029:        /**
030:         * An extended implementation of the content provider for the tabbed property
031:         * sheet page's list of tabs.
032:         * <p>
033:         * This implementation allows the section to override the list of what tabs are
034:         * displayed, rather than using the default list of tabs from the tabbed
035:         * property registry.
036:         * 
037:         * @author Anthony Hunter
038:         * @since 3.4
039:         */
040:        public class OverridableTabListContentProvider extends
041:                TabListContentProvider implements 
042:                IOverridableTabListContentProvider, ITabSelectionListener {
043:
044:            /**
045:             * Constructor for OverrideTabListContentProvider.
046:             * 
047:             * @param registry
048:             *            the tabbed property registry.
049:             */
050:            public OverridableTabListContentProvider(
051:                    TabbedPropertyRegistry registry) {
052:                super (registry);
053:            }
054:
055:            private TabbedPropertySheetPage tabbedPropertySheetPage;
056:
057:            private TabbedPropertyViewer tabbedPropertyViewer;
058:
059:            /**
060:             * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
061:             */
062:            public Object[] getElements(Object inputElement) {
063:                if (tabbedPropertySheetPage.getCurrentTab() == null) {
064:                    /*
065:                     * In this case, return the default list of tabs from the registry.
066:                     * The contributor will not have had a chance to load and override
067:                     * the tabs.
068:                     */
069:                    return registry.getTabDescriptors(currentPart,
070:                            (ISelection) inputElement);
071:                }
072:                return getOverrideTabs(inputElement);
073:            }
074:
075:            /*
076:             * (non-Javadoc)
077:             * 
078:             * @see org.eclipse.ui.internal.views.properties.tabbed.view.TabListContentProvider#dispose()
079:             */
080:            public void dispose() {
081:                stopListening();
082:                this .tabbedPropertyViewer = null;
083:                this .currentPart = null;
084:                this .tabbedPropertySheetPage = null;
085:            }
086:
087:            /*
088:             * (non-Javadoc)
089:             * 
090:             * @see org.eclipse.ui.internal.views.properties.tabbed.view.TabListContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
091:             *      java.lang.Object, java.lang.Object)
092:             */
093:            public void inputChanged(Viewer viewer, Object oldInput,
094:                    Object newInput) {
095:                if (tabbedPropertyViewer == null) {
096:                    Assert.isTrue(viewer instanceof  TabbedPropertyViewer);
097:                    init((TabbedPropertyViewer) viewer);
098:                }
099:            }
100:
101:            /**
102:             * Initialize the content provider for a tabbed property viewer.
103:             * 
104:             * @param tabbedPropertyViewer
105:             *            a tabbed property viewer.
106:             */
107:            private void init(TabbedPropertyViewer newTabbedPropertyViewer) {
108:                this .tabbedPropertyViewer = newTabbedPropertyViewer;
109:                currentPart = tabbedPropertyViewer.getWorkbenchPart();
110:                if (currentPart.getAdapter(IPropertySheetPage.class) != null) {
111:                    tabbedPropertySheetPage = (TabbedPropertySheetPage) currentPart
112:                            .getAdapter(IPropertySheetPage.class);
113:                } else {
114:                    /*
115:                     * Is the part is a IContributedContentsView for the contributor,
116:                     * for example, outline view.
117:                     */
118:                    IContributedContentsView view = (IContributedContentsView) currentPart
119:                            .getAdapter(IContributedContentsView.class);
120:                    if (view != null) {
121:                        IWorkbenchPart part = view.getContributingPart();
122:                        if (part != null) {
123:                            tabbedPropertySheetPage = (TabbedPropertySheetPage) part
124:                                    .getAdapter(IPropertySheetPage.class);
125:                        }
126:                    }
127:                }
128:                Assert
129:                        .isNotNull(
130:                                tabbedPropertySheetPage,
131:                                "DynamicTabListContentProvider could not find the TabbedPropertySheetPage for the active part");//$NON-NLS-1$
132:                startListening();
133:            }
134:
135:            /**
136:             * Start listening to tab selection change events.
137:             */
138:            private void startListening() {
139:                tabbedPropertySheetPage.addTabSelectionListener(this );
140:            }
141:
142:            /**
143:             * Stop listening to tab selection change events.
144:             */
145:            private void stopListening() {
146:                tabbedPropertySheetPage.removeTabSelectionListener(this );
147:            }
148:
149:            /*
150:             * (non-Javadoc)
151:             * 
152:             * @see org.eclipse.ui.views.properties.tabbed.ITabSelectionListener#tabSelected(org.eclipse.ui.views.properties.tabbed.ITabDescriptor)
153:             */
154:            public void tabSelected(ITabDescriptor tabDescriptor) {
155:                AbstractOverridableTabListPropertySection section = getOverridableTabListPropertySection();
156:                Assert.isNotNull(section);
157:                int selectedIndex = tabbedPropertyViewer.getSelectionIndex();
158:                section.selectTab(selectedIndex);
159:            }
160:
161:            /**
162:             * set the selected tab from the list of tabs provided by the section.
163:             */
164:            private void setSelectedTab() {
165:                TabDescriptor currentSelectedTabInList = null;
166:                IStructuredSelection selectionFromList = (IStructuredSelection) tabbedPropertyViewer
167:                        .getSelection();
168:                if (!selectionFromList.equals(StructuredSelection.EMPTY)) {
169:                    currentSelectedTabInList = (TabDescriptor) selectionFromList
170:                            .getFirstElement();
171:                }
172:                AbstractOverridableTabListPropertySection section = getOverridableTabListPropertySection();
173:                if (section == null) {
174:                    if (currentSelectedTabInList == null) {
175:                        /*
176:                         * make sure there is a selected tab in the list.
177:                         */
178:                        TabDescriptor newSelectedTab = (TabDescriptor) tabbedPropertyViewer
179:                                .getElementAt(0);
180:                        if (newSelectedTab != null) {
181:                            tabbedPropertyViewer.setSelection(
182:                                    new StructuredSelection(newSelectedTab),
183:                                    true);
184:                        }
185:                    }
186:                    return;
187:                }
188:                ITabItem[] dynamicTabItems = section.getTabs();
189:                if (dynamicTabItems == null) {
190:                    /*
191:                     * if the section does not provide overridden tabs, return.
192:                     */
193:                    return;
194:                }
195:                int selectedTabIndex = -1;
196:                for (int i = 0; i < dynamicTabItems.length; i++) {
197:                    if (dynamicTabItems[i].isSelected()) {
198:                        selectedTabIndex = i;
199:                    }
200:                }
201:                if (currentSelectedTabInList == null
202:                        || !currentSelectedTabInList.getText().equals(
203:                                dynamicTabItems[selectedTabIndex].getText())) {
204:                    TabDescriptor newSelectedTab = (TabDescriptor) tabbedPropertyViewer
205:                            .getElementAt(selectedTabIndex);
206:                    tabbedPropertyViewer.setSelection(new StructuredSelection(
207:                            newSelectedTab), true);
208:                }
209:            }
210:
211:            /**
212:             * Get the list of tabs to display in the tabbed property sheet page.
213:             * 
214:             * @param inputElement
215:             *            The current input element.
216:             * @return the list of tabs.
217:             */
218:            private ITabDescriptor[] getOverrideTabs(Object inputElement) {
219:                ITabDescriptor tabDescriptors[] = registry.getTabDescriptors(
220:                        currentPart, (ISelection) inputElement);
221:                if (tabDescriptors == TabbedPropertyRegistry.EMPTY_DESCRIPTOR_ARRAY) {
222:                    /*
223:                     * We clone the dynamic tabs from the single tab in the registry. If
224:                     * the registry has no tabs for the selection, return.
225:                     */
226:                    return tabDescriptors;
227:                }
228:                AbstractOverridableTabListPropertySection section = getOverridableTabListPropertySection();
229:                Assert.isNotNull(section);
230:                ITabItem[] tabItems = section.getTabs();
231:                if (tabItems == null) {
232:                    /*
233:                     * if the section does not provide overridden tabs, return the
234:                     * default tabs from the registry.
235:                     */
236:                    return tabDescriptors;
237:                }
238:                ITabDescriptor[] overrideTabDescriptors = new ITabDescriptor[tabItems.length];
239:                TabDescriptor target = (TabDescriptor) tabDescriptors[0];
240:                for (int i = 0; i < tabItems.length; i++) {
241:                    TabDescriptor cloneTabDescriptor = (TabDescriptor) target
242:                            .clone();
243:                    cloneTabDescriptor.setLabel(tabItems[i].getText());
244:                    cloneTabDescriptor.setImage(tabItems[i].getImage());
245:                    cloneTabDescriptor.setIndented(tabItems[i].isIndented());
246:                    cloneTabDescriptor.setSelected(tabItems[i].isSelected());
247:                    overrideTabDescriptors[i] = cloneTabDescriptor;
248:                    // System.out.print("override " + i + " [" +  //$NON-NLS-1$//$NON-NLS-2$
249:                    // tabItems[i].getText() + "]");//$NON-NLS-1$
250:                    // if (tabItems[i].isSelected()) {
251:                    // System.out.print(" selected");//$NON-NLS-1$
252:                    // }
253:                    // System.out.println("");//$NON-NLS-1$
254:                }
255:                return overrideTabDescriptors;
256:            }
257:
258:            /*
259:             * (non-Javadoc)
260:             * 
261:             * @see org.eclipse.ui.views.properties.tabbed.IOverridableTabListContentProvider#overrideTabs()
262:             */
263:            public void overrideTabs() {
264:                stopListening();
265:                Object input = tabbedPropertyViewer.getInput();
266:                tabbedPropertyViewer.setInput(input);
267:                setSelectedTab();
268:                startListening();
269:            }
270:
271:            /**
272:             * Get the section implementation that provides the list of tabs. In our
273:             * implementation, all the sections provide the list of tabs, so we select
274:             * the first section from the tab descriptor.
275:             * 
276:             * @return the section.
277:             */
278:            private AbstractOverridableTabListPropertySection getOverridableTabListPropertySection() {
279:                TabContents tab = tabbedPropertySheetPage.getCurrentTab();
280:                Assert.isNotNull(tab);
281:                if (tab != null) {
282:                    ISection section = tab.getSectionAtIndex(0);
283:                    if (section instanceof  AbstractOverridableTabListPropertySection) {
284:                        return (AbstractOverridableTabListPropertySection) section;
285:                    }
286:                }
287:                return null;
288:            }
289:        }
ww__w__._j___ava__2_s.__c__o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.