2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.eclipse.org/org/documents/epl-v10.php
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.
17 package com.android.ide.eclipse.adt.internal.editors.layout.parts;
19 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiDocumentNode;
20 import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
22 import org.eclipse.gef.EditPart;
23 import org.eclipse.gef.EditPartFactory;
24 import org.eclipse.swt.widgets.Display;
27 * A factory that returns the appropriate {@link EditPart} for a given model object.
29 * The only model objects we use are {@link UiElementNode} objects and they are
30 * edited using {@link UiElementEditPart}.
34 public class UiElementsEditPartFactory implements EditPartFactory {
36 private Display mDisplay;
37 private boolean mShowOutline = false;
38 private IOutlineProvider mProvider;
40 public interface IOutlineProvider {
44 public UiElementsEditPartFactory(Display display, IOutlineProvider provider) {
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;
55 if (node.getDescriptor().hasChildren()) {
56 return new UiLayoutEditPart(node, mProvider);
59 return new UiViewEditPart(node);
64 public void setShowOutline(boolean showOutline) {
65 mShowOutline = showOutline;