KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > cheatsheet > RegisterCSWizardPage


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.pde.internal.ui.wizards.cheatsheet;
13
14 import java.util.ArrayList JavaDoc;
15
16 import org.eclipse.core.resources.IFile;
17 import org.eclipse.core.resources.IProject;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.IPath;
20 import org.eclipse.core.runtime.Path;
21 import org.eclipse.jface.dialogs.Dialog;
22 import org.eclipse.jface.window.Window;
23 import org.eclipse.jface.wizard.WizardPage;
24 import org.eclipse.pde.core.IModel;
25 import org.eclipse.pde.core.plugin.IPluginAttribute;
26 import org.eclipse.pde.core.plugin.IPluginElement;
27 import org.eclipse.pde.core.plugin.IPluginExtension;
28 import org.eclipse.pde.core.plugin.IPluginModelBase;
29 import org.eclipse.pde.core.plugin.IPluginObject;
30 import org.eclipse.pde.internal.core.ICoreConstants;
31 import org.eclipse.pde.internal.core.PDECore;
32 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSConstants;
33 import org.eclipse.pde.internal.core.plugin.AbbreviatedFragmentModel;
34 import org.eclipse.pde.internal.core.plugin.AbbreviatedPluginModel;
35 import org.eclipse.pde.internal.core.util.PDETextHelper;
36 import org.eclipse.pde.internal.ui.IHelpContextIds;
37 import org.eclipse.pde.internal.ui.PDEPlugin;
38 import org.eclipse.pde.internal.ui.PDEUIMessages;
39 import org.eclipse.pde.internal.ui.util.SWTUtil;
40 import org.eclipse.swt.SWT;
41 import org.eclipse.swt.events.ModifyEvent;
42 import org.eclipse.swt.events.ModifyListener;
43 import org.eclipse.swt.events.SelectionAdapter;
44 import org.eclipse.swt.events.SelectionEvent;
45 import org.eclipse.swt.layout.GridData;
46 import org.eclipse.swt.layout.GridLayout;
47 import org.eclipse.swt.widgets.Button;
48 import org.eclipse.swt.widgets.Combo;
49 import org.eclipse.swt.widgets.Composite;
50 import org.eclipse.swt.widgets.Group;
51 import org.eclipse.swt.widgets.Label;
52 import org.eclipse.swt.widgets.Text;
53 import org.eclipse.ui.PlatformUI;
54
55 /**
56  * RegisterCSWizardPage
57  *
58  */

