001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 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.examples.propertysheet;
011:
012: import java.util.Vector;
013:
014: import org.eclipse.swt.graphics.RGB;
015:
016: /**
017: * A Group Element
018: */
019: public class GroupElement extends OrganizationElement {
020: public static String P_USERS = "users"; //$NON-NLS-1$
021:
022: public static String P_SUBGROUPS = "subgroups"; //$NON-NLS-1$
023:
024: public static String P_CONTENTS = "contents"; //$NON-NLS-1$
025:
026: private Vector subGroups;
027:
028: private Vector users;
029:
030: // must be synchronized to contain both the references of subGroups and users
031: private Vector contents;
032:
033: /**
034: * Constructor.
035: * Creates a new GroupElement within the passed parent GroupElement,
036: * gives it the passed name property, sets Icon.
037: *
038: * @param name the name
039: * @param parent the parent
040: */
041: public GroupElement(String name, GroupElement parent) {
042: super (name, parent);
043: }
044:
045: /**
046: * Adds an OrganizationElement to this GroupElement.
047: *
048: * @param userGroup The Organization Element
049: */
050: public void add(OrganizationElement userGroup) {
051: if (userGroup.isUser() || userGroup.isGroup()) {
052: getContents().add(userGroup);
053: }
054: if (userGroup.isGroup()) {
055: getSubGroups().add(userGroup);
056: // synchronizes backpointer of userGroup: defensive
057: userGroup.setParent(this );
058: }
059: if (userGroup.isUser()) {
060: getUsers().add(userGroup);
061: // synchronizes backpointer of userGroup: defensive
062: userGroup.setParent(this );
063: }
064:
065: }
066:
067: /**
068: * Creates a new <code>GroupElement</code>
069: * nested in this <code>GroupElement<code>
070: *
071: * @param name the name of the sub group
072: */
073: public GroupElement createSubGroup(String name) {
074: GroupElement newGroup = new GroupElement(name, this );
075: add(newGroup);
076: return newGroup;
077: }
078:
079: /**
080: * Creates a new <code>UserElement</code>
081: *
082: * @param the name of the user element
083: */
084: public UserElement createUser(String name) {
085: UserElement newUser = new UserElement(name, this );
086: add(newUser);
087: return newUser;
088: }
089:
090: /**
091: * Deletes an OrganizationElement from this GroupElement.
092: *
093: * @param userGroup the Organization Element
094: */
095: public void delete(OrganizationElement userGroup) {
096: if (userGroup.isUser() || userGroup.isGroup()) {
097: getContents().remove(userGroup);
098: }
099: if (userGroup.isGroup()) {
100: getSubGroups().remove(userGroup);
101: // synchronizes backpointer of userGroup: defensive
102: }
103: if (userGroup.isUser()) {
104: getUsers().remove(userGroup);
105: // synchronizes backpointer of userGroup: defensive
106: }
107: }
108:
109: /* (non-Javadoc)
110: * Method declared on IWorkbenchAdapter
111: */
112: public Object[] getChildren(Object o) {
113: return getContents().toArray();
114: }
115:
116: /**
117: * Returns the content
118: */
119: private Vector getContents() {
120: if (contents == null)
121: contents = new Vector();
122: return contents;
123: }
124:
125: /* (non-Javadoc)
126: * Method declared on IPropertySource
127: */
128: public Object getEditableValue() {
129: return this .toString();
130: }
131:
132: /**
133: * Returns the error message
134: */
135: public String getErrorMessage() {
136: return null;
137: }
138:
139: /**
140: * Returns the subgroups
141: */
142: private Vector getSubGroups() {
143: if (subGroups == null)
144: subGroups = new Vector();
145: return subGroups;
146: }
147:
148: /**
149: * Returns the users
150: */
151: private Vector getUsers() {
152: if (users == null)
153: users = new Vector();
154: return users;
155: }
156:
157: /* (non-Javadoc)
158: * Method declared on OrganizationElement
159: */
160: public boolean isGroup() {
161: return true;
162: }
163:
164: /* (non-Javadoc)
165: * @see org.eclipse.ui.model.IWorkbenchAdapter#getForeground(java.lang.Object)
166: */
167: public RGB getForeground(Object element) {
168: return null;
169: }
170:
171: /* (non-Javadoc)
172: * @see org.eclipse.ui.model.IWorkbenchAdapter#getBackground(java.lang.Object)
173: */
174: public RGB getBackground(Object element) {
175: return null;
176: }
177: }
|