001: /*******************************************************************************
002: * Copyright (c) 2004, 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.internal.registry;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.core.runtime.IConfigurationElement;
014: import org.eclipse.core.runtime.IStatus;
015: import org.eclipse.core.runtime.Status;
016: import org.eclipse.ui.IPageLayout;
017: import org.eclipse.ui.views.IStickyViewDescriptor;
018:
019: /**
020: * @since 3.0
021: */
022: public class StickyViewDescriptor implements IStickyViewDescriptor {
023:
024: private IConfigurationElement configurationElement;
025:
026: private String id;
027:
028: /**
029: * Folder constant for right sticky views.
030: */
031: public static final String STICKY_FOLDER_RIGHT = "stickyFolderRight"; //$NON-NLS-1$
032:
033: /**
034: * Folder constant for left sticky views.
035: */
036: public static final String STICKY_FOLDER_LEFT = "stickyFolderLeft"; //$NON-NLS-1$
037:
038: /**
039: * Folder constant for top sticky views.
040: */
041: public static final String STICKY_FOLDER_TOP = "stickyFolderTop"; //$NON-NLS-1$
042:
043: /**
044: * Folder constant for bottom sticky views.
045: */
046: public static final String STICKY_FOLDER_BOTTOM = "stickyFolderBottom"; //$NON-NLS-1$
047:
048: /**
049: * @param element
050: * @throws CoreException
051: */
052: public StickyViewDescriptor(IConfigurationElement element)
053: throws CoreException {
054: this .configurationElement = element;
055: id = configurationElement
056: .getAttribute(IWorkbenchRegistryConstants.ATT_ID);
057: if (id == null) {
058: throw new CoreException(new Status(IStatus.ERROR, element
059: .getNamespace(), 0,
060: "Invalid extension (missing id) ", null));//$NON-NLS-1$
061: }
062: }
063:
064: /**
065: * Return the configuration element.
066: *
067: * @return the configuration element
068: */
069: public IConfigurationElement getConfigurationElement() {
070: return configurationElement;
071: }
072:
073: /* (non-Javadoc)
074: * @see org.eclipse.ui.views.IStickyViewDescriptor#getLocation()
075: */
076: public int getLocation() {
077: int direction = IPageLayout.RIGHT;
078:
079: String location = configurationElement
080: .getAttribute(IWorkbenchRegistryConstants.ATT_LOCATION);
081: if (location != null) {
082: if (location.equalsIgnoreCase("left")) { //$NON-NLS-1$
083: direction = IPageLayout.LEFT;
084: } else if (location.equalsIgnoreCase("top")) { //$NON-NLS-1$
085: direction = IPageLayout.TOP;
086: } else if (location.equalsIgnoreCase("bottom")) { //$NON-NLS-1$
087: direction = IPageLayout.BOTTOM;
088: //no else for right - it is the default value;
089: }
090: }
091: return direction;
092: }
093:
094: /* (non-Javadoc)
095: * @see org.eclipse.ui.internal.registry.IStickyViewDescriptor#getId()
096: */
097: public String getId() {
098: return id;
099: }
100:
101: /* (non-Javadoc)
102: * @see org.eclipse.ui.internal.registry.IStickyViewDescriptor#isFixed()
103: */
104: public boolean isCloseable() {
105: boolean closeable = true;
106: String closeableString = configurationElement
107: .getAttribute(IWorkbenchRegistryConstants.ATT_CLOSEABLE);
108: if (closeableString != null) {
109: closeable = !closeableString.equals("false"); //$NON-NLS-1$
110: }
111: return closeable;
112: }
113:
114: /* (non-Javadoc)
115: * @see org.eclipse.ui.internal.registry.IStickyViewDescriptor#isMoveable()
116: */
117: public boolean isMoveable() {
118: boolean moveable = true;
119: String moveableString = configurationElement
120: .getAttribute(IWorkbenchRegistryConstants.ATT_MOVEABLE);
121: if (moveableString != null) {
122: moveable = !moveableString.equals("false"); //$NON-NLS-1$
123: }
124: return moveable;
125: }
126: }
|