59 public abstract class RegisterCSWizardPage extends WizardPage implements
60         IRegisterCSData {
61
62     public final static String JavaDoc F_PAGE_NAME = "register-cs"; //$NON-NLS-1$
63

64     public final static String JavaDoc F_CS_EXTENSION_POINT_ID =
65         "org.eclipse.ui.cheatsheets.cheatSheetContent"; //$NON-NLS-1$
66

67     public final static String JavaDoc F_CS_ELEMENT_CATEGORY = "category"; //$NON-NLS-1$
68

69     public final static String JavaDoc F_CS_ELEMENT_CHEATSHEET = "cheatsheet"; //$NON-NLS-1$
70

71     public final static String JavaDoc F_CS_ELEMENT_DESCRIPTION = "description"; //$NON-NLS-1$
72

73     public final static String JavaDoc F_LOCALE_VARIABLE = "$nl$"; //$NON-NLS-1$
74

75     private Combo fCategoryCombo;
76     
77     private Button fCategoryButton;
78     
79     private Text fDescriptionText;
80     
81     protected IModel fCheatSheetModel;
82     
83     private IPluginModelBase fPluginModelBase;
84     
85     private IProject fPluginProject;
86     
87     private boolean fPluginExists;
88     
89     private String JavaDoc fDataCategoryName;
90     
91     private String JavaDoc fDataDescription;
92     
93     private String JavaDoc fDataCheatSheetID;
94     
95     private IFile fPluginFile;
96     
97     private boolean fIsFragment;
98     
99     private CSCategoryTrackerUtil fCategoryTrackerUtil;
100     
101     /**
102      * @param pageName
103      */

104     public RegisterCSWizardPage(IModel model) {
105         super(F_PAGE_NAME);
106
107         fCheatSheetModel = model;
108         initialize();
109     }
110
111     /**
112      *
113      */

114     private void initialize() {
115         
116         setTitle(PDEUIMessages.CheatSheetFileWizardPage_1);
117         setDescription(PDEUIMessages.RegisterCSWizardPage_wizardPageDescription);
118         
119         fCategoryCombo = null;
120         fCategoryButton = null;
121         fDescriptionText = null;
122         
123         fCategoryTrackerUtil = new CSCategoryTrackerUtil();
124         
125         fDataCategoryName = null;
126         fDataDescription = null;
127         
128         // Get the project the cheat sheet is stored in
129
fPluginProject = fCheatSheetModel.getUnderlyingResource().getProject();
130
131         fDataCheatSheetID = generateCheatSheetID();
132         
133         initializePluginModel();
134     }
135
136     /**
137      *
138      */

139     private void initializePluginModel() {
140         IPath pluginPath = new Path(ICoreConstants.PLUGIN_FILENAME_DESCRIPTOR);
141         IPath fragmentPath = new Path(ICoreConstants.FRAGMENT_FILENAME_DESCRIPTOR);
142         // Check to see if a plugin or fragment file exists in the project
143
// storing the cheat sheet
144
if (fPluginProject.exists(pluginPath)) {
145             fPluginFile = fPluginProject.getFile(pluginPath.toPortableString());
146             fPluginModelBase =
147                 new AbbreviatedPluginModel(fPluginFile, F_CS_EXTENSION_POINT_ID);
148             fPluginExists = true;
149             fIsFragment = false;
150         } else if (fPluginProject.exists(fragmentPath)) {
151             fPluginFile = fPluginProject.getFile(fragmentPath.toPortableString());
152             fPluginModelBase =
153                 new AbbreviatedFragmentModel(fPluginFile, F_CS_EXTENSION_POINT_ID);
154             fPluginExists = true;
155             fIsFragment = true;
156         } else {
157             fPluginFile = fPluginProject.getFile(pluginPath.toPortableString());
158             fPluginModelBase = null;
159             fPluginExists = false;
160             fIsFragment = false;
161         }
162         // Load the plug-in or fragment if it exists in a lightweight model
163
if (fPluginExists) {
164             try {
165                 fPluginModelBase.load();
166             } catch (CoreException e) {
167                 PDECore.logException(e);
168             }
169         }
170     }
171     
172     /* (non-Javadoc)
173      * @see org.eclipse.pde.internal.ui.wizards.cheatsheet.IRegisterCSData#getDataDescription()
174      */

175     public String JavaDoc getDataDescription() {
176         return fDataDescription;
177     }
178     
179     /* (non-Javadoc)
180      * @see org.eclipse.pde.internal.ui.wizards.cheatsheet.IRegisterCSData#getDataCategoryName()
181      */

182     public String JavaDoc getDataCategoryName() {
183         return fDataCategoryName;
184     }
185     
186     /* (non-Javadoc)
187      * @see org.eclipse.pde.internal.ui.wizards.cheatsheet.IRegisterCSData#getDataCategoryType()
188      */

189     public int getDataCategoryType() {
190         String JavaDoc categoryID = getDataCategoryID();
191         if (categoryID == null) {
192             return CSCategoryTrackerUtil.F_TYPE_NO_CATEGORY;
193         }
194         return fCategoryTrackerUtil.getCategoryType(categoryID);
195     }
196     
197     /* (non-Javadoc)
198      * @see org.eclipse.pde.internal.ui.wizards.cheatsheet.IRegisterCSData#getDataCategoryID()
199      */

200     public String JavaDoc getDataCategoryID() {
201         if (fDataCategoryName != null) {
202             return fCategoryTrackerUtil.getCategoryID(fDataCategoryName);
203         }
204         return null;
205     }
206     
207     /* (non-Javadoc)
208      * @see org.eclipse.pde.internal.ui.wizards.cheatsheet.IRegisterCSData#pluginExists()
209      */

210     public boolean pluginExists() {
211         return fPluginExists;
212     }
213     
214     /* (non-Javadoc)
215      * @see org.eclipse.pde.internal.ui.wizards.cheatsheet.IRegisterCSData#getDataContentFile()
216      */

217     public String JavaDoc getDataContentFile() {
218         // Retrieve the full path to the cheat sheet
219
String JavaDoc portablePath =
220             fCheatSheetModel.getUnderlyingResource().getFullPath().toPortableString();
221         // Chop off the starting '/'
222
String JavaDoc result = portablePath.substring(1);
223         // Chop off the project name
224
int index = result.indexOf('/');
225         if (index == -1) {
226             return ""; //$NON-NLS-1$
227
}
228         result = result.substring(index);
229         // Prepend the locale specific variable
230
result = F_LOCALE_VARIABLE + result;
231         
232         return result;
233     }
234     
235     /* (non-Javadoc)
236      * @see org.eclipse.pde.internal.ui.wizards.cheatsheet.IRegisterCSData#getDataCheatSheetID()
237      */

238     public String JavaDoc getDataCheatSheetID() {
239         return fDataCheatSheetID;
240     }
241     
242     /* (non-Javadoc)
243      * @see org.eclipse.pde.internal.ui.wizards.cheatsheet.IRegisterCSData#getPluginFile()
244      */

245     public IFile getPluginFile() {
246         return fPluginFile;
247     }
248
249     /* (non-Javadoc)
250      * @see org.eclipse.pde.internal.ui.wizards.cheatsheet.IRegisterCSData#isFragment()
251      */

252     public boolean isFragment() {
253         return fIsFragment;
254     }
255     
256     /* (non-Javadoc)
257      * @see org.eclipse.pde.internal.ui.wizards.cheatsheet.IRegisterCSData#getPluginProject()
258      */

259     public IProject getPluginProject() {
260         return fPluginProject;
261     }
262     
263     /**
264      * @return
265      */

266     public abstract String JavaDoc getDataCheatSheetName();
267     
268     /**
269      * @return
270      */

271     public abstract boolean isCompositeCheatSheet();
272     
273     /* (non-Javadoc)
274      * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
275      */

276     public void createControl(Composite parent) {
277         
278         createUI(parent);
279         createUIListeners();
280         
281         updateUI();
282         validateUI();
283
284     }
285
286     /**
287      * @param parent
288      */

289     private void createUI(Composite parent) {
290         // Create the container
291
Composite container = createUIContainer(parent);
292         // Create the label
293
createUILabel(container);
294         // Create the group
295
Group group = createUIGroup(container);
296         // Create the category field
297
createUICategoryField(group);
298         // Create the description field
299
createUIDescriptionField(group);
300         // Set the control for the reciever
301
// Must be done otherwise a null assertion error is generated
302
setControl(container);
303         // Apply the dialog font to all controls using the default font
304
Dialog.applyDialogFont(container);
305         // TODO: MP: MED: CompCS: Update help context ID
306
// Provide functionality for the help button
307
PlatformUI.getWorkbench().getHelpSystem().setHelp(container,
308                 IHelpContextIds.NEW_SCHEMA);
309     }
310
311     /**
312      * @param container
313      */

314     private void createUILabel(Composite container) {
315         Label label = new Label(container, SWT.WRAP);
316         label.setText(PDEUIMessages.RegisterCSWizardPage_labelInstructionText);
317         GridData data = new GridData(GridData.FILL_HORIZONTAL);
318         data.widthHint = 300;
319         label.setLayoutData(data);
320     }
321
322     /**
323      * @param container
324      * @return
325      */

326     private Group createUIGroup(Composite container) {
327         Group group = new Group(container, SWT.NONE);
328         GridLayout layout = new GridLayout(3, false);
329         layout.marginWidth = 6;
330         layout.marginHeight = 6;
331         group.setLayout(layout);
332         GridData data = new GridData(GridData.FILL_HORIZONTAL);
333         data.horizontalSpan = 3;
334         data.verticalIndent = 10;
335         group.setLayoutData(data);
336         group.setText(PDEUIMessages.RegisterCSWizardPage_groupRegistration);
337         return group;
338     }
339
340     /**
341      * @param parent
342      * @return
343      */

344     private Composite createUIContainer(Composite parent) {
345         Composite container = new Composite(parent, SWT.NONE);
346         GridLayout layout = new GridLayout();
347         layout.numColumns = 3;
348         container.setLayout(layout);
349         return container;
350     }
351     
352     /**
353      * @param parent
354      */

355     private void createUICategoryField(Composite parent) {
356         // Create the label
357
createUICategoryLabel(parent);
358         // Create the combo
359
createUICategoryCombo(parent);
360         // Create the button
361
createUICategoryButton(parent);
362     }
363
364     /**
365      * @param parent
366      */

367     private void createUICategoryLabel(Composite parent) {
368         Label label = new Label(parent, SWT.NONE);
369         label.setText(PDEUIMessages.RegisterCSWizardPage_labelCategory);
370     }
371
372     /**
373      * @param parent
374      */

375     private void createUICategoryCombo(Composite parent) {
376         int style = SWT.READ_ONLY | SWT.BORDER;
377         fCategoryCombo = new Combo(parent, style);
378         GridData data = new GridData(GridData.FILL_HORIZONTAL);
379         fCategoryCombo.setLayoutData(data);
380         fCategoryCombo.add(PDEUIMessages.SimpleCSCommandDetails_6);
381         fCategoryCombo.setText(PDEUIMessages.SimpleCSCommandDetails_6);
382     }
383
384     /**
385      * @param parent
386      */

387     private void createUICategoryButton(Composite parent) {
388         fCategoryButton = new Button(parent, SWT.PUSH);
389         GridData data = new GridData(GridData.HORIZONTAL_ALIGN_END);
390         data.widthHint = 50;
391         fCategoryButton.setLayoutData(data);
392         fCategoryButton.setText(PDEUIMessages.RegisterCSWizardPage_buttonNew);
393         fCategoryButton.setToolTipText(PDEUIMessages.RegisterCSWizardPage_toolTipNewCategory);
394         SWTUtil.setButtonDimensionHint(fCategoryButton);
395     }
396
397     /**
398      * @param parent
399      */

400     private void createUIDescriptionField(Composite parent) {
401         // Create the label
402
createUIDescriptionLabel(parent);
403         // Create the text widget
404
createUIDescriptionText(parent);
405     }
406
407     /**
408      * @param parent
409      */

410     private void createUIDescriptionLabel(Composite parent) {
411         Label label = new Label(parent, SWT.NONE);
412         label.setText(PDEUIMessages.RegisterCSWizardPage_labelDescription);
413         int style = GridData.VERTICAL_ALIGN_BEGINNING
414                 | GridData.HORIZONTAL_ALIGN_END;
415         GridData data = new GridData(style);
416         label.setLayoutData(data);
417     }
418
419     /**
420      * @param parent
421      */

422     private void createUIDescriptionText(Composite parent) {
423         int style = SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.BORDER;
424         fDescriptionText = new Text(parent, style);
425         GridData data = new GridData(GridData.FILL_HORIZONTAL);
426         data.heightHint = 60;
427         data.horizontalSpan = 2;
428         fDescriptionText.setLayoutData(data);
429     }
430
431     /**
432      *
433      */

434     private void createUIListeners() {
435         // Create listeners for the category button
436
createUIListenersCategoryButton();
437         // Create listeners for the category combo box
438
createUIListenersCategoryCombo();
439         // Create listeners for the description text
440
createUIListenersDescriptionText();
441     }
442
443     /**
444      *
445      */

446     private void createUIListenersCategoryButton() {
447         fCategoryButton.addSelectionListener(new SelectionAdapter() {
448             public void widgetSelected(SelectionEvent e) {
449                 handleWidgetSelectedCategoryButton();
450             }
451         });
452     }
453
454     /**
455      *
456      */

457     private void createUIListenersCategoryCombo() {
458         fCategoryCombo.addModifyListener(new ModifyListener() {
459             public void modifyText(ModifyEvent e) {
460                 fDataCategoryName = fCategoryCombo.getText();
461             }
462         });
463     }
464
465     /**
466      *
467      */

468     private void createUIListenersDescriptionText() {
469         fDescriptionText.addModifyListener(new ModifyListener() {
470             public void modifyText(ModifyEvent e) {
471                 fDataDescription = fDescriptionText.getText();
472             }
473         });
474     }
475     
476     /**
477      *
478      */

479     private void handleWidgetSelectedCategoryButton() {
480         // Create a dialog allowing the user to input the category name
481
NewCategoryNameDialog dialog = new NewCategoryNameDialog(
482                 PDEPlugin.getActiveWorkbenchShell());
483         dialog.create();
484         dialog.getShell().setText(PDEUIMessages.RegisterCSWizardPage_dialogTitleNewCategory);
485
486         if (dialog.open() == Window.OK) {
487             String JavaDoc newCategoryName = dialog.getNameText();
488
489             if (PDETextHelper.isDefinedAfterTrim(newCategoryName)) {
490                 String JavaDoc trimmedText = newCategoryName.trim();
491                 fCategoryCombo.add(trimmedText);
492                 fCategoryCombo.setText(trimmedText);
493                 fCategoryCombo.setFocus();
494                 String JavaDoc id = generateCategoryID(trimmedText);
495                 fCategoryTrackerUtil.associate(id, trimmedText,
496                         CSCategoryTrackerUtil.F_TYPE_NEW_CATEGORY);
497             }
498         }
499         
500     }
501
502     /**
503      *
504      */

505     private void updateUI() {
506
507         if (fPluginExists) {
508             // Find all cheat sheet extensions within the host plug-in
509
IPluginExtension[] extensions = findExtensions(fPluginModelBase,
510                     F_CS_EXTENSION_POINT_ID);
511             // Process all category elements
512
processCategoryElements(extensions);
513             // Process all cheat sheet elements
514
processCheatSheetElements(extensions);
515         }
516     }
517
518     /**
519      * @param extensions
520      */

521     private void processCategoryElements(IPluginExtension[] extensions) {
522         // Linear search: Process all cheat sheet extensions found
523
for (int i = 0; i < extensions.length; i++) {
524             if (extensions[i].getChildCount() == 0) {
525                 // Extension has no children, skip to the next extension
526
continue;
527             }
528             IPluginExtension extension = extensions[i];
529             IPluginObject[] pluginObjects = extension.getChildren();
530             // Process all children
531
for (int j = 0; j < pluginObjects.length; j++) {
532                 if (pluginObjects[j] instanceof IPluginElement) {
533                     IPluginElement element = (IPluginElement)pluginObjects[j];
534                     if (element.getName().equals(F_CS_ELEMENT_CATEGORY)) {
535                         // Category element
536
// Update the category combo
537
updateUICategoryComboElement(element);
538                     }
539                 }
540             }
541         }
542     }
543     
544     /**
545      * @param extensions
546      */

547     private void processCheatSheetElements(IPluginExtension[] extensions) {
548         // Query cheat sheet extensions for information required to update
549
// the description text and category combo widgets
550
// Linear search: Process all cheat sheet extensions found
551
for (int i = 0; i < extensions.length; i++) {
552             if (extensions[i].getChildCount() == 0) {
553                 // Extension has no children, skip to the next extension
554
continue;
555             }
556             IPluginExtension extension = extensions[i];
557             IPluginObject[] pluginObjects = extension.getChildren();
558             // Process all children
559
for (int j = 0; j < pluginObjects.length; j++) {
560                 if (pluginObjects[j] instanceof IPluginElement) {
561                     IPluginElement element = (IPluginElement)pluginObjects[j];
562                     if (element.getName().equals(F_CS_ELEMENT_CHEATSHEET)) {
563                         // Cheat sheet element
564
processCheatSheetElement(element, fDataCheatSheetID);
565                     }
566                     
567                 }
568             }
569         }
570     }
571
572     /**
573      * Process category elements
574      * @param parentElement
575      */

576     private void updateUICategoryComboElement(IPluginElement parentElement) {
577         // Get the id attribute
578
IPluginAttribute idAttribute =
579             parentElement.getAttribute(ICompCSConstants.ATTRIBUTE_ID);
580         // Get the name attribute
581
IPluginAttribute nameAttribute =
582             parentElement.getAttribute(ICompCSConstants.ATTRIBUTE_NAME);
583         // Add the category to the combo box only if
584
// (1) the category name is defined
585
// (2) the category has not already been added to the combo box
586
if ((nameAttribute != null) &&
587                 PDETextHelper.isDefined(nameAttribute.getValue()) &&
588                 (idAttribute != null) &&
589                 PDETextHelper.isDefined(idAttribute.getValue()) &&
590                 (fCategoryTrackerUtil.containsCategoryName(nameAttribute.getValue()) == false)) {
591             // TODO: MP: LOW: CompCS: Reference translated value
592
fCategoryCombo.add(nameAttribute.getValue());
593             // Assocate the category ID with the category name
594
fCategoryTrackerUtil.associate(idAttribute.getValue(),
595                     nameAttribute.getValue(),
596                     CSCategoryTrackerUtil.F_TYPE_OLD_CATEGORY);
597         }
598     }
599     
600     /**
601      * Process cheatsheet elements with a category attribute
602      * @param parentElement
603      */

604     private void updateUICategoryComboAttribute(IPluginElement element) {
605         // Get the category attribute
606
IPluginAttribute categoryAttribute =
607             element.getAttribute(F_CS_ELEMENT_CATEGORY);
608         // Process the category attribute
609
if ((categoryAttribute != null) &&
610                 PDETextHelper.isDefined(categoryAttribute.getValue())) {
611             String JavaDoc id = categoryAttribute.getValue();
612             // Check to see if the category ID has been defined
613
if (fCategoryTrackerUtil.containsCategoryID(id)) {
614                 // Update the category combo selection
615
String JavaDoc name =
616                     fCategoryTrackerUtil.getCategoryName(id);
617                 fCategoryCombo.setText(name);
618             } else {
619                 // Add the category ID to the combo box (no assoicated name)
620
// This can only happen if the category is defined outside of
621
// the plug-in the cheat sheet is stored in
622
fCategoryCombo.add(id);
623                 fCategoryCombo.setText(id);
624                 fCategoryTrackerUtil.associate(id, id,
625                         CSCategoryTrackerUtil.F_TYPE_OLD_CATEGORY);
626             }
627         }
628     }
629     
630     /**
631      * @param extensions
632      */

633     private void processCheatSheetElement(IPluginElement parentElement,
634             String JavaDoc generatedID) {
635         // Get the id attribute
636
IPluginAttribute idAttribute =
637             parentElement.getAttribute(ICompCSConstants.ATTRIBUTE_ID);
638
639         // Check for the generated ID for this cheat sheet
640
// If a cheat sheet exists with the generated ID already, read its
641
// description and populate the description text accordingly
642
if ((idAttribute != null) &&
643                 PDETextHelper.isDefined(idAttribute.getValue()) &&
644                 generatedID.equals(idAttribute.getValue())) {
645             // Matching cheat sheet extension found
646
// Process children if any
647
if (parentElement.getChildCount() > 0) {
648                 // Update the description text widget
649
updateUIDescriptionText(parentElement);
650             }
651             updateUICategoryComboAttribute(parentElement);
652         }
653     }
654
655     /**
656      * @param parentElement
657      */

658     private void updateUIDescriptionText(IPluginElement parentElement) {
659         IPluginObject pluginObject = parentElement.getChildren()[0];
660         if (pluginObject instanceof IPluginElement) {
661             IPluginElement element = (IPluginElement)pluginObject;
662             if (element.getName().equals(F_CS_ELEMENT_DESCRIPTION) &&
663                     PDETextHelper.isDefinedAfterTrim(element.getText())) {
664                 // Triggers listener to update data description on load
665
fDescriptionText.setText(element.getText().trim());
666             }
667         }
668     }
669     
670     /**
671      *
672      */

673     private void validateUI() {
674         setPageComplete(true);
675     }
676     
677     /**
678      * @param model
679      * @param extensionPointID
680      * @return
681      */

682     public IPluginExtension[] findExtensions(IPluginModelBase model,
683             String JavaDoc extensionPointID) {
684         IPluginExtension[] extensions = model.getPluginBase().getExtensions();
685         
686         ArrayList JavaDoc csExtensions = new ArrayList JavaDoc();
687         for (int i = 0; i < extensions.length; i++) {
688             String JavaDoc point = extensions[i].getPoint();
689             if (extensionPointID.equals(point)) {
690                 csExtensions.add(extensions[i]);
691             }
692         }
693         return (IPluginExtension[]) csExtensions.toArray(
694                 new IPluginExtension[csExtensions.size()]);
695     }
696     
697     /**
698      * @return
699      */

700     private String JavaDoc generateCheatSheetID() {
701         // Generate the hash code using the full path
702
long uniqueID = hash(fCheatSheetModel.getUnderlyingResource().getFullPath().toPortableString());
703         // Qualify with the project name
704
// Append the hash code to make the name unique and allow cheat sheets
705
// with the same name (but different directories) be registered
706
// individually
707
String JavaDoc result = fPluginProject.getName() +
708                         '.' +
709                         F_CS_ELEMENT_CHEATSHEET +
710                         uniqueID;
711         return result;
712     }
713     
714     /**
715      * @return
716      */

717     private String JavaDoc generateCategoryID(String JavaDoc name) {
718         // Generate the hash code using the category name
719
long uniqueID = hash(name);
720         // Qualify with the project name
721
// Append the hash code to make the name unique
722
String JavaDoc result = fPluginProject.getName() +
723                         '.' +
724                         F_CS_ELEMENT_CATEGORY +
725                         uniqueID;
726         return result;
727     }
728     
729     /**
730      * @param string
731      * @return
732      */

733     private long hash(String JavaDoc string) {
734         int b = 378551;
735         int a = 63689;
736         long hash = 0;
737
738         for(int i = 0; i < string.length(); i++) {
739             hash = hash * a + string.charAt(i);
740             a = a * b;
741         }
742         return (hash & 0x7FFFFFFF);
743     }
744     
745 }
746
Popular Tags