Source Code Cross Referenced for SimpleCSCommandComboPart.java in  » IDE-Eclipse » Eclipse-plug-in-development » org » eclipse » pde » internal » ui » editor » cheatsheet » simple » details » 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.cheatsheet.simple.details 
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.pde.internal.ui.editor.cheatsheet.simple.details;
011:
012:        import java.util.Iterator;
013:
014:        import org.eclipse.pde.internal.ui.editor.cheatsheet.simple.ISimpleCSCommandKeyListener;
015:        import org.eclipse.pde.internal.ui.editor.cheatsheet.simple.NewCommandKeyEvent;
016:        import org.eclipse.pde.internal.ui.editor.cheatsheet.simple.SimpleCSCommandManager;
017:        import org.eclipse.pde.internal.ui.parts.ComboPart;
018:        import org.eclipse.swt.custom.CCombo;
019:        import org.eclipse.swt.events.DisposeEvent;
020:        import org.eclipse.swt.events.DisposeListener;
021:        import org.eclipse.swt.widgets.Combo;
022:        import org.eclipse.swt.widgets.Composite;
023:        import org.eclipse.ui.forms.widgets.FormToolkit;
024:
025:        /**
026:         * SimpleCSCommandComboPart
027:         *
028:         */
029:        public class SimpleCSCommandComboPart extends ComboPart implements 
030:                ISimpleCSCommandKeyListener, DisposeListener {
031:
032:            private int fNewCommandKeyIndex;
033:
034:            private int fComboEntryLimit;
035:
036:            /**
037:             * 
038:             */
039:            public SimpleCSCommandComboPart() {
040:                super ();
041:                fNewCommandKeyIndex = -1;
042:                fComboEntryLimit = -1;
043:            }
044:
045:            /**
046:             * @param listener
047:             */
048:            public void addDisposeListener(DisposeListener listener) {
049:                if (combo == null) {
050:                    return;
051:                } else if (combo instanceof  Combo) {
052:                    ((Combo) combo).addDisposeListener(listener);
053:                } else {
054:                    ((CCombo) combo).addDisposeListener(listener);
055:                }
056:            }
057:
058:            /* (non-Javadoc)
059:             * @see org.eclipse.pde.internal.ui.parts.ComboPart#createControl(org.eclipse.swt.widgets.Composite, org.eclipse.ui.forms.widgets.FormToolkit, int)
060:             */
061:            public void createControl(Composite parent, FormToolkit toolkit,
062:                    int style) {
063:                super .createControl(parent, toolkit, style);
064:                // Connect to the global command manager
065:                SimpleCSCommandManager.Instance().addCommandKeyListener(this );
066:                // Register to be notified when the combo is diposed in order to 
067:                // disconnect from the global command manager
068:                addDisposeListener(this );
069:            }
070:
071:            /* (non-Javadoc)
072:             * @see org.eclipse.pde.internal.ui.editor.cheatsheet.simple.ISimpleCSCommandKeyListener#newCommandKey(org.eclipse.pde.internal.ui.editor.cheatsheet.simple.NewCommandKeyEvent)
073:             */
074:            public void newCommandKey(NewCommandKeyEvent event) {
075:                // Source:  Another combo box
076:                String key = event.getKey();
077:                // Add the new key to the combo if it does not already exist
078:                putValueInCombo(key, fNewCommandKeyIndex);
079:            }
080:
081:            /**
082:             * @param key
083:             */
084:            private void putValueInCombo(String key, int index) {
085:                // Ensure the key does not already exist in the combo
086:                if (indexOf(key) != -1) {
087:                    return;
088:                }
089:                // If we are at the combo entry limit, remove the least recent entry
090:                // that is not selected
091:                if (getItemCount() >= fComboEntryLimit) {
092:                    removeLeastRecentEntry();
093:                }
094:                // Add the new key
095:                if (index < 0) {
096:                    // Add at the end
097:                    add(key);
098:                } else {
099:                    // Add at the specified index
100:                    add(key, index);
101:                }
102:            }
103:
104:            /**
105:             * 
106:             */
107:            private void removeLeastRecentEntry() {
108:                // The least recent entry is the last non-selected entry in the 
109:                // reciever's list
110:                int entryCount = getItemCount();
111:                // Nothing to do if there is one entry or no entries
112:                if (entryCount <= 1) {
113:                    return;
114:                }
115:                // There has to be at least two entries
116:                int lastEntry = entryCount - 1;
117:                // Remove the last entry if it is NOT selected
118:                // Important:  The entry may be selected for another model object;
119:                // since, the details page is static.  As a result, removing the last
120:                // entry for this model object may remove a selected entry for another
121:                // model object.  In that case, the entry is re-inserted into the 
122:                // reciever when the other model object is selected again 
123:                if (lastEntry != getSelectionIndex()) {
124:                    remove(lastEntry);
125:                    return;
126:                }
127:                // Last entry was selected, try the second last entry
128:                int secondlastEntry = lastEntry - 1;
129:                remove(secondlastEntry);
130:            }
131:
132:            /**
133:             * @param limit
134:             */
135:            public void setComboEntryLimit(int limit) {
136:                fComboEntryLimit = limit;
137:            }
138:
139:            /**
140:             * @return
141:             */
142:            public int getComboEntryLimit() {
143:                return fComboEntryLimit;
144:            }
145:
146:            /**
147:             * Specify the index to insert the new command key into the combo box 
148:             * reciever.  Applicable to new command keys obtained via new command key
149:             * events (Source: other combo boxes).
150:             * @param newCommandKeyIndex
151:             */
152:            public void setNewCommandKeyIndex(int newCommandKeyIndex) {
153:                fNewCommandKeyIndex = newCommandKeyIndex;
154:            }
155:
156:            /**
157:             * @return
158:             */
159:            public int getNewCommandKeyIndex() {
160:                return fNewCommandKeyIndex;
161:            }
162:
163:            /* (non-Javadoc)
164:             * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
165:             */
166:            public void widgetDisposed(DisposeEvent e) {
167:                // Disconnect from the global command manager
168:                SimpleCSCommandManager.Instance()
169:                        .removeCommandKeyListener(this );
170:            }
171:
172:            /**
173:             * 
174:             */
175:            public void populate() {
176:                // Populate the combo with all the values found in the command manager
177:                Iterator iterator = SimpleCSCommandManager.Instance().getKeys()
178:                        .iterator();
179:                while (iterator.hasNext()) {
180:                    String key = (String) iterator.next();
181:                    add(key);
182:                }
183:            }
184:
185:            /**
186:             * @param key
187:             * @param value
188:             */
189:            public void putValue(String key, String value) {
190:                putValue(key, value, -1);
191:            }
192:
193:            /**
194:             * @param key
195:             * @param value
196:             */
197:            public void putValue(String key, String value, int index) {
198:                // Source:  This combo box
199:                // Add the new key to the combo if it does not already exist
200:                SimpleCSCommandManager manager = SimpleCSCommandManager
201:                        .Instance();
202:                putValueInCombo(key, index);
203:                // Store the actual value in the command manager and notify the
204:                // other command combo boxes
205:                manager.put(key, value);
206:            }
207:
208:            /**
209:             * @param key
210:             * @return
211:             */
212:            public String getValue(String key) {
213:                return SimpleCSCommandManager.Instance().get(key);
214:            }
215:
216:        }
w__w__w_.___j__a_v__a__2___s_.__co_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.