001: /*******************************************************************************
002: * Copyright (c) 2005, 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.layout;
011:
012: /**
013: * Manages the internal piece of trim for each trim area.
014: *
015: * @since 3.2
016: */
017: public class TrimDescriptor {
018:
019: /**
020: * The window trim object.
021: */
022: private IWindowTrim fTrim;
023:
024: /**
025: * The cache for the window trim object's control.
026: */
027: private SizeCache fCache;
028:
029: /**
030: * The cache for the common drag affordance, if available.
031: */
032: private SizeCache fDockingHandle = null;
033:
034: /**
035: * The current area that we belong to.
036: *
037: * @see TrimLayout#getAreaIds()
038: */
039: private int fAreaId;
040:
041: /**
042: * Create a trim descriptor for the trim manager.
043: *
044: * @param trim
045: * the window trim
046: * @param areaId
047: * the trim area we belong to.
048: */
049: public TrimDescriptor(IWindowTrim trim, int areaId) {
050: fTrim = trim;
051: fAreaId = areaId;
052: }
053:
054: /**
055: * @return Returns the fCache.
056: */
057: public SizeCache getCache() {
058: return fCache;
059: }
060:
061: /**
062: * Set the trim cache. Because of the requirements of possibly changing
063: * orientation when docking on a different side, the same IWindowTrim
064: * sometimes needs to have it's control SizeCache replaced.
065: *
066: * @param c
067: * cache.
068: */
069: public void setCache(SizeCache c) {
070: fCache = c;
071: }
072:
073: /**
074: * @return Returns the fTrim.
075: */
076: public IWindowTrim getTrim() {
077: return fTrim;
078: }
079:
080: /**
081: * Return the cache for the common drag affordance.
082: *
083: * @return return the docking handle cache
084: */
085: public SizeCache getDockingCache() {
086: return fDockingHandle;
087: }
088:
089: /**
090: * The trim ID.
091: *
092: * @return the trim ID. This should not be <code>null</code>.
093: */
094: public String getId() {
095: return fTrim.getId();
096: }
097:
098: /**
099: * Returns whether the control for this trim is visible.
100: *
101: * @return <code>true</code> if the control is visible.
102: */
103: public boolean isVisible() {
104: if (!fTrim.getControl().isDisposed()) {
105: return fTrim.getControl().isVisible();
106: }
107: return false;
108: }
109:
110: /**
111: * Set the cache for the common drag affordance.
112: *
113: * @param cache
114: * the sizecache for the docking control
115: */
116: public void setDockingCache(SizeCache cache) {
117: fDockingHandle = cache;
118: }
119:
120: /**
121: * The area ID this descriptor belongs to.
122: *
123: * @return the ID
124: * @see TrimLayout#getAreaIds()
125: */
126: public int getAreaId() {
127: return fAreaId;
128: }
129:
130: /**
131: * Set the current area this descriptor belongs to.
132: *
133: * @param id
134: * the area ID.
135: * @see TrimLayout#getAreaIds()
136: */
137: public void setAreaId(int id) {
138: fAreaId = id;
139: }
140:
141: /**
142: * Flush any contained size caches.
143: */
144: public void flush() {
145: if (fCache != null) {
146: fCache.flush();
147: }
148: if (fDockingHandle != null) {
149: fDockingHandle.flush();
150: }
151: }
152:
153: /**
154: * Update the visibility of the trim controls.
155: *
156: * @param visible
157: * visible or not.
158: */
159: public void setVisible(boolean visible) {
160: if (fTrim.getControl() != null
161: && !fTrim.getControl().isDisposed()) {
162: fTrim.getControl().setVisible(visible);
163: }
164: if (fDockingHandle != null
165: && fDockingHandle.getControl() != null
166: && !fDockingHandle.getControl().isDisposed()) {
167: fDockingHandle.getControl().setVisible(visible);
168: }
169: }
170: }
|