KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > registry > ActionSetPartAssociationsReader


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

11 package org.eclipse.ui.internal.registry;
12
13 import org.eclipse.core.runtime.IConfigurationElement;
14 import org.eclipse.core.runtime.IExtensionRegistry;
15 import org.eclipse.ui.PlatformUI;
16 import org.eclipse.ui.internal.IWorkbenchConstants;
17 import org.eclipse.ui.internal.WorkbenchPlugin;
18
19 /**
20  * A strategy to read action set part association extension from the registry.
21  */

22 public class ActionSetPartAssociationsReader extends RegistryReader {
23     private ActionSetRegistry registry;
24     private static final String JavaDoc TAG_EXTENSION="actionSetPartAssociation";//$NON-NLS-1$
25
private static final String JavaDoc TAG_PART="part";//$NON-NLS-1$
26
private static final String JavaDoc ATT_ID="id";//$NON-NLS-1$
27
private static final String JavaDoc ATT_TARGET_ID="targetID";//$NON-NLS-1$
28

29 /**
30  * Creates a new reader.
31  */

32 public ActionSetPartAssociationsReader() {
33     super();
34 }
35 //for dynamic UI
36
public ActionSetPartAssociationsReader(ActionSetRegistry registry) {
37     this.registry = registry;
38 }
39
40 /**
41  * Process an extension.
42  */

43 private boolean processExtension(IConfigurationElement element) {
44     String JavaDoc actionSetId = element.getAttribute(ATT_TARGET_ID);
45     IConfigurationElement [] children = element.getChildren();
46     for (int i = 0; i < children.length; i++) {
47         IConfigurationElement child = children[i];
48         String JavaDoc type = child.getName();
49         if (type.equals(TAG_PART)) {
50             String JavaDoc partId = child.getAttribute(ATT_ID);
51             if (partId != null)
52                 registry.addAssociation(actionSetId, partId);
53         } else {
54             WorkbenchPlugin.log("Unable to process element: " +//$NON-NLS-1$
55
type +
56                 " in action set part associations extension: " +//$NON-NLS-1$
57
element.getDeclaringExtension().getUniqueIdentifier());
58         }
59     }
60     return true;
61 }
62
63 /**
64  * Reads the given element.
65  */

66 //for dynamic UI - change access from protected to public
67
public boolean readElement(IConfigurationElement element) {
68     String JavaDoc type = element.getName();
69     if (type.equals(TAG_EXTENSION)) {
70         return processExtension(element);
71     }
72     return false;
73 }
74
75 /**
76  * Read the association extensions within a registry.
77  */

78 public void readRegistry(IExtensionRegistry in, ActionSetRegistry out)
79 {
80     registry = out;
81     readRegistry(in, PlatformUI.PLUGIN_ID, IWorkbenchConstants.PL_ACTION_SET_PART_ASSOCIATIONS);
82 }
83 }
84
Popular Tags