/*******************************************************************************
* Copyright 2011 Google Inc. All Rights Reserved.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package com.google.gdt.eclipse.designer.gxt.model.layout;
import com.google.gdt.eclipse.designer.gxt.model.layout.assistant.BorderLayoutAssistant;
import com.google.gdt.eclipse.designer.model.widgets.WidgetInfo;
import org.eclipse.wb.core.model.ObjectInfo;
import org.eclipse.wb.core.model.broadcast.ObjectInfoPresentationDecorateText;
import org.eclipse.wb.internal.core.model.creation.CreationSupport;
import org.eclipse.wb.internal.core.model.description.ComponentDescription;
import org.eclipse.wb.internal.core.utils.ast.AstEditor;
import java.util.List;
/**
* Model for <code>BorderLayout</code>.
*
* @author scheglov_ke
* @coverage ExtGWT.model.layout
*/
public final class BorderLayoutInfo extends LayoutInfo {
////////////////////////////////////////////////////////////////////////////
//
// Constructor
//
////////////////////////////////////////////////////////////////////////////
public BorderLayoutInfo(AstEditor editor,
ComponentDescription description,
CreationSupport creationSupport) throws Exception {
super(editor, description, creationSupport);
decorateWidgetText_withRegionName();
}
////////////////////////////////////////////////////////////////////////////
//
// Initialize
//
////////////////////////////////////////////////////////////////////////////
@Override
protected void initializeLayoutAssistant() {
new BorderLayoutAssistant(this);
}
////////////////////////////////////////////////////////////////////////////
//
// Events
//
////////////////////////////////////////////////////////////////////////////
private void decorateWidgetText_withRegionName() {
addBroadcastListener(new ObjectInfoPresentationDecorateText() {
public void invoke(ObjectInfo object, String[] text) throws Exception {
if (isManagedObject(object)) {
WidgetInfo widget = (WidgetInfo) object;
BorderLayoutDataInfo borderData = getBorderData(widget);
String region = borderData.getRegion();
if (region != null) {
text[0] = region + " - " + text[0];
}
}
}
});
}
////////////////////////////////////////////////////////////////////////////
//
// LayoutData
//
////////////////////////////////////////////////////////////////////////////
/**
* @return {@link BorderLayoutDataInfo} associated with given {@link WidgetInfo}.
*/
public static BorderLayoutDataInfo getBorderData(WidgetInfo widget) {
return (BorderLayoutDataInfo) getLayoutData(widget);
}
////////////////////////////////////////////////////////////////////////////
//
// Commands
//
////////////////////////////////////////////////////////////////////////////
/**
* @return the {@link WidgetInfo} in given region, may be <code>null</code>.
*/
public WidgetInfo getWidget(String region) {
List<WidgetInfo> widgets = getWidgets();
for (WidgetInfo widget : widgets) {
String widgetRegion = getBorderData(widget).getRegion();
if (region.equals(widgetRegion)) {
return widget;
}
}
return null;
}
}