1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.eclipse.org/org/documents/epl-v10.php 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.ide.eclipse.adt.internal.editors.layout.parts; 18 19 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiDocumentNode; 20 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; 21 22 import org.eclipse.gef.EditPart; 23 import org.eclipse.gef.EditPartFactory; 24 import org.eclipse.swt.widgets.Display; 25 26 /** 27 * A factory that returns the appropriate {@link EditPart} for a given model object. 28 * <p/> 29 * The only model objects we use are {@link UiElementNode} objects and they are 30 * edited using {@link UiElementEditPart}. 31 * 32 * @since GLE1 33 */ 34 public class UiElementsEditPartFactory implements EditPartFactory { 35 36 private Display mDisplay; 37 private boolean mShowOutline = false; 38 private IOutlineProvider mProvider; 39 40 public interface IOutlineProvider { 41 boolean hasOutline(); 42 } 43 44 public UiElementsEditPartFactory(Display display, IOutlineProvider provider) { 45 mDisplay = display; 46 mProvider = provider; 47 } 48 49 public EditPart createEditPart(EditPart context, Object model) { 50 if (model instanceof UiDocumentNode) { 51 return new UiDocumentEditPart((UiDocumentNode) model, mDisplay); 52 } else if (model instanceof UiElementNode) { 53 UiElementNode node = (UiElementNode) model; 54 55 if (node.getDescriptor().hasChildren()) { 56 return new UiLayoutEditPart(node, mProvider); 57 } 58 59 return new UiViewEditPart(node); 60 } 61 return null; 62 } 63 64 public void setShowOutline(boolean showOutline) { 65 mShowOutline = showOutline; 66 } 67 68 } 69