From 681a754db644b092b1d6203d9cf74b01c9b3a629 Mon Sep 17 00:00:00 2001 From: Raphael Moll Date: Mon, 13 Sep 2010 16:02:27 -0700 Subject: ADT: remove GLE1. Change-Id: I80dbd00988748842b940312f4d8136e7b9187500 --- .../META-INF/MANIFEST.MF | 2 - .../editors/layout/IGraphicalLayoutEditor.java | 10 - .../adt/internal/editors/layout/LayoutEditor.java | 96 +- .../editors/layout/gle1/GraphicalLayoutEditor.java | 1458 -------------------- .../editors/layout/gle1/PaletteFactory.java | 95 -- .../editors/layout/gle1/UiContentOutlinePage.java | 618 --------- .../editors/layout/gle1/UiPropertySheetPage.java | 141 -- .../editors/layout/gle2/GraphicalEditorPart.java | 23 - .../editors/layout/parts/DropFeedback.java | 778 ----------- .../editors/layout/parts/ElementCreateCommand.java | 100 -- .../editors/layout/parts/ElementFigure.java | 81 -- .../editors/layout/parts/LayoutFigure.java | 154 --- .../editors/layout/parts/UiDocumentEditPart.java | 214 --- .../layout/parts/UiDocumentTreeEditPart.java | 39 - .../editors/layout/parts/UiElementEditPart.java | 347 ----- .../layout/parts/UiElementTreeEditPart.java | 76 - .../layout/parts/UiElementTreeEditPartFactory.java | 49 - .../layout/parts/UiElementsEditPartFactory.java | 68 - .../editors/layout/parts/UiLayoutEditPart.java | 120 -- .../editors/layout/parts/UiLayoutTreeEditPart.java | 41 - .../editors/layout/parts/UiViewEditPart.java | 57 - .../editors/layout/parts/UiViewTreeEditPart.java | 32 - 22 files changed, 8 insertions(+), 4591 deletions(-) delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle1/GraphicalLayoutEditor.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle1/PaletteFactory.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle1/UiContentOutlinePage.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle1/UiPropertySheetPage.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/DropFeedback.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/ElementCreateCommand.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/ElementFigure.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/LayoutFigure.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiDocumentEditPart.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiDocumentTreeEditPart.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiElementEditPart.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiElementTreeEditPart.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiElementTreeEditPartFactory.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiElementsEditPartFactory.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiLayoutEditPart.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiLayoutTreeEditPart.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiViewEditPart.java delete mode 100644 eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiViewTreeEditPart.java (limited to 'eclipse/plugins') diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/META-INF/MANIFEST.MF b/eclipse/plugins/com.android.ide.eclipse.adt/META-INF/MANIFEST.MF index 38ef706..93b0871 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/META-INF/MANIFEST.MF +++ b/eclipse/plugins/com.android.ide.eclipse.adt/META-INF/MANIFEST.MF @@ -58,10 +58,8 @@ Export-Package: com.android.ide.eclipse.adt;x-friends:="com.android.ide.eclipse. com.android.ide.eclipse.adt.internal.editors.layout;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.adt.internal.editors.layout.configuration;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.adt.internal.editors.layout.descriptors;x-friends:="com.android.ide.eclipse.tests", - com.android.ide.eclipse.adt.internal.editors.layout.gle1;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.adt.internal.editors.layout.gle2;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.adt.internal.editors.layout.gre;x-friends:="com.android.ide.eclipse.tests", - com.android.ide.eclipse.adt.internal.editors.layout.parts;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.adt.internal.editors.layout.uimodel;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.adt.internal.editors.manifest;x-friends:="com.android.ide.eclipse.tests", com.android.ide.eclipse.adt.internal.editors.manifest.descriptors;x-friends:="com.android.ide.eclipse.tests", diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/IGraphicalLayoutEditor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/IGraphicalLayoutEditor.java index 3a8e454..c8fd5c8 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/IGraphicalLayoutEditor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/IGraphicalLayoutEditor.java @@ -16,9 +16,7 @@ package com.android.ide.eclipse.adt.internal.editors.layout; -import com.android.ide.eclipse.adt.internal.editors.layout.parts.ElementCreateCommand; import com.android.ide.eclipse.adt.internal.editors.uimodel.UiDocumentNode; -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; import org.eclipse.core.resources.IFile; import org.eclipse.gef.ui.parts.SelectionSynchronizer; @@ -76,14 +74,6 @@ public interface IGraphicalLayoutEditor extends IEditorPart { abstract void deactivated(); /** - * Used by LayoutEditor.UiEditorActions.selectUiNode to select a new UI Node - * created by {@link ElementCreateCommand#execute()}. - * - * @param uiNodeModel The {@link UiElementNode} to select. - */ - abstract void selectModel(UiElementNode uiNodeModel); - - /** * Returns the selection synchronizer object. * The synchronizer can be used to sync the selection of 2 or more EditPartViewers. */ diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditor.java index 0195105..8560fa8 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditor.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/LayoutEditor.java @@ -25,15 +25,10 @@ import com.android.ide.eclipse.adt.internal.editors.descriptors.IUnknownDescript import com.android.ide.eclipse.adt.internal.editors.layout.descriptors.CustomViewDescriptorService; import com.android.ide.eclipse.adt.internal.editors.layout.descriptors.LayoutDescriptors; import com.android.ide.eclipse.adt.internal.editors.layout.descriptors.ViewElementDescriptor; -import com.android.ide.eclipse.adt.internal.editors.layout.gle1.GraphicalLayoutEditor; -import com.android.ide.eclipse.adt.internal.editors.layout.gle1.UiContentOutlinePage; -import com.android.ide.eclipse.adt.internal.editors.layout.gle1.UiPropertySheetPage; import com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart; import com.android.ide.eclipse.adt.internal.editors.layout.gle2.OutlinePage2; import com.android.ide.eclipse.adt.internal.editors.layout.gle2.PropertySheetPage2; -import com.android.ide.eclipse.adt.internal.editors.ui.tree.UiActions; import com.android.ide.eclipse.adt.internal.editors.uimodel.UiDocumentNode; -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData; import com.android.ide.eclipse.adt.internal.sdk.Sdk; import com.android.sdklib.IAndroidTarget; @@ -43,7 +38,6 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.gef.ui.parts.TreeViewer; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IFileEditorInput; @@ -74,18 +68,11 @@ public class LayoutEditor extends AndroidXmlEditor implements IShowEditorInput, private IGraphicalLayoutEditor mGraphicalEditor; private int mGraphicalEditorIndex; - /** - * Implementation of the {@link IContentOutlinePage} for this editor. - * @deprecated Used for backward compatibility with GLE1. - */ - private UiContentOutlinePage mOutlineForGle1; /** Implementation of the {@link IContentOutlinePage} for this editor */ private IContentOutlinePage mOutline; /** Custom implementation of {@link IPropertySheetPage} for this editor */ private IPropertySheetPage mPropertyPage; - private UiEditorActions mUiEditorActions; - private final HashMap mUnknownDescriptorMap = new HashMap(); @@ -182,15 +169,8 @@ public class LayoutEditor extends AndroidXmlEditor implements IShowEditorInput, // the user, or through a configuration change in the configuration selector.) if (mGraphicalEditor == null) { - String useGle1 = System.getenv("USE_GLE1"); //$NON-NLS-1$ - - if (useGle1 != null && !useGle1.equals("0")) { //$NON-NLS-1$ - // If USE_GLE1 exists and is non-zero, use the old GLE v1 - mGraphicalEditor = new GraphicalLayoutEditor(this); - } else { - // Otherwise we now default to the new GLE v2 - mGraphicalEditor = new GraphicalEditorPart(this); - } + // Instantiate GLE v2 + mGraphicalEditor = new GraphicalEditorPart(this); mGraphicalEditorIndex = addPage(mGraphicalEditor, getEditorInput()); setPageText(mGraphicalEditorIndex, mGraphicalEditor.getTitle()); @@ -217,19 +197,11 @@ public class LayoutEditor extends AndroidXmlEditor implements IShowEditorInput, protected void postCreatePages() { super.postCreatePages(); - // This is called after the createFormPages() and createTextPage() methods have - // been called. Usually we select the first page (e.g. the GLE here) but right - // now we're going to temporarily select the last page (the XML text editor) if - // GLE1 is being used. That's because GLE1 is mostly useless and being deprecated. - // - // Note that this sets the default page. Eventually a default page might be + // Optional: set the default page. Eventually a default page might be // restored by selectDefaultPage() later based on the last page used by the user. - // - // TODO revert this once GLE2 becomes useful and is the default. - - if (mGraphicalEditor instanceof GraphicalLayoutEditor) { - setActivePage(getPageCount() - 1); - } + // For example, to make the last page the default one (rather than the first page), + // un-comment this line: + // setActivePage(getPageCount() - 1); } /* (non-java doc) @@ -281,11 +253,6 @@ public class LayoutEditor extends AndroidXmlEditor implements IShowEditorInput, // re-create or reload the pages with the default page shown as the previous active page. createAndroidPages(); selectDefaultPage(Integer.toString(currentPage)); - - // update the GLE1 outline. The GLE2 outline doesn't need this call anymore. - if (mOutlineForGle1 != null) { - mOutlineForGle1.reloadModel(); - } } /** @@ -306,11 +273,6 @@ public class LayoutEditor extends AndroidXmlEditor implements IShowEditorInput, if (mGraphicalEditor != null) { mGraphicalEditor.onXmlModelChanged(); } - - // update the GLE1 outline. The GLE2 outline doesn't need this call anymore. - if (mOutlineForGle1 != null) { - mOutlineForGle1.reloadModel(); - } } /** @@ -324,16 +286,7 @@ public class LayoutEditor extends AndroidXmlEditor implements IShowEditorInput, // gets stuck in the XML outline. if (IContentOutlinePage.class == adapter && mGraphicalEditor != null) { - if (mOutline == null && mGraphicalEditor instanceof GraphicalLayoutEditor) { - // Create the GLE1 outline. We need to keep a specific reference to it in order - // to call its reloadModel() method. The GLE2 outline no longer relies on this - // and can be casted to the base interface. - mOutlineForGle1 = new UiContentOutlinePage( - (GraphicalLayoutEditor) mGraphicalEditor, - new TreeViewer()); - mOutline = mOutlineForGle1; - - } else if (mOutline == null && mGraphicalEditor instanceof GraphicalEditorPart) { + if (mOutline == null && mGraphicalEditor instanceof GraphicalEditorPart) { mOutline = new OutlinePage2((GraphicalEditorPart) mGraphicalEditor); } @@ -341,10 +294,7 @@ public class LayoutEditor extends AndroidXmlEditor implements IShowEditorInput, } if (IPropertySheetPage.class == adapter && mGraphicalEditor != null) { - if (mPropertyPage == null && mGraphicalEditor instanceof GraphicalLayoutEditor) { - mPropertyPage = new UiPropertySheetPage(); - - } else if (mPropertyPage == null && mGraphicalEditor instanceof GraphicalEditorPart) { + if (mPropertyPage == null && mGraphicalEditor instanceof GraphicalEditorPart) { mPropertyPage = new PropertySheetPage2(); } @@ -409,32 +359,6 @@ public class LayoutEditor extends AndroidXmlEditor implements IShowEditorInput, //EclipseUiHelper.showView(EclipseUiHelper.PROPERTY_SHEET_VIEW_ID, false /* activate */); } - public class UiEditorActions extends UiActions { - - @Override - protected UiDocumentNode getRootNode() { - return mUiRootNode; - } - - // Select the new item - @Override - protected void selectUiNode(UiElementNode uiNodeToSelect) { - mGraphicalEditor.selectModel(uiNodeToSelect); - } - - @Override - public void commitPendingXmlChanges() { - // Pass. There is nothing to commit before the XML is changed here. - } - } - - public UiEditorActions getUiEditorActions() { - if (mUiEditorActions == null) { - mUiEditorActions = new UiEditorActions(); - } - return mUiEditorActions; - } - // ---- Local Methods ---- /** @@ -570,10 +494,6 @@ public class LayoutEditor extends AndroidXmlEditor implements IShowEditorInput, mUiRootNode.reloadFromXmlNode(mUiRootNode.getXmlDocument()); } - if (mOutlineForGle1 != null) { - mOutlineForGle1.reloadModel(); - } - if (mGraphicalEditor != null) { mGraphicalEditor.onTargetChange(); mGraphicalEditor.reloadPalette(); diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle1/GraphicalLayoutEditor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle1/GraphicalLayoutEditor.java deleted file mode 100644 index 6dcf4bd..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle1/GraphicalLayoutEditor.java +++ /dev/null @@ -1,1458 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.adt.internal.editors.layout.gle1; - -import com.android.ide.eclipse.adt.AdtPlugin; -import com.android.ide.eclipse.adt.internal.editors.IconFactory; -import com.android.ide.eclipse.adt.internal.editors.layout.ExplodedRenderingHelper; -import com.android.ide.eclipse.adt.internal.editors.layout.IGraphicalLayoutEditor; -import com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor; -import com.android.ide.eclipse.adt.internal.editors.layout.LayoutReloadMonitor; -import com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback; -import com.android.ide.eclipse.adt.internal.editors.layout.UiElementPullParser; -import com.android.ide.eclipse.adt.internal.editors.layout.WidgetPullParser; -import com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor.UiEditorActions; -import com.android.ide.eclipse.adt.internal.editors.layout.LayoutReloadMonitor.ChangeFlags; -import com.android.ide.eclipse.adt.internal.editors.layout.LayoutReloadMonitor.ILayoutReloadListener; -import com.android.ide.eclipse.adt.internal.editors.layout.configuration.ConfigurationComposite; -import com.android.ide.eclipse.adt.internal.editors.layout.configuration.LayoutCreatorDialog; -import com.android.ide.eclipse.adt.internal.editors.layout.configuration.ConfigurationComposite.CustomButton; -import com.android.ide.eclipse.adt.internal.editors.layout.configuration.ConfigurationComposite.IConfigListener; -import com.android.ide.eclipse.adt.internal.editors.layout.descriptors.ViewElementDescriptor; -import com.android.ide.eclipse.adt.internal.editors.layout.parts.ElementCreateCommand; -import com.android.ide.eclipse.adt.internal.editors.layout.parts.UiElementEditPart; -import com.android.ide.eclipse.adt.internal.editors.layout.parts.UiElementsEditPartFactory; -import com.android.ide.eclipse.adt.internal.editors.layout.parts.UiElementsEditPartFactory.IOutlineProvider; -import com.android.ide.eclipse.adt.internal.editors.ui.tree.CopyCutAction; -import com.android.ide.eclipse.adt.internal.editors.ui.tree.PasteAction; -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiDocumentNode; -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; -import com.android.ide.eclipse.adt.internal.resources.configurations.FolderConfiguration; -import com.android.ide.eclipse.adt.internal.resources.manager.ProjectResources; -import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFile; -import com.android.ide.eclipse.adt.internal.resources.manager.ResourceFolderType; -import com.android.ide.eclipse.adt.internal.resources.manager.ResourceManager; -import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData; -import com.android.ide.eclipse.adt.internal.sdk.LoadStatus; -import com.android.ide.eclipse.adt.internal.sdk.Sdk; -import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData.LayoutBridge; -import com.android.ide.eclipse.adt.internal.sdk.Sdk.ITargetChangeListener; -import com.android.ide.eclipse.adt.io.IFileWrapper; -import com.android.layoutlib.api.ILayoutBridge; -import com.android.layoutlib.api.ILayoutLog; -import com.android.layoutlib.api.ILayoutResult; -import com.android.layoutlib.api.IProjectCallback; -import com.android.layoutlib.api.IResourceValue; -import com.android.layoutlib.api.IXmlPullParser; -import com.android.layoutlib.api.ILayoutResult.ILayoutViewInfo; -import com.android.sdklib.IAndroidTarget; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.gef.DefaultEditDomain; -import org.eclipse.gef.EditPart; -import org.eclipse.gef.EditPartViewer; -import org.eclipse.gef.GraphicalViewer; -import org.eclipse.gef.SelectionManager; -import org.eclipse.gef.dnd.TemplateTransferDragSourceListener; -import org.eclipse.gef.dnd.TemplateTransferDropTargetListener; -import org.eclipse.gef.editparts.ScalableFreeformRootEditPart; -import org.eclipse.gef.palette.PaletteRoot; -import org.eclipse.gef.requests.CreationFactory; -import org.eclipse.gef.ui.parts.GraphicalEditorWithPalette; -import org.eclipse.gef.ui.parts.SelectionSynchronizer; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.PaletteData; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.ide.IDE; -import org.eclipse.ui.part.FileEditorInput; - -import java.awt.image.BufferedImage; -import java.awt.image.DataBufferInt; -import java.awt.image.Raster; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Graphical layout editor, based on GEF. - *

- * To understand GEF: http://www.ibm.com/developerworks/opensource/library/os-gef/ - *

- * To understand Drag'n'drop: http://www.eclipse.org/articles/Article-Workbench-DND/drag_drop.html - * - * @since GLE1 - */ -public class GraphicalLayoutEditor extends GraphicalEditorWithPalette - implements IGraphicalLayoutEditor, IConfigListener, ILayoutReloadListener, IOutlineProvider { - - - /** Reference to the layout editor */ - private final LayoutEditor mLayoutEditor; - - /** reference to the file being edited. */ - private IFile mEditedFile; - - private Clipboard mClipboard; - private Composite mParent; - private ConfigurationComposite mConfigComposite; - - private PaletteRoot mPaletteRoot; - - private Map> mConfiguredFrameworkRes; - private Map> mConfiguredProjectRes; - private ProjectCallback mProjectCallback; - private ILayoutLog mLogger; - - private boolean mUseExplodeMode; - private boolean mUseOutlineMode; - private boolean mNeedsXmlReload = false; - private boolean mNeedsRecompute = false; - - /** Listener to update the root node if the target of the file is changed because of a - * SDK location change or a project target change */ - private ITargetChangeListener mTargetListener = new ITargetChangeListener() { - public void onProjectTargetChange(IProject changedProject) { - if (changedProject != null && changedProject.equals(getProject())) { - updateEditor(); - } - } - - public void onTargetLoaded(IAndroidTarget target) { - IProject project = getProject(); - if (target != null && target.equals(Sdk.getCurrent().getTarget(project))) { - updateEditor(); - } - } - - public void onSdkLoaded() { - Sdk currentSdk = Sdk.getCurrent(); - if (currentSdk != null) { - IAndroidTarget target = currentSdk.getTarget(mEditedFile.getProject()); - if (target != null) { - mConfigComposite.onSdkLoaded(target); - onConfigurationChange(); - } - } - } - - private void updateEditor() { - mLayoutEditor.commitPages(false /* onSave */); - - // because the target changed we must reset the configured resources. - mConfiguredFrameworkRes = mConfiguredProjectRes = null; - - // make sure we remove the custom view loader, since its parent class loader is the - // bridge class loader. - mProjectCallback = null; - - // recreate the ui root node always, this will also call onTargetChange - // on the config composite - mLayoutEditor.initUiRootNode(true /*force*/); - } - - private IProject getProject() { - return getLayoutEditor().getProject(); - } - }; - - private final Runnable mConditionalRecomputeRunnable = new Runnable() { - public void run() { - if (mLayoutEditor.isGraphicalEditorActive()) { - recomputeLayout(); - } else { - mNeedsRecompute = true; - } - } - }; - - private final Runnable mLocaleUpdaterFromUiRunnable = new Runnable() { - public void run() { - mConfigComposite.updateLocales(); - } - }; - - public GraphicalLayoutEditor(LayoutEditor layoutEditor) { - mLayoutEditor = layoutEditor; - setEditDomain(new DefaultEditDomain(this)); - setPartName("Layout"); - - AdtPlugin.getDefault().addTargetListener(mTargetListener); - } - - // ------------------------------------ - // Methods overridden from base classes - //------------------------------------ - - @Override - public void createPartControl(Composite parent) { - mParent = parent; - GridLayout gl; - - mClipboard = new Clipboard(parent.getDisplay()); - - parent.setLayout(gl = new GridLayout(1, false)); - gl.marginHeight = gl.marginWidth = 0; - - // create the top part for the configuration control - - CustomButton[][] customButtons = new CustomButton[][] { - new CustomButton[] { - new CustomButton( - null, //text - IconFactory.getInstance().getIcon("explode"), - "Displays extra margins in the layout.", - true /*toggle*/, - false /*defaultValue*/ - ) { - @Override - public void onSelected(boolean newState) { - mUseExplodeMode = newState; - recomputeLayout(); - } - }, - new CustomButton( - null, //text - IconFactory.getInstance().getIcon("outline"), - "Shows the outline of all views in the layout.", - true /*toggle*/, - false /*defaultValue*/ - ) { - @Override - public void onSelected(boolean newState) { - mUseOutlineMode = newState; - recomputeLayout(); - } - } - } - }; - - mConfigComposite = new ConfigurationComposite(this, customButtons, parent, SWT.NONE); - - // create a new composite that will contain the standard editor controls. - Composite editorParent = new Composite(parent, SWT.NONE); - editorParent.setLayoutData(new GridData(GridData.FILL_BOTH)); - editorParent.setLayout(new FillLayout()); - super.createPartControl(editorParent); - } - - @Override - public void dispose() { - if (mTargetListener != null) { - AdtPlugin.getDefault().removeTargetListener(mTargetListener); - mTargetListener = null; - } - - LayoutReloadMonitor.getMonitor().removeListener(mEditedFile.getProject(), this); - - if (mClipboard != null) { - mClipboard.dispose(); - mClipboard = null; - } - - super.dispose(); - } - - /** - * Returns the selection synchronizer object. - * The synchronizer can be used to sync the selection of 2 or more EditPartViewers. - *

- * This is changed from protected to public so that the outline can use it. - * - * @return the synchronizer - */ - @Override - public SelectionSynchronizer getSelectionSynchronizer() { - return super.getSelectionSynchronizer(); - } - - /** - * Returns the edit domain. - *

- * This is changed from protected to public so that the outline can use it. - * - * @return the edit domain - */ - @Override - public DefaultEditDomain getEditDomain() { - return super.getEditDomain(); - } - - /* (non-Javadoc) - * Creates the palette root. - */ - @Override - protected PaletteRoot getPaletteRoot() { - mPaletteRoot = PaletteFactory.createPaletteRoot(mPaletteRoot, - mLayoutEditor.getTargetData()); - return mPaletteRoot; - } - - public Clipboard getClipboard() { - return mClipboard; - } - - /** - * Save operation in the Graphical Layout Editor. - *

- * In our workflow, the model is owned by the Structured XML Editor. - * The graphical layout editor just displays it -- thus we don't really - * save anything here. - *

- * This must NOT call the parent editor part. At the contrary, the parent editor - * part will call this *after* having done the actual save operation. - *

- * The only action this editor must do is mark the undo command stack as - * being no longer dirty. - */ - @Override - public void doSave(IProgressMonitor monitor) { - getCommandStack().markSaveLocation(); - firePropertyChange(PROP_DIRTY); - } - - @Override - protected void configurePaletteViewer() { - super.configurePaletteViewer(); - - // Create a drag source listener on an edit part that is a viewer. - // What this does is use DND with a TemplateTransfer type which is actually - // the PaletteTemplateEntry held in the PaletteRoot. - TemplateTransferDragSourceListener dragSource = - new TemplateTransferDragSourceListener(getPaletteViewer()); - - // Create a drag source on the palette viewer. - // See the drag target associated with the GraphicalViewer in configureGraphicalViewer. - getPaletteViewer().addDragSourceListener(dragSource); - } - - /* (non-javadoc) - * Configure the graphical viewer before it receives its contents. - */ - @Override - protected void configureGraphicalViewer() { - super.configureGraphicalViewer(); - - GraphicalViewer viewer = getGraphicalViewer(); - viewer.setEditPartFactory(new UiElementsEditPartFactory(mParent.getDisplay(), this)); - viewer.setRootEditPart(new ScalableFreeformRootEditPart()); - - // Disable the following -- we don't drag *from* the GraphicalViewer yet: - // viewer.addDragSourceListener(new TemplateTransferDragSourceListener(viewer)); - - viewer.addDropTargetListener(new DropListener(viewer)); - } - - class DropListener extends TemplateTransferDropTargetListener { - public DropListener(EditPartViewer viewer) { - super(viewer); - } - - // TODO explain - @Override - protected CreationFactory getFactory(final Object template) { - return new CreationFactory() { - public Object getNewObject() { - // We don't know the newly created EditPart since "creating" new - // elements is done by ElementCreateCommand.execute() directly by - // manipulating the XML elements.. - return null; - } - - public Object getObjectType() { - return template; - } - - }; - } - } - - /* (non-javadoc) - * Set the contents of the GraphicalViewer after it has been created. - */ - @Override - protected void initializeGraphicalViewer() { - GraphicalViewer viewer = getGraphicalViewer(); - viewer.setContents(getModel()); - - IEditorInput input = getEditorInput(); - if (input instanceof FileEditorInput) { - FileEditorInput fileInput = (FileEditorInput)input; - mEditedFile = fileInput.getFile(); - - LayoutReloadMonitor.getMonitor().addListener(mEditedFile.getProject(), this); - } else { - // really this shouldn't happen! Log it in case it happens - mEditedFile = null; - AdtPlugin.log(IStatus.ERROR, "Input is not of type FileEditorInput: %1$s", - input.toString()); - } - } - - /* (non-javadoc) - * Sets the graphicalViewer for this EditorPart. - * @param viewer the graphical viewer - */ - @Override - protected void setGraphicalViewer(GraphicalViewer viewer) { - super.setGraphicalViewer(viewer); - - // TODO: viewer.setKeyHandler() - viewer.setContextMenu(createContextMenu(viewer)); - } - - /** - * Used by LayoutEditor.UiEditorActions.selectUiNode to select a new UI Node - * created by {@link ElementCreateCommand#execute()}. - * - * @param uiNodeModel The {@link UiElementNode} to select. - */ - public void selectModel(UiElementNode uiNodeModel) { - GraphicalViewer viewer = getGraphicalViewer(); - - // Give focus to the graphical viewer (in case the outline has it) - viewer.getControl().forceFocus(); - - Object editPart = viewer.getEditPartRegistry().get(uiNodeModel); - - if (editPart instanceof EditPart) { - viewer.select((EditPart)editPart); - } - } - - - //-------------- - // Local methods - //-------------- - - public LayoutEditor getLayoutEditor() { - return mLayoutEditor; - } - - private MenuManager createContextMenu(GraphicalViewer viewer) { - MenuManager menuManager = new MenuManager(); - menuManager.setRemoveAllWhenShown(true); - menuManager.addMenuListener(new ActionMenuListener(viewer)); - - return menuManager; - } - - private class ActionMenuListener implements IMenuListener { - private final GraphicalViewer mViewer; - - public ActionMenuListener(GraphicalViewer viewer) { - mViewer = viewer; - } - - /** - * The menu is about to be shown. The menu manager has already been - * requested to remove any existing menu item. This method gets the - * tree selection and if it is of the appropriate type it re-creates - * the necessary actions. - */ - public void menuAboutToShow(IMenuManager manager) { - ArrayList selected = new ArrayList(); - - // filter selected items and only keep those we can handle - for (Object obj : mViewer.getSelectedEditParts()) { - if (obj instanceof UiElementEditPart) { - UiElementEditPart part = (UiElementEditPart) obj; - UiElementNode uiNode = part.getUiNode(); - if (uiNode != null) { - selected.add(uiNode); - } - } - } - - if (selected.size() > 0) { - doCreateMenuAction(manager, mViewer, selected); - } - } - } - - private void doCreateMenuAction(IMenuManager manager, - final GraphicalViewer viewer, - final ArrayList selected) { - if (selected != null) { - boolean hasXml = false; - for (UiElementNode uiNode : selected) { - if (uiNode.getXmlNode() != null) { - hasXml = true; - break; - } - } - - if (hasXml) { - manager.add(new CopyCutAction(mLayoutEditor, getClipboard(), - null, selected, true /* cut */)); - manager.add(new CopyCutAction(mLayoutEditor, getClipboard(), - null, selected, false /* cut */)); - - // Can't paste with more than one element selected (the selection is the target) - if (selected.size() <= 1) { - // Paste is not valid if it would add a second element on a terminal element - // which parent is a document -- an XML document can only have one child. This - // means paste is valid if the current UI node can have children or if the - // parent is not a document. - UiElementNode ui_root = selected.get(0).getUiRoot(); - if (ui_root.getDescriptor().hasChildren() || - !(ui_root.getUiParent() instanceof UiDocumentNode)) { - manager.add(new PasteAction(mLayoutEditor, getClipboard(), - selected.get(0))); - } - } - manager.add(new Separator()); - } - } - - // Append "add" and "remove" actions. They do the same thing as the add/remove - // buttons on the side. - IconFactory factory = IconFactory.getInstance(); - - final UiEditorActions uiActions = mLayoutEditor.getUiEditorActions(); - - // "Add" makes sense only if there's 0 or 1 item selected since the - // one selected item becomes the target. - if (selected == null || selected.size() <= 1) { - manager.add(new Action("Add...", factory.getImageDescriptor("add")) { //$NON-NLS-2$ - @Override - public void run() { - UiElementNode node = selected != null && selected.size() > 0 ? selected.get(0) - : null; - uiActions.doAdd(node, viewer.getControl().getShell()); - } - }); - } - - if (selected != null) { - manager.add(new Action("Remove", factory.getImageDescriptor("delete")) { //$NON-NLS-2$ - @Override - public void run() { - uiActions.doRemove(selected, viewer.getControl().getShell()); - } - }); - - manager.add(new Separator()); - - manager.add(new Action("Up", factory.getImageDescriptor("up")) { //$NON-NLS-2$ - @Override - public void run() { - uiActions.doUp(selected); - } - }); - manager.add(new Action("Down", factory.getImageDescriptor("down")) { //$NON-NLS-2$ - @Override - public void run() { - uiActions.doDown(selected); - } - }); - } - - } - - /** - * Opens and initialize the editor with a new file. - * @param file the file being edited. - */ - public void openFile(IFile file) { - mEditedFile = file; - mConfigComposite.setFile(mEditedFile); - } - - /** - * Resets the editor with a replacement file. - * @param file the replacement file. - */ - public void replaceFile(IFile file) { - resetInput(); - - mEditedFile = file; - mConfigComposite.replaceFile(mEditedFile); - } - - /** - * Resets the editor with a replacement file coming from a config change in the config - * selector. - * @param file the replacement file. - */ - public void changeFileOnNewConfig(IFile file) { - resetInput(); - - mEditedFile = file; - mConfigComposite.changeFileOnNewConfig(mEditedFile); - } - - public void onTargetChange() { - resetInput(); - mConfigComposite.onXmlModelLoaded(); - onConfigurationChange(); - } - - public void onSdkChange() { - Sdk currentSdk = Sdk.getCurrent(); - if (currentSdk != null) { - IAndroidTarget target = currentSdk.getTarget(mEditedFile.getProject()); - if (target != null) { - mConfigComposite.onSdkLoaded(target); - onConfigurationChange(); - } - } - } - - /** - * Resets the editor's input and the viewer model. - */ - private void resetInput() { - GraphicalViewer viewer = getGraphicalViewer(); - viewer.setContents(getModel()); - - IEditorInput input = mLayoutEditor.getEditorInput(); - setInput(input); - } - - - public Rectangle getBounds() { - return mConfigComposite.getScreenBounds(); - } - - /** - * Renders an Android View described by a {@link ViewElementDescriptor}. - *

This uses the wrap_content mode for both layout_width and - * layout_height, and use the class name for the text attribute. - * @param descriptor the descriptor for the class to render. - * @return an ImageData containing the rendering or null if rendering failed. - */ - public ImageData renderWidget(ViewElementDescriptor descriptor) { - if (mEditedFile == null) { - return null; - } - - IAndroidTarget target = Sdk.getCurrent().getTarget(mEditedFile.getProject()); - if (target == null) { - return null; - } - - AndroidTargetData data = Sdk.getCurrent().getTargetData(target); - if (data == null) { - return null; - } - - LayoutBridge bridge = data.getLayoutBridge(); - - if (bridge.bridge != null) { // bridge can never be null. - ResourceManager resManager = ResourceManager.getInstance(); - - ProjectCallback projectCallback = null; - Map> configuredProjectResources = null; - if (mEditedFile != null) { - ProjectResources projectRes = resManager.getProjectResources( - mEditedFile.getProject()); - projectCallback = new ProjectCallback(bridge.classLoader, - projectRes, mEditedFile.getProject()); - - // get the configured resources for the project - // get the resources of the file's project. - if (mConfiguredProjectRes == null && projectRes != null) { - // make sure they are loaded - projectRes.loadAll(); - - // get the project resource values based on the current config - mConfiguredProjectRes = projectRes.getConfiguredResources( - mConfigComposite.getCurrentConfig()); - } - - configuredProjectResources = mConfiguredProjectRes; - } else { - // we absolutely need a Map of configured project resources. - configuredProjectResources = new HashMap>(); - } - - // get the framework resources - Map> frameworkResources = - getConfiguredFrameworkResources(); - - if (configuredProjectResources != null && frameworkResources != null) { - // get the selected theme - String theme = mConfigComposite.getTheme(); - if (theme != null) { - // Render a single object as described by the ViewElementDescriptor. - WidgetPullParser parser = new WidgetPullParser(descriptor); - ILayoutResult result = computeLayout(bridge, parser, - null /* projectKey */, - 1 /* width */, 1 /* height */, true /* renderFullSize */, - 160 /*density*/, 160.f /*xdpi*/, 160.f /*ydpi*/, theme, - mConfigComposite.isProjectTheme(), - configuredProjectResources, frameworkResources, projectCallback, - null /* logger */); - - // post rendering clean up - bridge.cleanUp(); - - // update the UiElementNode with the layout info. - if (result.getSuccess() == ILayoutResult.SUCCESS) { - BufferedImage largeImage = result.getImage(); - - // we need to resize it to the actual widget size, and convert it into - // an SWT image object. - int width = result.getRootView().getRight(); - int height = result.getRootView().getBottom(); - Raster raster = largeImage.getData(new java.awt.Rectangle(width, height)); - int[] imageDataBuffer = ((DataBufferInt)raster.getDataBuffer()).getData(); - - ImageData imageData = new ImageData(width, height, 32, - new PaletteData(0x00FF0000, 0x0000FF00, 0x000000FF)); - - imageData.setPixels(0, 0, imageDataBuffer.length, imageDataBuffer, 0); - - return imageData; - } - } - } - } - return null; - } - - /** - * Callback for XML model changed. Only update/recompute the layout if the editor is visible - */ - public void onXmlModelChanged() { - if (mLayoutEditor.isGraphicalEditorActive()) { - doXmlReload(true /* force */); - recomputeLayout(); - } else { - mNeedsXmlReload = true; - } - } - - /** - * Actually performs the XML reload - * @see #onXmlModelChanged() - */ - private void doXmlReload(boolean force) { - if (force || mNeedsXmlReload) { - GraphicalViewer viewer = getGraphicalViewer(); - - // try to preserve the selection before changing the content - SelectionManager selMan = viewer.getSelectionManager(); - ISelection selection = selMan.getSelection(); - - try { - viewer.setContents(getModel()); - } finally { - selMan.setSelection(selection); - } - - mNeedsXmlReload = false; - } - } - - public UiDocumentNode getModel() { - return mLayoutEditor.getUiRootNode(); - } - - public void reloadPalette() { - PaletteFactory.createPaletteRoot(mPaletteRoot, mLayoutEditor.getTargetData()); - } - - /** - * Looks for a file matching the new {@link FolderConfiguration} and attempts to open it. - *

If there is no match, notify the user. - */ - public void onConfigurationChange() { - mConfiguredFrameworkRes = mConfiguredProjectRes = null; - - if (mEditedFile == null || mConfigComposite.getEditedConfig() == null) { - return; - } - - // Before doing the normal process, test for the following case. - // - the editor is being opened (or reset for a new input) - // - the file being opened is not the best match for any possible configuration - // - another random compatible config was chosen in the config composite. - // The result is that match will not be the file being edited, but because this is not - // due to a config change, we should not trigger opening the actual best match (also, - // because the editor is still opening the MatchingStrategy woudln't answer true - // and the best match file would open in a different editor). - // So the solution is that if the editor is being created, we just call recomputeLayout - // without looking for a better matching layout file. - if (mLayoutEditor.isCreatingPages()) { - recomputeLayout(); - } else { - // get the resources of the file's project. - ProjectResources resources = ResourceManager.getInstance().getProjectResources( - mEditedFile.getProject()); - - // from the resources, look for a matching file - ResourceFile match = null; - if (resources != null) { - match = resources.getMatchingFile(mEditedFile.getName(), - ResourceFolderType.LAYOUT, - mConfigComposite.getCurrentConfig()); - } - - if (match != null) { - // since this is coming from Eclipse, this is always an instance of IFileWrapper - IFileWrapper iFileWrapper = (IFileWrapper) match.getFile(); - IFile iFile = iFileWrapper.getIFile(); - if (iFile.equals(mEditedFile) == false) { - try { - // tell the editor that the next replacement file is due to a config change. - mLayoutEditor.setNewFileOnConfigChange(true); - - // ask the IDE to open the replacement file. - IDE.openEditor(getSite().getWorkbenchWindow().getActivePage(), iFile); - - // we're done! - return; - } catch (PartInitException e) { - // FIXME: do something! - } - } - - // at this point, we have not opened a new file. - - // Store the state in the current file - mConfigComposite.storeState(); - - // Even though the layout doesn't change, the config changed, and referenced - // resources need to be updated. - recomputeLayout(); - } else { - // display the error. - FolderConfiguration currentConfig = mConfigComposite.getCurrentConfig(); - String message = String.format( - "No resources match the configuration\n \n\t%1$s\n \nChange the configuration or create:\n \n\tres/%2$s/%3$s\n \nYou can also click the 'Create' button above.", - currentConfig.toDisplayString(), - currentConfig.getFolderName(ResourceFolderType.LAYOUT), - mEditedFile.getName()); - showErrorInEditor(message); - } - } - } - - public void onThemeChange() { - // Store the state in the current file - mConfigComposite.storeState(); - - recomputeLayout(); - } - - public void onCreate() { - LayoutCreatorDialog dialog = new LayoutCreatorDialog(mParent.getShell(), - mEditedFile.getName(), mConfigComposite.getCurrentConfig()); - if (dialog.open() == Dialog.OK) { - final FolderConfiguration config = new FolderConfiguration(); - dialog.getConfiguration(config); - - createAlternateLayout(config); - } - } - - /** - * Recomputes the layout with the help of layoutlib. - */ - public void recomputeLayout() { - doXmlReload(false /* force */); - try { - // check that the resource exists. If the file is opened but the project is closed - // or deleted for some reason (changed from outside of eclipse), then this will - // return false; - if (mEditedFile.exists() == false) { - String message = String.format("Resource '%1$s' does not exist.", - mEditedFile.getFullPath().toString()); - - showErrorInEditor(message); - - return; - } - - IProject iProject = mEditedFile.getProject(); - - if (mEditedFile.isSynchronized(IResource.DEPTH_ZERO) == false) { - String message = String.format("%1$s is out of sync. Please refresh.", - mEditedFile.getName()); - - showErrorInEditor(message); - - // also print it in the error console. - AdtPlugin.printErrorToConsole(iProject.getName(), message); - return; - } - - Sdk currentSdk = Sdk.getCurrent(); - if (currentSdk != null) { - IAndroidTarget target = currentSdk.getTarget(mEditedFile.getProject()); - if (target == null) { - showErrorInEditor("The project target is not set."); - return; - } - - AndroidTargetData data = currentSdk.getTargetData(target); - if (data == null) { - // It can happen that the workspace refreshes while the target is loading its - // data, which could trigger a redraw of the opened layout if some resources - // changed while Eclipse is closed. - // In this case data could be null, but this is not an error. - // We can just silently return, as all the opened editors are automatically - // refreshed once the SDK finishes loading. - LoadStatus targetLoadStatus = currentSdk.checkAndLoadTargetData(target, null); - switch (targetLoadStatus) { - case LOADING: - showErrorInEditor(String.format( - "The project target (%1$s) is still loading.\n%2$s will refresh automatically once the process is finished.", - target.getName(), mEditedFile.getName())); - break; - case FAILED: // known failure - case LOADED: // success but data isn't loaded?!?! - showErrorInEditor(String.format( - "The project target (%s) was not properly loaded.", - target.getName())); - break; - } - return; - } - - // check there is actually a model (maybe the file is empty). - UiDocumentNode model = getModel(); - - if (model.getUiChildren().size() == 0) { - showErrorInEditor("No Xml content. Go to the Outline view and add nodes."); - return; - } - - LayoutBridge bridge = data.getLayoutBridge(); - - if (bridge.bridge != null) { // bridge can never be null. - ResourceManager resManager = ResourceManager.getInstance(); - - ProjectResources projectRes = resManager.getProjectResources(iProject); - if (projectRes == null) { - return; - } - - // get the resources of the file's project. - Map> configuredProjectRes = - getConfiguredProjectResources(); - - // get the framework resources - Map> frameworkResources = - getConfiguredFrameworkResources(); - - if (configuredProjectRes != null && frameworkResources != null) { - if (mProjectCallback == null) { - mProjectCallback = new ProjectCallback( - bridge.classLoader, projectRes, iProject); - } - - if (mLogger == null) { - mLogger = new ILayoutLog() { - public void error(String message) { - AdtPlugin.printErrorToConsole(mEditedFile.getName(), message); - } - - public void error(Throwable error) { - String message = error.getMessage(); - if (message == null) { - message = error.getClass().getName(); - } - - PrintStream ps = new PrintStream(AdtPlugin.getErrorStream()); - error.printStackTrace(ps); - } - - public void warning(String message) { - AdtPlugin.printToConsole(mEditedFile.getName(), message); - } - }; - } - - // get the selected theme - String theme = mConfigComposite.getTheme(); - if (theme != null) { - // Compute the layout - Rectangle rect = getBounds(); - - int width = rect.width; - int height = rect.height; - if (mUseExplodeMode) { - // compute how many padding in x and y will bump the screen size - List children = getModel().getUiChildren(); - if (children.size() == 1) { - ExplodedRenderingHelper helper = new ExplodedRenderingHelper( - children.get(0).getXmlNode(), iProject); - - // there are 2 paddings for each view - // left and right, or top and bottom. - int paddingValue = ExplodedRenderingHelper.PADDING_VALUE * 2; - - width += helper.getWidthPadding() * paddingValue; - height += helper.getHeightPadding() * paddingValue; - } - } - - int density = mConfigComposite.getDensity().getDpiValue(); - float xdpi = mConfigComposite.getXDpi(); - float ydpi = mConfigComposite.getYDpi(); - boolean isProjectTheme = mConfigComposite.isProjectTheme(); - - UiElementPullParser parser = new UiElementPullParser(getModel(), - mUseExplodeMode, density, xdpi, iProject); - - ILayoutResult result = computeLayout(bridge, parser, - iProject /* projectKey */, - width, height, false /*renderFullSize*/, - density, xdpi, ydpi, - theme, isProjectTheme, - configuredProjectRes, frameworkResources, mProjectCallback, - mLogger); - - // post-rendering clean up - bridge.cleanUp(); - - // update the UiElementNode with the layout info. - if (result.getSuccess() == ILayoutResult.SUCCESS) { - model.setEditData(result.getImage()); - - updateNodeWithBounds(result.getRootView()); - } else { - String message = result.getErrorMessage(); - - // Reset the edit data for all the nodes. - resetNodeBounds(model); - - if (message != null) { - // set the error in the top element. - model.setEditData(message); - } - } - - model.refreshUi(); - } - } - } else { - // SDK is loaded but not the layout library! - String message = null; - // check whether the bridge managed to load, or not - if (bridge.status == LoadStatus.LOADING) { - message = String.format( - "Eclipse is loading framework information and the Layout library from the SDK folder.\n%1$s will refresh automatically once the process is finished.", - mEditedFile.getName()); - } else { - message = String.format("Eclipse failed to load the framework information and the Layout library!"); - } - showErrorInEditor(message); - } - } else { - String message = String.format( - "Eclipse is loading the SDK.\n%1$s will refresh automatically once the process is finished.", - mEditedFile.getName()); - - showErrorInEditor(message); - } - } finally { - // no matter the result, we are done doing the recompute based on the latest - // resource/code change. - mNeedsRecompute = false; - } - } - - private void showErrorInEditor(String message) { - // get the model to display the error directly in the editor - UiDocumentNode model = getModel(); - - // Reset the edit data for all the nodes. - resetNodeBounds(model); - - if (message != null) { - // set the error in the top element. - model.setEditData(message); - } - - model.refreshUi(); - } - - private void resetNodeBounds(UiElementNode node) { - node.setEditData(null); - - List children = node.getUiChildren(); - for (UiElementNode child : children) { - resetNodeBounds(child); - } - } - - private void updateNodeWithBounds(ILayoutViewInfo r) { - if (r != null) { - // update the node itself, as the viewKey is the XML node in this implementation. - Object viewKey = r.getViewKey(); - if (viewKey instanceof UiElementNode) { - Rectangle bounds = new Rectangle(r.getLeft(), r.getTop(), - r.getRight()-r.getLeft(), r.getBottom() - r.getTop()); - - ((UiElementNode)viewKey).setEditData(bounds); - } - - // and then its children. - ILayoutViewInfo[] children = r.getChildren(); - if (children != null) { - for (ILayoutViewInfo child : children) { - updateNodeWithBounds(child); - } - } - } - } - - /* - * Called when the file changes triggered a redraw of the layout - */ - public void reloadLayout(ChangeFlags flags, boolean libraryChanged) { - boolean recompute = false; - - if (flags.rClass) { - recompute = true; - ProjectResources projectRes = getProjectResources(); - if (projectRes != null) { - projectRes.resetDynamicIds(); - } - } - - if (flags.localeList) { - // the locale list *potentially* changed so we update the locale list in the - // config composite. - // However there's no recompute, as it could not be needed (for instance a new layout) - // If a resource that's not a layout changed this will trigger a recompute anyway. - mParent.getDisplay().asyncExec(mLocaleUpdaterFromUiRunnable); - } - - if (flags.resources || (libraryChanged && flags.layout)) { - recompute = true; - - // TODO: differentiate between single and multi resource file changed, and whether the resource change affects the cache. - - // force a reparse in case a value XML file changed. - mConfiguredProjectRes = null; - - // clear the cache in the bridge in case a bitmap/9-patch changed. - IAndroidTarget target = Sdk.getCurrent().getTarget(mEditedFile.getProject()); - if (target != null) { - - AndroidTargetData data = Sdk.getCurrent().getTargetData(target); - if (data != null) { - LayoutBridge bridge = data.getLayoutBridge(); - - if (bridge.bridge != null) { - bridge.bridge.clearCaches(mEditedFile.getProject()); - } - } - } - - } - - if (flags.code) { - // only recompute if the custom view loader was used to load some code. - if (mProjectCallback != null && mProjectCallback.isUsed()) { - mProjectCallback = null; - recompute = true; - } - } - - if (recompute) { - mParent.getDisplay().asyncExec(mConditionalRecomputeRunnable); - } - } - - /** - * Responds to a page change that made the Graphical editor page the activated page. - */ - public void activated() { - if (mNeedsRecompute || mNeedsXmlReload) { - recomputeLayout(); - } - } - - /** - * Responds to a page change that made the Graphical editor page the deactivated page - */ - public void deactivated() { - // nothing to be done here for now. - } - - public Map> getConfiguredFrameworkResources() { - if (mConfiguredFrameworkRes == null) { - ProjectResources frameworkRes = getFrameworkResources(); - - if (frameworkRes == null) { - AdtPlugin.log(IStatus.ERROR, "Failed to get ProjectResource for the framework"); - } else { - // get the framework resource values based on the current config - mConfiguredFrameworkRes = frameworkRes.getConfiguredResources( - mConfigComposite.getCurrentConfig()); - } - } - - return mConfiguredFrameworkRes; - } - - public Map> getConfiguredProjectResources() { - if (mConfiguredProjectRes == null) { - ProjectResources project = getProjectResources(); - - // make sure they are loaded - project.loadAll(); - - // get the project resource values based on the current config - mConfiguredProjectRes = project.getConfiguredResources( - mConfigComposite.getCurrentConfig()); - } - - return mConfiguredProjectRes; - } - - /** - * Returns a {@link ProjectResources} for the framework resources. - * @return the framework resources or null if not found. - */ - public ProjectResources getFrameworkResources() { - if (mEditedFile != null) { - Sdk currentSdk = Sdk.getCurrent(); - if (currentSdk != null) { - IAndroidTarget target = currentSdk.getTarget(mEditedFile.getProject()); - - if (target != null) { - AndroidTargetData data = currentSdk.getTargetData(target); - - if (data != null) { - return data.getFrameworkResources(); - } - } - } - } - - return null; - } - - public ProjectResources getProjectResources() { - if (mEditedFile != null) { - ResourceManager manager = ResourceManager.getInstance(); - return manager.getProjectResources(mEditedFile.getProject()); - } - - return null; - } - - /** - * Creates a new layout file from the specified {@link FolderConfiguration}. - */ - private void createAlternateLayout(final FolderConfiguration config) { - new Job("Create Alternate Resource") { - @Override - protected IStatus run(IProgressMonitor monitor) { - // get the folder name - String folderName = config.getFolderName(ResourceFolderType.LAYOUT); - try { - - // look to see if it exists. - // get the res folder - IFolder res = (IFolder)mEditedFile.getParent().getParent(); - String path = res.getLocation().toOSString(); - - File newLayoutFolder = new File(path + File.separator + folderName); - if (newLayoutFolder.isFile()) { - // this should not happen since aapt would have complained - // before, but if one disable the automatic build, this could - // happen. - String message = String.format("File 'res/%1$s' is in the way!", - folderName); - - AdtPlugin.displayError("Layout Creation", message); - - return new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, message); - } else if (newLayoutFolder.exists() == false) { - // create it. - newLayoutFolder.mkdir(); - } - - // now create the file - File newLayoutFile = new File(newLayoutFolder.getAbsolutePath() + - File.separator + mEditedFile.getName()); - - newLayoutFile.createNewFile(); - - InputStream input = mEditedFile.getContents(); - - FileOutputStream fos = new FileOutputStream(newLayoutFile); - - byte[] data = new byte[512]; - int count; - while ((count = input.read(data)) != -1) { - fos.write(data, 0, count); - } - - input.close(); - fos.close(); - - // refreshes the res folder to show up the new - // layout folder (if needed) and the file. - // We use a progress monitor to catch the end of the refresh - // to trigger the edit of the new file. - res.refreshLocal(IResource.DEPTH_INFINITE, new IProgressMonitor() { - public void done() { - mParent.getDisplay().asyncExec(new Runnable() { - public void run() { - onConfigurationChange(); - } - }); - } - - public void beginTask(String name, int totalWork) { - // pass - } - - public void internalWorked(double work) { - // pass - } - - public boolean isCanceled() { - // pass - return false; - } - - public void setCanceled(boolean value) { - // pass - } - - public void setTaskName(String name) { - // pass - } - - public void subTask(String name) { - // pass - } - - public void worked(int work) { - // pass - } - }); - } catch (IOException e2) { - String message = String.format( - "Failed to create File 'res/%1$s/%2$s' : %3$s", - folderName, mEditedFile.getName(), e2.getMessage()); - - AdtPlugin.displayError("Layout Creation", message); - - return new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, - message, e2); - } catch (CoreException e2) { - String message = String.format( - "Failed to create File 'res/%1$s/%2$s' : %3$s", - folderName, mEditedFile.getName(), e2.getMessage()); - - AdtPlugin.displayError("Layout Creation", message); - - return e2.getStatus(); - } - - return Status.OK_STATUS; - - } - }.schedule(); - } - - /** - * Computes a layout by calling the correct computeLayout method of ILayoutBridge based on - * the implementation API level. - */ - @SuppressWarnings("deprecation") - private static ILayoutResult computeLayout(LayoutBridge bridge, - IXmlPullParser layoutDescription, Object projectKey, - int screenWidth, int screenHeight, boolean renderFullSize, - int density, float xdpi, float ydpi, - String themeName, boolean isProjectTheme, - Map> projectResources, - Map> frameworkResources, - IProjectCallback projectCallback, ILayoutLog logger) { - - if (bridge.apiLevel >= ILayoutBridge.API_CURRENT) { - // newest API with support for "render full height" - // TODO: link boolean to UI. - return bridge.bridge.computeLayout(layoutDescription, - projectKey, screenWidth, screenHeight, renderFullSize, - density, xdpi, ydpi, - themeName, isProjectTheme, - projectResources, frameworkResources, projectCallback, - logger); - } else if (bridge.apiLevel == 3) { - // newer api with density support. - return bridge.bridge.computeLayout(layoutDescription, - projectKey, screenWidth, screenHeight, density, xdpi, ydpi, - themeName, isProjectTheme, - projectResources, frameworkResources, projectCallback, - logger); - } else if (bridge.apiLevel == 2) { - // api with boolean for separation of project/framework theme - return bridge.bridge.computeLayout(layoutDescription, - projectKey, screenWidth, screenHeight, themeName, isProjectTheme, - projectResources, frameworkResources, projectCallback, - logger); - } else { - // oldest api with no density/dpi, and project theme boolean mixed - // into the theme name. - - // change the string if it's a custom theme to make sure we can - // differentiate them - if (isProjectTheme) { - themeName = "*" + themeName; //$NON-NLS-1$ - } - - return bridge.bridge.computeLayout(layoutDescription, - projectKey, screenWidth, screenHeight, themeName, - projectResources, frameworkResources, projectCallback, - logger); - } - } - - public boolean hasOutline() { - return mUseOutlineMode; - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle1/PaletteFactory.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle1/PaletteFactory.java deleted file mode 100644 index 363466b..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle1/PaletteFactory.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.adt.internal.editors.layout.gle1; - -import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor; -import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData; - -import org.eclipse.gef.palette.PaletteDrawer; -import org.eclipse.gef.palette.PaletteGroup; -import org.eclipse.gef.palette.PaletteRoot; -import org.eclipse.gef.palette.PaletteTemplateEntry; - -import java.util.List; - -/** - * Factory that creates the palette for the {@link GraphicalLayoutEditor}. - * - * @since GLE1 - */ -public class PaletteFactory { - - /** Static factory, nothing to instantiate here. */ - private PaletteFactory() { - } - - public static PaletteRoot createPaletteRoot(PaletteRoot currentPalette, - AndroidTargetData targetData) { - - if (currentPalette == null) { - currentPalette = new PaletteRoot(); - } - - for (int n = currentPalette.getChildren().size() - 1; n >= 0; n--) { - currentPalette.getChildren().remove(n); - } - - if (targetData != null) { - addTools(currentPalette); - addViews(currentPalette, "Layouts", - targetData.getLayoutDescriptors().getLayoutDescriptors()); - addViews(currentPalette, "Views", - targetData.getLayoutDescriptors().getViewDescriptors()); - } - - return currentPalette; - } - - private static void addTools(PaletteRoot paletteRoot) { - PaletteGroup group = new PaletteGroup("Tools"); - - // Default tools: selection. - // Do not use the MarqueeToolEntry since we don't support multiple selection. - /* -- Do not put the selection tool. It's the unique tool so it looks useless. - Leave this piece of code here in case we want it back later. - PanningSelectionToolEntry entry = new PanningSelectionToolEntry(); - group.add(entry); - paletteRoot.setDefaultEntry(entry); - */ - - paletteRoot.add(group); - } - - private static void addViews(PaletteRoot paletteRoot, String groupName, - List descriptors) { - PaletteDrawer group = new PaletteDrawer(groupName); - - for (ElementDescriptor desc : descriptors) { - PaletteTemplateEntry entry = new PaletteTemplateEntry( - desc.getUiName(), // label - desc.getTooltip(), // short description - desc, // template - desc.getImageDescriptor(), // small icon - desc.getImageDescriptor() // large icon - ); - - group.add(entry); - } - - paletteRoot.add(group); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle1/UiContentOutlinePage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle1/UiContentOutlinePage.java deleted file mode 100644 index 86ff180..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle1/UiContentOutlinePage.java +++ /dev/null @@ -1,618 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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.android.ide.eclipse.adt.internal.editors.layout.gle1; - -import com.android.ide.eclipse.adt.internal.editors.IconFactory; -import com.android.ide.eclipse.adt.internal.editors.layout.IGraphicalLayoutEditor; -import com.android.ide.eclipse.adt.internal.editors.layout.parts.UiDocumentTreeEditPart; -import com.android.ide.eclipse.adt.internal.editors.layout.parts.UiElementTreeEditPart; -import com.android.ide.eclipse.adt.internal.editors.layout.parts.UiElementTreeEditPartFactory; -import com.android.ide.eclipse.adt.internal.editors.layout.parts.UiLayoutTreeEditPart; -import com.android.ide.eclipse.adt.internal.editors.layout.parts.UiViewTreeEditPart; -import com.android.ide.eclipse.adt.internal.editors.ui.tree.CopyCutAction; -import com.android.ide.eclipse.adt.internal.editors.ui.tree.PasteAction; -import com.android.ide.eclipse.adt.internal.editors.ui.tree.UiActions; -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiDocumentNode; -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; -import com.android.ide.eclipse.adt.internal.ui.EclipseUiHelper; - -import org.eclipse.gef.EditPartViewer; -import org.eclipse.gef.ui.parts.ContentOutlinePage; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TreePath; -import org.eclipse.jface.viewers.TreeSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.TreeItem; -import org.eclipse.ui.IActionBars; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -/** - * Implementation of the {@link ContentOutlinePage} to display {@link UiElementNode}. - * - * @since GLE1 - */ -public class UiContentOutlinePage extends ContentOutlinePage { - - private GraphicalLayoutEditor mEditor; - - private Action mAddAction; - private Action mDeleteAction; - private Action mUpAction; - private Action mDownAction; - - private UiOutlineActions mUiActions = new UiOutlineActions(); - - public UiContentOutlinePage(GraphicalLayoutEditor editor, final EditPartViewer viewer) { - super(viewer); - mEditor = editor; - IconFactory factory = IconFactory.getInstance(); - - mAddAction = new Action("Add...") { - @Override - public void run() { - List nodes = getModelSelections(); - UiElementNode node = nodes != null && nodes.size() > 0 ? nodes.get(0) : null; - - mUiActions.doAdd(node, viewer.getControl().getShell()); - } - }; - mAddAction.setToolTipText("Adds a new element."); - mAddAction.setImageDescriptor(factory.getImageDescriptor("add")); //$NON-NLS-1$ - - mDeleteAction = new Action("Remove...") { - @Override - public void run() { - List nodes = getModelSelections(); - - mUiActions.doRemove(nodes, viewer.getControl().getShell()); - } - }; - mDeleteAction.setToolTipText("Removes an existing selected element."); - mDeleteAction.setImageDescriptor(factory.getImageDescriptor("delete")); //$NON-NLS-1$ - - mUpAction = new Action("Up") { - @Override - public void run() { - List nodes = getModelSelections(); - - mUiActions.doUp(nodes); - } - }; - mUpAction.setToolTipText("Moves the selected element up"); - mUpAction.setImageDescriptor(factory.getImageDescriptor("up")); //$NON-NLS-1$ - - mDownAction = new Action("Down") { - @Override - public void run() { - List nodes = getModelSelections(); - - mUiActions.doDown(nodes); - } - }; - mDownAction.setToolTipText("Moves the selected element down"); - mDownAction.setImageDescriptor(factory.getImageDescriptor("down")); //$NON-NLS-1$ - - // all actions disabled by default. - mAddAction.setEnabled(false); - mDeleteAction.setEnabled(false); - mUpAction.setEnabled(false); - mDownAction.setEnabled(false); - - addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - ISelection selection = event.getSelection(); - - // the selection is never empty. The least it'll contain is the - // UiDocumentTreeEditPart object. - if (selection instanceof StructuredSelection) { - StructuredSelection structSel = (StructuredSelection)selection; - - if (structSel.size() == 1 && - structSel.getFirstElement() instanceof UiDocumentTreeEditPart) { - mDeleteAction.setEnabled(false); - mUpAction.setEnabled(false); - mDownAction.setEnabled(false); - } else { - mDeleteAction.setEnabled(true); - mUpAction.setEnabled(true); - mDownAction.setEnabled(true); - } - - // the "add" button is always enabled, in order to be able to set the - // initial root node - mAddAction.setEnabled(true); - } - } - }); - } - - - /* (non-Javadoc) - * @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite) - */ - @Override - public void createControl(Composite parent) { - // create outline viewer page - getViewer().createControl(parent); - - // configure outline viewer - getViewer().setEditPartFactory(new UiElementTreeEditPartFactory()); - - setupOutline(); - setupContextMenu(); - setupTooltip(); - setupDoubleClick(); - } - - /* - * (non-Javadoc) - * @see org.eclipse.ui.part.Page#setActionBars(org.eclipse.ui.IActionBars) - * - * Called automatically after createControl - */ - @Override - public void setActionBars(IActionBars actionBars) { - IToolBarManager toolBarManager = actionBars.getToolBarManager(); - toolBarManager.add(mAddAction); - toolBarManager.add(mDeleteAction); - toolBarManager.add(new Separator()); - toolBarManager.add(mUpAction); - toolBarManager.add(mDownAction); - - IMenuManager menuManager = actionBars.getMenuManager(); - menuManager.add(mAddAction); - menuManager.add(mDeleteAction); - menuManager.add(new Separator()); - menuManager.add(mUpAction); - menuManager.add(mDownAction); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.part.IPage#dispose() - */ - @Override - public void dispose() { - breakConnectionWithEditor(); - - // dispose - super.dispose(); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.part.IPage#getControl() - */ - @Override - public Control getControl() { - return getViewer().getControl(); - } - - void setNewEditor(GraphicalLayoutEditor editor) { - mEditor = editor; - setupOutline(); - } - - void breakConnectionWithEditor() { - // unhook outline viewer - mEditor.getSelectionSynchronizer().removeViewer(getViewer()); - } - - private void setupOutline() { - - getViewer().setEditDomain(mEditor.getEditDomain()); - - // hook outline viewer - mEditor.getSelectionSynchronizer().addViewer(getViewer()); - - // initialize outline viewer with model - getViewer().setContents(mEditor.getModel()); - } - - private void setupContextMenu() { - MenuManager menuManager = new MenuManager(); - menuManager.setRemoveAllWhenShown(true); - menuManager.addMenuListener(new IMenuListener() { - /** - * The menu is about to be shown. The menu manager has already been - * requested to remove any existing menu item. This method gets the - * tree selection and if it is of the appropriate type it re-creates - * the necessary actions. - */ - public void menuAboutToShow(IMenuManager manager) { - List selected = getModelSelections(); - - if (selected != null) { - doCreateMenuAction(manager, selected); - return; - } - doCreateMenuAction(manager, null /* ui_node */); - } - }); - Control control = getControl(); - Menu contextMenu = menuManager.createContextMenu(control); - control.setMenu(contextMenu); - } - - /** - * Adds the menu actions to the context menu when the given UI node is selected in - * the tree view. - * - * @param manager The context menu manager - * @param selected The UI node selected in the tree. Can be null, in which case the root - * is to be modified. - */ - private void doCreateMenuAction(IMenuManager manager, List selected) { - - if (selected != null) { - boolean hasXml = false; - for (UiElementNode uiNode : selected) { - if (uiNode.getXmlNode() != null) { - hasXml = true; - break; - } - } - - if (hasXml) { - manager.add(new CopyCutAction(mEditor.getLayoutEditor(), mEditor.getClipboard(), - null, selected, true /* cut */)); - manager.add(new CopyCutAction(mEditor.getLayoutEditor(), mEditor.getClipboard(), - null, selected, false /* cut */)); - - // Can't paste with more than one element selected (the selection is the target) - if (selected.size() <= 1) { - // Paste is not valid if it would add a second element on a terminal element - // which parent is a document -- an XML document can only have one child. This - // means paste is valid if the current UI node can have children or if the parent - // is not a document. - UiElementNode ui_root = selected.get(0).getUiRoot(); - if (ui_root.getDescriptor().hasChildren() || - !(ui_root.getUiParent() instanceof UiDocumentNode)) { - manager.add(new PasteAction(mEditor.getLayoutEditor(), - mEditor.getClipboard(), - selected.get(0))); - } - } - manager.add(new Separator()); - } - } - - // Append "add" and "remove" actions. They do the same thing as the add/remove - // buttons on the side. - // - // "Add" makes sense only if there's 0 or 1 item selected since the - // one selected item becomes the target. - if (selected == null || selected.size() <= 1) { - manager.add(mAddAction); - } - - if (selected != null) { - manager.add(mDeleteAction); - manager.add(new Separator()); - - manager.add(mUpAction); - manager.add(mDownAction); - } - - if (selected != null && selected.size() == 1) { - manager.add(new Separator()); - - Action propertiesAction = new Action("Properties") { - @Override - public void run() { - EclipseUiHelper.showView(EclipseUiHelper.PROPERTY_SHEET_VIEW_ID, - true /* activate */); - } - }; - propertiesAction.setToolTipText("Displays properties of the selected element."); - manager.add(propertiesAction); - } - } - - /** - * Updates the outline view with the model of the {@link IGraphicalLayoutEditor}. - *

- * This attemps to preserve the selection, if any. - */ - public void reloadModel() { - // Attemps to preserve the UiNode selection, if any - List uiNodes = null; - try { - // get current selection using the model rather than the edit part as - // reloading the content may change the actual edit part. - uiNodes = getModelSelections(); - - // perform the update - getViewer().setContents(mEditor.getModel()); - - } finally { - // restore selection - if (uiNodes != null) { - setModelSelection(uiNodes.get(0)); - } - } - } - - /** - * Returns the currently selected element, if any, in the viewer. - * This returns the viewer's elements (i.e. an {@link UiElementTreeEditPart}) - * and not the underlying model node. - *

- * When there is no actual selection, this might still return the root node, - * which is of type {@link UiDocumentTreeEditPart}. - */ - @SuppressWarnings("unchecked") - private List getViewerSelections() { - ISelection selection = getSelection(); - if (selection instanceof StructuredSelection) { - StructuredSelection structuredSelection = (StructuredSelection)selection; - - if (structuredSelection.size() > 0) { - ArrayList selected = new ArrayList(); - - for (Iterator it = structuredSelection.iterator(); it.hasNext(); ) { - Object selectedObj = it.next(); - - if (selectedObj instanceof UiElementTreeEditPart) { - selected.add((UiElementTreeEditPart) selectedObj); - } - } - - return selected.size() > 0 ? selected : null; - } - } - - return null; - } - - /** - * Returns the currently selected model element, which is either an - * {@link UiViewTreeEditPart} or an {@link UiLayoutTreeEditPart}. - *

- * Returns null if there is no selection or if the implicit root is "selected" - * (which actually represents the lack of a real element selection.) - */ - private List getModelSelections() { - - List parts = getViewerSelections(); - - if (parts != null) { - ArrayList selected = new ArrayList(); - - for (UiElementTreeEditPart part : parts) { - if (part instanceof UiViewTreeEditPart || part instanceof UiLayoutTreeEditPart) { - selected.add((UiElementNode) part.getModel()); - } - } - - return selected.size() > 0 ? selected : null; - } - - return null; - } - - /** - * Selects the corresponding edit part in the tree viewer. - */ - private void setViewerSelection(UiElementTreeEditPart selectedPart) { - if (selectedPart != null && !(selectedPart instanceof UiDocumentTreeEditPart)) { - LinkedList segments = new LinkedList(); - for (UiElementTreeEditPart part = selectedPart; - !(part instanceof UiDocumentTreeEditPart); - part = (UiElementTreeEditPart) part.getParent()) { - segments.add(0, part); - } - setSelection(new TreeSelection(new TreePath(segments.toArray()))); - } - } - - /** - * Selects the corresponding model element in the tree viewer. - */ - private void setModelSelection(UiElementNode uiNodeToSelect) { - if (uiNodeToSelect != null) { - - // find an edit part that has the requested model element - UiElementTreeEditPart part = findPartForModel( - (UiElementTreeEditPart) getViewer().getContents(), - uiNodeToSelect); - - // if we found a part, select it and reveal it - if (part != null) { - setViewerSelection(part); - getViewer().reveal(part); - } - } - } - - /** - * Utility method that tries to find an edit part that matches a given model UI node. - * - * @param rootPart The root of the viewer edit parts - * @param uiNode The UI node model to find - * @return The part that matches the model or null if it's not in the sub tree. - */ - private UiElementTreeEditPart findPartForModel(UiElementTreeEditPart rootPart, - UiElementNode uiNode) { - if (rootPart.getModel() == uiNode) { - return rootPart; - } - - for (Object part : rootPart.getChildren()) { - if (part instanceof UiElementTreeEditPart) { - UiElementTreeEditPart found = findPartForModel( - (UiElementTreeEditPart) part, uiNode); - if (found != null) { - return found; - } - } - } - - return null; - } - - /** - * Sets up a custom tooltip when hovering over tree items. - *

- * The tooltip will display the element's javadoc, if any, or the item's getText otherwise. - */ - private void setupTooltip() { - final Tree tree = (Tree) getControl(); - - /* - * Reference: - * http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet125.java?view=markup - */ - - final Listener listener = new Listener() { - Shell tip = null; - Label label = null; - - public void handleEvent(Event event) { - switch(event.type) { - case SWT.Dispose: - case SWT.KeyDown: - case SWT.MouseExit: - case SWT.MouseDown: - case SWT.MouseMove: - if (tip != null) { - tip.dispose(); - tip = null; - label = null; - } - break; - case SWT.MouseHover: - if (tip != null) { - tip.dispose(); - tip = null; - label = null; - } - - String tooltip = null; - - TreeItem item = tree.getItem(new Point(event.x, event.y)); - if (item != null) { - Object data = item.getData(); - if (data instanceof UiElementTreeEditPart) { - Object model = ((UiElementTreeEditPart) data).getModel(); - if (model instanceof UiElementNode) { - tooltip = ((UiElementNode) model).getDescriptor().getTooltip(); - } - } - - if (tooltip == null) { - tooltip = item.getText(); - } else { - tooltip = item.getText() + ":\r" + tooltip; - } - - if (tooltip != null) { - Shell shell = tree.getShell(); - Display display = tree.getDisplay(); - - tip = new Shell(shell, SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL); - tip.setBackground(display .getSystemColor(SWT.COLOR_INFO_BACKGROUND)); - FillLayout layout = new FillLayout(); - layout.marginWidth = 2; - tip.setLayout(layout); - label = new Label(tip, SWT.NONE); - label.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); - label.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); - label.setData("_TABLEITEM", item); - label.setText(tooltip); - label.addListener(SWT.MouseExit, this); - label.addListener(SWT.MouseDown, this); - Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT); - Rectangle rect = item.getBounds(0); - Point pt = tree.toDisplay(rect.x, rect.y); - tip.setBounds(pt.x, pt.y, size.x, size.y); - tip.setVisible(true); - } - } - } - } - }; - - tree.addListener(SWT.Dispose, listener); - tree.addListener(SWT.KeyDown, listener); - tree.addListener(SWT.MouseMove, listener); - tree.addListener(SWT.MouseHover, listener); - } - - /** - * Sets up double-click action on the tree. - *

- * By default, double-click (a.k.a. "default selection") on a valid list item will - * show the property view. - */ - private void setupDoubleClick() { - final Tree tree = (Tree) getControl(); - - tree.addListener(SWT.DefaultSelection, new Listener() { - public void handleEvent(Event event) { - EclipseUiHelper.showView(EclipseUiHelper.PROPERTY_SHEET_VIEW_ID, - true /* activate */); - } - }); - } - - // --------------- - - private class UiOutlineActions extends UiActions { - - @Override - protected UiDocumentNode getRootNode() { - return mEditor.getModel(); // this is LayoutEditor.getUiRootNode() - } - - // Select the new item - @Override - protected void selectUiNode(UiElementNode uiNodeToSelect) { - setModelSelection(uiNodeToSelect); - } - - @Override - public void commitPendingXmlChanges() { - // Pass. There is nothing to commit before the XML is changed here. - } - - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle1/UiPropertySheetPage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle1/UiPropertySheetPage.java deleted file mode 100644 index e619344..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle1/UiPropertySheetPage.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.adt.internal.editors.layout.gle1; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.TreeItem; -import org.eclipse.ui.views.properties.PropertySheetEntry; -import org.eclipse.ui.views.properties.PropertySheetPage; - -/** - * A customized property sheet page for the graphical layout editor. - *

- * Currently it just provides a custom tooltip to display attributes javadocs. - * - * @since GLE1 - */ -public class UiPropertySheetPage extends PropertySheetPage { - - - public UiPropertySheetPage() { - super(); - } - - @Override - public void createControl(Composite parent) { - super.createControl(parent); - - setupTooltip(); - } - - /** - * Sets up a custom tooltip when hovering over tree items. - *

- * The tooltip will display the element's javadoc, if any, or the item's getText otherwise. - */ - private void setupTooltip() { - final Tree tree = (Tree) getControl(); - - /* - * Reference: - * http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet125.java?view=markup - */ - - final Listener listener = new Listener() { - Shell tip = null; - Label label = null; - - public void handleEvent(Event event) { - switch(event.type) { - case SWT.Dispose: - case SWT.KeyDown: - case SWT.MouseExit: - case SWT.MouseDown: - case SWT.MouseMove: - if (tip != null) { - tip.dispose(); - tip = null; - label = null; - } - break; - case SWT.MouseHover: - if (tip != null) { - tip.dispose(); - tip = null; - label = null; - } - - String tooltip = null; - - TreeItem item = tree.getItem(new Point(event.x, event.y)); - if (item != null) { - Object data = item.getData(); - if (data instanceof PropertySheetEntry) { - tooltip = ((PropertySheetEntry) data).getDescription(); - } - - if (tooltip == null) { - tooltip = item.getText(); - } else { - tooltip = item.getText() + ":\r" + tooltip; - } - - if (tooltip != null) { - Shell shell = tree.getShell(); - Display display = tree.getDisplay(); - - tip = new Shell(shell, SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL); - tip.setBackground(display .getSystemColor(SWT.COLOR_INFO_BACKGROUND)); - FillLayout layout = new FillLayout(); - layout.marginWidth = 2; - tip.setLayout(layout); - label = new Label(tip, SWT.NONE); - label.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); - label.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); - label.setData("_TABLEITEM", item); - label.setText(tooltip); - label.addListener(SWT.MouseExit, this); - label.addListener(SWT.MouseDown, this); - Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT); - Rectangle rect = item.getBounds(0); - Point pt = tree.toDisplay(rect.x, rect.y); - tip.setBounds(pt.x, pt.y, size.x, size.y); - tip.setVisible(true); - } - } - } - } - }; - - tree.addListener(SWT.Dispose, listener); - tree.addListener(SWT.KeyDown, listener); - tree.addListener(SWT.MouseMove, listener); - tree.addListener(SWT.MouseHover, listener); - - } - -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java index 27b7c20..21d8272 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java @@ -31,7 +31,6 @@ import com.android.ide.eclipse.adt.internal.editors.layout.configuration.LayoutC import com.android.ide.eclipse.adt.internal.editors.layout.configuration.ConfigurationComposite.CustomButton; import com.android.ide.eclipse.adt.internal.editors.layout.configuration.ConfigurationComposite.IConfigListener; import com.android.ide.eclipse.adt.internal.editors.layout.gre.RulesEngine; -import com.android.ide.eclipse.adt.internal.editors.layout.parts.ElementCreateCommand; import com.android.ide.eclipse.adt.internal.editors.uimodel.UiDocumentNode; import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; import com.android.ide.eclipse.adt.internal.resources.configurations.FolderConfiguration; @@ -1288,28 +1287,6 @@ public class GraphicalEditorPart extends EditorPart } } - /** - * Used by LayoutEditor.UiEditorActions.selectUiNode to select a new UI Node - * created by {@link ElementCreateCommand#execute()}. - * - * @param uiNodeModel The {@link UiElementNode} to select. - */ - public void selectModel(UiElementNode uiNodeModel) { - - // TODO this method was useful for GLE1. We may not need it anymore now. - -// GraphicalViewer viewer = getGraphicalViewer(); -// -// // Give focus to the graphical viewer (in case the outline has it) -// viewer.getControl().forceFocus(); -// -// Object editPart = viewer.getEditPartRegistry().get(uiNodeModel); -// -// if (editPart instanceof EditPart) { -// viewer.select((EditPart)editPart); -// } - } - private class ReloadListener implements ILayoutReloadListener { /* * Called when the file changes triggered a redraw of the layout diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/DropFeedback.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/DropFeedback.java deleted file mode 100644 index ec928dd..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/DropFeedback.java +++ /dev/null @@ -1,778 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.adt.internal.editors.layout.parts; - -import com.android.ide.eclipse.adt.internal.editors.descriptors.DescriptorsUtils; -import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor; -import com.android.ide.eclipse.adt.internal.editors.layout.LayoutConstants; -import com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor.UiEditorActions; -import com.android.ide.eclipse.adt.internal.editors.layout.parts.UiLayoutEditPart.HighlightInfo; -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; -import com.android.sdklib.SdkConstants; - -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.draw2d.geometry.Rectangle; - -import java.util.HashMap; -import java.util.Map.Entry; - -/** - * Utility methods used when dealing with dropping EditPart on the GLE. - *

- * This class uses some temporary static storage to avoid excessive allocations during - * drop operations. It is expected to only be invoked from the main UI thread with no - * concurrent access. - * - * @since GLE1 - */ -class DropFeedback { - - private static final int TOP = 0; - private static final int LEFT = 1; - private static final int BOTTOM = 2; - private static final int RIGHT = 3; - private static final int MAX_DIR = RIGHT; - - private static final int sOppositeDirection[] = { BOTTOM, RIGHT, TOP, LEFT }; - - private static final UiElementEditPart sTempClosests[] = new UiElementEditPart[4]; - private static final int sTempMinDists[] = new int[4]; - - - /** - * Target information computed from a drop on a RelativeLayout. - * We need only one instance of this and it is sRelativeInfo. - */ - private static class RelativeInfo { - /** The two target parts 0 and 1. They can be null, meaning a border is used. - * The direction from part 0 to 1 is always to-the-right or to-the-bottom. */ - final UiElementEditPart targetParts[] = new UiElementEditPart[2]; - /** Direction from the anchor part to the drop point. */ - int direction; - /** The index of the "anchor" part, i.e. the closest one selected by the drop. - * This can be either 0 or 1. The corresponding part can be null. */ - int anchorIndex; - } - - /** The single RelativeInfo used to compute results from a drop on a RelativeLayout */ - private static final RelativeInfo sRelativeInfo = new RelativeInfo(); - /** A temporary array of 2 {@link UiElementEditPart} to avoid allocations. */ - private static final UiElementEditPart sTempTwoParts[] = new UiElementEditPart[2]; - - - private DropFeedback() { - } - - - //----- Package methods called by users of this helper class ----- - - - /** - * This method is used by {@link ElementCreateCommand#execute()} when a new item - * needs to be "dropped" in the current XML document. It creates the new item using - * the given descriptor as a child of the given parent part. - * - * @param parentPart The parent part. - * @param descriptor The descriptor for the new XML element. - * @param where The drop location (in parent coordinates) - * @param actions The helper that actually modifies the XML model. - */ - static void addElementToXml(UiElementEditPart parentPart, - ElementDescriptor descriptor, Point where, - UiEditorActions actions) { - - String layoutXmlName = getXmlLocalName(parentPart); - RelativeInfo info = null; - UiElementEditPart sibling = null; - - // TODO consider merge like a vertical layout - // TODO consider TableLayout like a linear - if (LayoutConstants.LINEAR_LAYOUT.equals(layoutXmlName)) { - sibling = findLinearTarget(parentPart, where)[1]; - - } else if (LayoutConstants.RELATIVE_LAYOUT.equals(layoutXmlName)) { - info = findRelativeTarget(parentPart, where, sRelativeInfo); - if (info != null) { - sibling = info.targetParts[info.anchorIndex]; - sibling = getNextUiSibling(sibling); - } - } - - if (actions != null) { - UiElementNode uiSibling = sibling != null ? sibling.getUiNode() : null; - UiElementNode uiParent = parentPart.getUiNode(); - UiElementNode uiNode = actions.addElement(uiParent, uiSibling, descriptor, - false /*updateLayout*/); - - if (LayoutConstants.ABSOLUTE_LAYOUT.equals(layoutXmlName)) { - adjustAbsoluteAttributes(uiNode, where); - } else if (LayoutConstants.RELATIVE_LAYOUT.equals(layoutXmlName)) { - adustRelativeAttributes(uiNode, info); - } - } - } - - /** - * This method is used by {@link UiLayoutEditPart#showDropTarget(Point)} to compute - * highlight information when a drop target is moved over a valid drop area. - *

- * Since there are no "out" parameters in Java, all the information is returned - * via the {@link HighlightInfo} structure passed as parameter. - * - * @param parentPart The parent part, always a layout. - * @param highlightInfo A structure where result is stored to perform highlight. - * @param where The target drop point, in parent's coordinates - * @return The {@link HighlightInfo} structured passed as a parameter, for convenience. - */ - static HighlightInfo computeDropFeedback(UiLayoutEditPart parentPart, - HighlightInfo highlightInfo, - Point where) { - String layoutType = getXmlLocalName(parentPart); - - if (LayoutConstants.ABSOLUTE_LAYOUT.equals(layoutType)) { - highlightInfo.anchorPoint = where; - - } else if (LayoutConstants.LINEAR_LAYOUT.equals(layoutType)) { - boolean isVertical = isVertical(parentPart); - - highlightInfo.childParts = findLinearTarget(parentPart, where); - computeLinearLine(parentPart, isVertical, highlightInfo); - - } else if (LayoutConstants.RELATIVE_LAYOUT.equals(layoutType)) { - - RelativeInfo info = findRelativeTarget(parentPart, where, sRelativeInfo); - if (info != null) { - highlightInfo.childParts = sRelativeInfo.targetParts; - computeRelativeLine(parentPart, info, highlightInfo); - } - } - - return highlightInfo; - } - - - //----- Misc utilities ----- - - /** - * Returns the next UI sibling of this part, i.e. the element which is just after in - * the UI/XML order in the same parent. Returns null if there's no such part. - *

- * Note: by "UI sibling" here we mean the sibling in the UiNode hierarchy. By design the - * UiNode model has the exact same order as the XML model. This has nothing to do - * with the "user interface" order that you see on the rendered Android layouts (e.g. for - * LinearLayout they are the same but for AbsoluteLayout or RelativeLayout the UI/XML model - * order can be vastly different from the user interface order.) - */ - private static UiElementEditPart getNextUiSibling(UiElementEditPart part) { - if (part != null) { - UiElementNode uiNode = part.getUiNode(); - if (uiNode != null) { - uiNode = uiNode.getUiNextSibling(); - } - if (uiNode != null) { - for (Object childPart : part.getParent().getChildren()) { - if (childPart instanceof UiElementEditPart && - ((UiElementEditPart) childPart).getUiNode() == uiNode) { - return (UiElementEditPart) childPart; - } - } - } - } - return null; - } - - /** - * Returns the XML local name of the ui node associated with this edit part or null. - */ - private static String getXmlLocalName(UiElementEditPart editPart) { - UiElementNode uiNode = editPart.getUiNode(); - if (uiNode != null) { - ElementDescriptor desc = uiNode.getDescriptor(); - if (desc != null) { - return desc.getXmlLocalName(); - } - } - return null; - } - - /** - * Adjusts the attributes of a new node dropped in an AbsoluteLayout. - * - * @param uiNode The new node being dropped. - * @param where The drop location (in parent coordinates) - */ - private static void adjustAbsoluteAttributes(final UiElementNode uiNode, final Point where) { - if (where == null) { - return; - } - uiNode.getEditor().wrapEditXmlModel(new Runnable() { - public void run() { - uiNode.setAttributeValue( - LayoutConstants.ATTR_LAYOUT_X, - SdkConstants.NS_RESOURCES, - String.format(LayoutConstants.VALUE_N_DIP, where.x), - false /* override */); - uiNode.setAttributeValue( - LayoutConstants.ATTR_LAYOUT_Y, - SdkConstants.NS_RESOURCES, - String.format(LayoutConstants.VALUE_N_DIP, where.y), - false /* override */); - - uiNode.commitDirtyAttributesToXml(); - } - }); - } - - /** - * Adjusts the attributes of a new node dropped in a RelativeLayout: - *

    - *
  • anchor part: the one the user selected (or the closest) and to which the new one - * will "attach". The anchor part can be null, either because the layout is currently - * empty or the user is attaching to an existing empty border. - *
  • direction: the direction from the anchor part to the drop point. That's also the - * direction from the anchor part to the new part. - *
  • the new node; it is created either after the anchor for right or top directions - * or before the anchor for left or bottom directions. This means the new part can - * reference the id of the anchor part. - *
- * - * Several cases: - *
    - *
  • set: layout_above/below/toLeftOf/toRightOf to point to the anchor. - *
  • copy: layout_centerHorizontal for top/bottom directions - *
  • copy: layout_centerVertical for left/right directions. - *
  • copy: layout_above/below/toLeftOf/toRightOf for the orthogonal direction - * (i.e. top/bottom or left/right.) - *
- * - * @param uiNode The new node being dropped. - * @param info The context computed by {@link #findRelativeTarget(UiElementEditPart, Point, RelativeInfo)}. - */ - private static void adustRelativeAttributes(final UiElementNode uiNode, RelativeInfo info) { - if (uiNode == null || info == null) { - return; - } - - final UiElementEditPart anchorPart = info.targetParts[info.anchorIndex]; // can be null - final int direction = info.direction; - - uiNode.getEditor().wrapEditXmlModel(new Runnable() { - public void run() { - HashMap map = new HashMap(); - - UiElementNode anchorUiNode = anchorPart != null ? anchorPart.getUiNode() : null; - String anchorId = anchorUiNode != null - ? anchorUiNode.getAttributeValue(LayoutConstants.ATTR_ID) - : null; - - if (anchorId == null) { - anchorId = DescriptorsUtils.getFreeWidgetId(anchorUiNode); - anchorUiNode.setAttributeValue( - LayoutConstants.ATTR_ID, - SdkConstants.NS_RESOURCES, - anchorId, - true /*override*/); - } - - if (anchorId != null) { - switch(direction) { - case TOP: - map.put(LayoutConstants.ATTR_LAYOUT_ABOVE, anchorId); - break; - case BOTTOM: - map.put(LayoutConstants.ATTR_LAYOUT_BELOW, anchorId); - break; - case LEFT: - map.put(LayoutConstants.ATTR_LAYOUT_TO_LEFT_OF, anchorId); - break; - case RIGHT: - map.put(LayoutConstants.ATTR_LAYOUT_TO_RIGHT_OF, anchorId); - break; - } - - switch(direction) { - case TOP: - case BOTTOM: - map.put(LayoutConstants.ATTR_LAYOUT_CENTER_HORIZONTAL, - anchorUiNode.getAttributeValue( - LayoutConstants.ATTR_LAYOUT_CENTER_HORIZONTAL)); - - map.put(LayoutConstants.ATTR_LAYOUT_TO_LEFT_OF, - anchorUiNode.getAttributeValue( - LayoutConstants.ATTR_LAYOUT_TO_LEFT_OF)); - map.put(LayoutConstants.ATTR_LAYOUT_TO_RIGHT_OF, - anchorUiNode.getAttributeValue( - LayoutConstants.ATTR_LAYOUT_TO_RIGHT_OF)); - break; - case LEFT: - case RIGHT: - map.put(LayoutConstants.ATTR_LAYOUT_CENTER_VERTICAL, - anchorUiNode.getAttributeValue( - LayoutConstants.ATTR_LAYOUT_CENTER_VERTICAL)); - map.put(LayoutConstants.ATTR_LAYOUT_ALIGN_BASELINE, - anchorUiNode.getAttributeValue( - LayoutConstants.ATTR_LAYOUT_ALIGN_BASELINE)); - - map.put(LayoutConstants.ATTR_LAYOUT_ABOVE, - anchorUiNode.getAttributeValue(LayoutConstants.ATTR_LAYOUT_ABOVE)); - map.put(LayoutConstants.ATTR_LAYOUT_BELOW, - anchorUiNode.getAttributeValue(LayoutConstants.ATTR_LAYOUT_BELOW)); - break; - } - } else { - // We don't have an anchor node. Assume we're targeting a border and align - // to the parent. - switch(direction) { - case TOP: - map.put(LayoutConstants.ATTR_LAYOUT_ALIGN_PARENT_TOP, - LayoutConstants.VALUE_TRUE); - break; - case BOTTOM: - map.put(LayoutConstants.ATTR_LAYOUT_ALIGN_PARENT_BOTTOM, - LayoutConstants.VALUE_TRUE); - break; - case LEFT: - map.put(LayoutConstants.ATTR_LAYOUT_ALIGN_PARENT_LEFT, - LayoutConstants.VALUE_TRUE); - break; - case RIGHT: - map.put(LayoutConstants.ATTR_LAYOUT_ALIGN_PARENT_RIGHT, - LayoutConstants.VALUE_TRUE); - break; - } - } - - for (Entry entry : map.entrySet()) { - uiNode.setAttributeValue( - entry.getKey(), - SdkConstants.NS_RESOURCES, - entry.getValue(), - true /* override */); - } - uiNode.commitDirtyAttributesToXml(); - } - }); - } - - - //----- LinearLayout -------- - - /** - * For a given parent edit part that MUST represent a LinearLayout, finds the - * element before which the location points. - *

- * This computes the edit part that corresponds to what will be the "next sibling" of the new - * element. - *

- * It returns null if it can't be determined, in which case the element will be added at the - * end of the parent child list. - * - * @return The edit parts that correspond to what will be the "prev" and "next sibling" of the - * new element. The previous sibling can be null if adding before the first element. - * The next sibling can be null if adding after the last element. - */ - private static UiElementEditPart[] findLinearTarget(UiElementEditPart parent, Point point) { - // default orientation is horizontal - boolean isVertical = isVertical(parent); - - int target = isVertical ? point.y : point.x; - - UiElementEditPart prev = null; - UiElementEditPart next = null; - - for (Object child : parent.getChildren()) { - if (child instanceof UiElementEditPart) { - UiElementEditPart childPart = (UiElementEditPart) child; - Point p = childPart.getBounds().getCenter(); - int middle = isVertical ? p.y : p.x; - if (target < middle) { - next = childPart; - break; - } - prev = childPart; - } - } - - sTempTwoParts[0] = prev; - sTempTwoParts[1] = next; - return sTempTwoParts; - } - - /** - * Computes the highlight line between two parts. - *

- * The two parts are listed in HighlightInfo.childParts[2]. Any of the parts - * can be null. - * The result is stored in HighlightInfo. - *

- * Caller must clear the HighlightInfo as appropriate before this call. - * - * @param parentPart The parent part, always a layout. - * @param isVertical True for vertical parts, thus computing an horizontal line. - * @param highlightInfo The in-out highlight info. - */ - private static void computeLinearLine(UiLayoutEditPart parentPart, - boolean isVertical, HighlightInfo highlightInfo) { - Rectangle r = parentPart.getBounds(); - - if (isVertical) { - Point p = null; - UiElementEditPart part = highlightInfo.childParts[0]; - if (part != null) { - p = part.getBounds().getBottom(); - } else { - part = highlightInfo.childParts[1]; - if (part != null) { - p = part.getBounds().getTop(); - } - } - if (p != null) { - // horizontal line with middle anchor point - highlightInfo.tempPoints[0].setLocation(0, p.y); - highlightInfo.tempPoints[1].setLocation(r.width, p.y); - highlightInfo.linePoints = highlightInfo.tempPoints; - highlightInfo.anchorPoint = p.setLocation(r.width / 2, p.y); - } - } else { - Point p = null; - UiElementEditPart part = highlightInfo.childParts[0]; - if (part != null) { - p = part.getBounds().getRight(); - } else { - part = highlightInfo.childParts[1]; - if (part != null) { - p = part.getBounds().getLeft(); - } - } - if (p != null) { - // vertical line with middle anchor point - highlightInfo.tempPoints[0].setLocation(p.x, 0); - highlightInfo.tempPoints[1].setLocation(p.x, r.height); - highlightInfo.linePoints = highlightInfo.tempPoints; - highlightInfo.anchorPoint = p.setLocation(p.x, r.height / 2); - } - } - } - - /** - * Returns true if the linear layout is marked as vertical. - * - * @param parent The a layout part that must be a LinearLayout - * @return True if the linear layout has a vertical orientation attribute. - */ - private static boolean isVertical(UiElementEditPart parent) { - String orientation = parent.getStringAttr("orientation"); //$NON-NLS-1$ - boolean isVertical = "vertical".equals(orientation) || //$NON-NLS-1$ - "1".equals(orientation); //$NON-NLS-1$ - return isVertical; - } - - - //----- RelativeLayout -------- - - /** - * Finds the "target" relative layout item for the drop operation & feedback. - *

- * If the drop point is exactly on a current item, simply returns the side the drop will occur - * compared to the center of that element. For the actual XML, we'll need to insert *after* - * that element to make sure that referenced are defined in the right order. - * In that case the result contains two elements, the second one always being on the right or - * bottom side of the first one. When insert in XML, we want to insert right before that - * second element or at the end of the child list if the second element is null. - *

- * If the drop point is not exactly on a current element, find the closest in each - * direction and align with the two closest of these. - * - * @return null if we fail to find anything (such as there are currently no items to compare - * with); otherwise fills the {@link RelativeInfo} and return it. - */ - private static RelativeInfo findRelativeTarget(UiElementEditPart parent, - Point point, - RelativeInfo outInfo) { - - for (int i = 0; i < 4; i++) { - sTempMinDists[i] = Integer.MAX_VALUE; - sTempClosests[i] = null; - } - - - for (Object child : parent.getChildren()) { - if (child instanceof UiElementEditPart) { - UiElementEditPart childPart = (UiElementEditPart) child; - Rectangle r = childPart.getBounds(); - if (r.contains(point)) { - - float rx = ((float)(point.x - r.x) / (float)r.width ) - 0.5f; - float ry = ((float)(point.y - r.y) / (float)r.height) - 0.5f; - - /* TOP - * \ / - * \ / - * L X R - * / \ - * / \ - * BOT - */ - - int index = 0; - if (Math.abs(rx) >= Math.abs(ry)) { - if (rx < 0) { - outInfo.direction = LEFT; - index = 1; - } else { - outInfo.direction = RIGHT; - } - } else { - if (ry < 0) { - outInfo.direction = TOP; - index = 1; - } else { - outInfo.direction = BOTTOM; - } - } - - outInfo.anchorIndex = index; - outInfo.targetParts[index] = childPart; - outInfo.targetParts[1 - index] = findClosestPart(childPart, - outInfo.direction); - - return outInfo; - } - - computeClosest(point, childPart, sTempClosests, sTempMinDists, TOP); - computeClosest(point, childPart, sTempClosests, sTempMinDists, LEFT); - computeClosest(point, childPart, sTempClosests, sTempMinDists, BOTTOM); - computeClosest(point, childPart, sTempClosests, sTempMinDists, RIGHT); - } - } - - UiElementEditPart closest = null; - int minDist = Integer.MAX_VALUE; - int minDir = -1; - - for (int i = 0; i <= MAX_DIR; i++) { - if (sTempClosests[i] != null && sTempMinDists[i] < minDist) { - closest = sTempClosests[i]; - minDist = sTempMinDists[i]; - minDir = i; - } - } - - if (closest != null) { - int index = 0; - switch(minDir) { - case TOP: - case LEFT: - index = 0; - break; - case BOTTOM: - case RIGHT: - index = 1; - break; - } - outInfo.anchorIndex = index; - outInfo.targetParts[index] = closest; - outInfo.targetParts[1 - index] = findClosestPart(closest, sOppositeDirection[minDir]); - outInfo.direction = sOppositeDirection[minDir]; - return outInfo; - } - - return null; - } - - /** - * Computes the highlight line for a drop on a RelativeLayout. - *

- * The line is always placed on the side of the anchor part indicated by the - * direction. The direction always point from the anchor part to the drop point. - *

- * If there's no anchor part, use the other one with a reversed direction. - *

- * On output, this updates the {@link HighlightInfo}. - */ - private static void computeRelativeLine(UiLayoutEditPart parentPart, - RelativeInfo relInfo, - HighlightInfo highlightInfo) { - - UiElementEditPart[] parts = relInfo.targetParts; - int dir = relInfo.direction; - int index = relInfo.anchorIndex; - UiElementEditPart part = parts[index]; - - if (part == null) { - dir = sOppositeDirection[dir]; - part = parts[1 - index]; - } - if (part == null) { - // give up if both parts are null - return; - } - - Rectangle r = part.getBounds(); - Point p = null; - switch(dir) { - case TOP: - p = r.getTop(); - break; - case BOTTOM: - p = r.getBottom(); - break; - case LEFT: - p = r.getLeft(); - break; - case RIGHT: - p = r.getRight(); - break; - } - - highlightInfo.anchorPoint = p; - - r = parentPart.getBounds(); - switch(dir) { - case TOP: - case BOTTOM: - // horizontal line with middle anchor point - highlightInfo.tempPoints[0].setLocation(0, p.y); - highlightInfo.tempPoints[1].setLocation(r.width, p.y); - highlightInfo.linePoints = highlightInfo.tempPoints; - highlightInfo.anchorPoint = p; - break; - case LEFT: - case RIGHT: - // vertical line with middle anchor point - highlightInfo.tempPoints[0].setLocation(p.x, 0); - highlightInfo.tempPoints[1].setLocation(p.x, r.height); - highlightInfo.linePoints = highlightInfo.tempPoints; - highlightInfo.anchorPoint = p; - break; - } - } - - /** - * Given a certain reference point (drop point), computes the distance to the given - * part in the given direction. For example if direction is top, only accepts parts which - * bottom is above the reference point, computes their distance and then updates the - * current minimal distances and current closest parts arrays accordingly. - */ - private static void computeClosest(Point refPoint, - UiElementEditPart compareToPart, - UiElementEditPart[] currClosests, - int[] currMinDists, - int direction) { - Rectangle r = compareToPart.getBounds(); - - Point p = null; - boolean usable = false; - - switch(direction) { - case TOP: - p = r.getBottom(); - usable = p.y <= refPoint.y; - break; - case BOTTOM: - p = r.getTop(); - usable = p.y >= refPoint.y; - break; - case LEFT: - p = r.getRight(); - usable = p.x <= refPoint.x; - break; - case RIGHT: - p = r.getLeft(); - usable = p.x >= refPoint.x; - break; - } - - if (usable) { - int d = p.getDistance2(refPoint); - if (d < currMinDists[direction]) { - currMinDists[direction] = d; - currClosests[direction] = compareToPart; - } - } - } - - /** - * Given a reference parts, finds the closest part in the parent in the given direction. - * For example if direction is top, finds the closest sibling part which is above the - * reference part and non-overlapping (they can touch.) - */ - private static UiElementEditPart findClosestPart(UiElementEditPart referencePart, - int direction) { - if (referencePart == null || referencePart.getParent() == null) { - return null; - } - - Rectangle r = referencePart.getBounds(); - Point ref = null; - switch(direction) { - case TOP: - ref = r.getTop(); - break; - case BOTTOM: - ref = r.getBottom(); - break; - case LEFT: - ref = r.getLeft(); - break; - case RIGHT: - ref = r.getRight(); - break; - } - - int minDist = Integer.MAX_VALUE; - UiElementEditPart closestPart = null; - - for (Object childPart : referencePart.getParent().getChildren()) { - if (childPart != referencePart && childPart instanceof UiElementEditPart) { - r = ((UiElementEditPart) childPart).getBounds(); - Point p = null; - boolean usable = false; - - switch(direction) { - case TOP: - p = r.getBottom(); - usable = p.y <= ref.y; - break; - case BOTTOM: - p = r.getTop(); - usable = p.y >= ref.y; - break; - case LEFT: - p = r.getRight(); - usable = p.x <= ref.x; - break; - case RIGHT: - p = r.getLeft(); - usable = p.x >= ref.x; - break; - } - - if (usable) { - int d = p.getDistance2(ref); - if (d < minDist) { - minDist = d; - closestPart = (UiElementEditPart) childPart; - } - } - } - } - - return closestPart; - } - -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/ElementCreateCommand.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/ElementCreateCommand.java deleted file mode 100644 index 128dfd7..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/ElementCreateCommand.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.adt.internal.editors.layout.parts; - -import com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor; -import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor; -import com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor; -import com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor.UiEditorActions; -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; - -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.gef.commands.Command; - -/** - * A command that knows how to instantiate a new element based on a given {@link ElementDescriptor}, - * the parent {@link UiElementEditPart} and an optional target location. - * - * @since GLE1 - */ -public class ElementCreateCommand extends Command { - - /** Descriptor of the new element to create */ - private final ElementDescriptor mDescriptor; - /** The edit part that hosts the new edit part */ - private final UiElementEditPart mParentPart; - /** The drop location in parent coordinates */ - private final Point mTargetPoint; - - /** - * Creates a new {@link ElementCreateCommand}. - * - * @param descriptor Descriptor of the new element to create - * @param targetPart The edit part that hosts the new edit part - * @param targetPoint The drop location in parent coordinates - */ - public ElementCreateCommand(ElementDescriptor descriptor, - UiElementEditPart targetPart, Point targetPoint) { - mDescriptor = descriptor; - mParentPart = targetPart; - mTargetPoint = targetPoint; - } - - // --- Methods inherited from Command --- - - @Override - public boolean canExecute() { - return mDescriptor != null && - mParentPart != null && - mParentPart.getUiNode() != null && - mParentPart.getUiNode().getEditor() instanceof LayoutEditor; - } - - @Override - public void execute() { - super.execute(); - UiElementNode uiParent = mParentPart.getUiNode(); - if (uiParent != null) { - final AndroidXmlEditor editor = uiParent.getEditor(); - if (editor instanceof LayoutEditor) { - ((LayoutEditor) editor).wrapUndoEditXmlModel( - String.format("Create %1$s", mDescriptor.getXmlLocalName()), - new Runnable() { - public void run() { - UiEditorActions actions = ((LayoutEditor) editor).getUiEditorActions(); - if (actions != null) { - DropFeedback.addElementToXml(mParentPart, mDescriptor, mTargetPoint, - actions); - } - } - }); - } - } - } - - @Override - public void redo() { - throw new UnsupportedOperationException("redo not supported by this command"); //$NON-NLS-1$ - } - - @Override - public void undo() { - throw new UnsupportedOperationException("undo not supported by this command"); //$NON-NLS-1$ - } - -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/ElementFigure.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/ElementFigure.java deleted file mode 100644 index f3dc1ac..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/ElementFigure.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.adt.internal.editors.layout.parts; - -import com.android.ide.eclipse.adt.internal.editors.layout.parts.UiElementsEditPartFactory.IOutlineProvider; - -import org.eclipse.draw2d.ColorConstants; -import org.eclipse.draw2d.Figure; -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.swt.SWT; - - -/** - * The figure used to draw basic elements. - *

- * The figure is totally empty and transparent except for the selection border. - * - * @since GLE1 - */ -class ElementFigure extends Figure { - - private boolean mIsSelected; - private Rectangle mInnerBounds; - private final IOutlineProvider mProvider; - - public ElementFigure(IOutlineProvider provider) { - mProvider = provider; - setOpaque(false); - } - - public void setSelected(boolean isSelected) { - if (isSelected != mIsSelected) { - mIsSelected = isSelected; - repaint(); - } - } - - @Override - public void setBounds(Rectangle rect) { - super.setBounds(rect); - - mInnerBounds = getBounds().getCopy(); - if (mInnerBounds.width > 0) { - mInnerBounds.width--; - } - if (mInnerBounds.height > 0) { - mInnerBounds.height--; - } - } - - public Rectangle getInnerBounds() { - return mInnerBounds; - } - - @Override - protected void paintBorder(Graphics graphics) { - super.paintBorder(graphics); - - if (mIsSelected || (mProvider != null && mProvider.hasOutline())) { - graphics.setLineWidth(1); - graphics.setLineStyle(SWT.LINE_SOLID); - graphics.setForegroundColor(mIsSelected ? ColorConstants.red : ColorConstants.white); - graphics.drawRectangle(getInnerBounds()); - } - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/LayoutFigure.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/LayoutFigure.java deleted file mode 100644 index a4e3573..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/LayoutFigure.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.adt.internal.editors.layout.parts; - -import com.android.ide.eclipse.adt.internal.editors.layout.parts.UiElementsEditPartFactory.IOutlineProvider; -import com.android.ide.eclipse.adt.internal.editors.layout.parts.UiLayoutEditPart.HighlightInfo; - -import org.eclipse.draw2d.ColorConstants; -import org.eclipse.draw2d.Figure; -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.swt.SWT; - -/** - * The figure used to draw the feedback on a layout. - *

- * By default the figure is transparent and empty. - * The base {@link ElementFigure} knows how to draw the selection border. - * This figure knows how to draw the drop feedback. - * - * @since GLE1 - */ -class LayoutFigure extends ElementFigure { - - private HighlightInfo mHighlightInfo; - - public LayoutFigure(IOutlineProvider provider) { - super(provider); - } - - public void setHighlighInfo(HighlightInfo highlightInfo) { - mHighlightInfo = highlightInfo; - repaint(); - } - - /** - * Paints the "border" for this figure. - *

- * The parent {@link Figure#paint(Graphics)} calls {@link #paintFigure(Graphics)} then - * {@link #paintClientArea(Graphics)} then {@link #paintBorder(Graphics)}. Here we thus - * draw the actual highlight border but also the highlight anchor lines and points so that - * we can make sure they are all drawn on top of the border. - *

- * Note: This method doesn't really need to restore its graphic state. The parent - * Figure will do it for us. - *

- * - * @param graphics The Graphics object used for painting - */ - @Override - protected void paintBorder(Graphics graphics) { - super.paintBorder(graphics); - - if (mHighlightInfo == null) { - return; - } - - // Draw the border. We want other highlighting to be drawn on top of the border. - if (mHighlightInfo.drawDropBorder) { - graphics.setLineWidth(3); - graphics.setLineStyle(SWT.LINE_SOLID); - graphics.setForegroundColor(ColorConstants.green); - graphics.drawRectangle(getInnerBounds().getCopy().shrink(1, 1)); - } - - Rectangle bounds = getBounds(); - int bx = bounds.x; - int by = bounds.y; - int w = bounds.width; - int h = bounds.height; - - // Draw frames of target child parts, if any - if (mHighlightInfo.childParts != null) { - graphics.setLineWidth(2); - graphics.setLineStyle(SWT.LINE_DOT); - graphics.setForegroundColor(ColorConstants.lightBlue); - for (UiElementEditPart part : mHighlightInfo.childParts) { - if (part != null) { - graphics.drawRectangle(part.getBounds().getCopy().translate(bx, by)); - } - } - } - - // Draw the target line, if any - if (mHighlightInfo.linePoints != null) { - int x1 = mHighlightInfo.linePoints[0].x; - int y1 = mHighlightInfo.linePoints[0].y; - int x2 = mHighlightInfo.linePoints[1].x; - int y2 = mHighlightInfo.linePoints[1].y; - - // if the line is right to the edge, draw it one pixel more inside so that the - // full 2-pixel width be visible. - if (x1 <= 0) x1++; - if (x2 <= 0) x2++; - if (y1 <= 0) y1++; - if (y2 <= 0) y2++; - - if (x1 >= w - 1) x1--; - if (x2 >= w - 1) x2--; - if (y1 >= h - 1) y1--; - if (y2 >= h - 1) y2--; - - x1 += bx; - x2 += bx; - y1 += by; - y2 += by; - - graphics.setLineWidth(2); - graphics.setLineStyle(SWT.LINE_DASH); - graphics.setLineCap(SWT.CAP_ROUND); - graphics.setForegroundColor(ColorConstants.orange); - graphics.drawLine(x1, y1, x2, y2); - } - - // Draw the anchor point, if any - if (mHighlightInfo.anchorPoint != null) { - int x = mHighlightInfo.anchorPoint.x; - int y = mHighlightInfo.anchorPoint.y; - - // If the point is right on the edge, draw it one pixel inside so that it - // matches the highlight line. It makes it slightly more visible that way. - if (x <= 0) x++; - if (y <= 0) y++; - if (x >= w - 1) x--; - if (y >= h - 1) y--; - x += bx; - y += by; - - graphics.setLineWidth(2); - graphics.setLineStyle(SWT.LINE_SOLID); - graphics.setLineCap(SWT.CAP_ROUND); - graphics.setForegroundColor(ColorConstants.orange); - graphics.drawLine(x-5, y-5, x+5, y+5); - graphics.drawLine(x-5, y+5, x+5, y-5); - // 7 * cos(45) == 5 so we use 8 for the circle radius (it looks slightly better than 7) - graphics.setLineWidth(1); - graphics.drawOval(x-8, y-8, 16, 16); - } - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiDocumentEditPart.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiDocumentEditPart.java deleted file mode 100644 index 9f6557c..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiDocumentEditPart.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.adt.internal.editors.layout.parts; - -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiDocumentNode; -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; - -import org.eclipse.draw2d.AbstractBackground; -import org.eclipse.draw2d.ColorConstants; -import org.eclipse.draw2d.FreeformLayer; -import org.eclipse.draw2d.FreeformLayout; -import org.eclipse.draw2d.Graphics; -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.Label; -import org.eclipse.draw2d.geometry.Insets; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.gef.EditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.Request; -import org.eclipse.gef.RequestConstants; -import org.eclipse.gef.editpolicies.RootComponentEditPolicy; -import org.eclipse.gef.requests.DropRequest; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.PaletteData; -import org.eclipse.swt.widgets.Display; - -import java.awt.image.BufferedImage; -import java.awt.image.DataBufferInt; - -/** - * Graphical edit part for the root document. - *

- * It acts as a simple container. - * - * @since GLE1 - */ -public class UiDocumentEditPart extends UiElementEditPart { - - private Display mDisplay; - private FreeformLayer mLayer; - private ImageBackground mImage; - private Label mChild = null; - - final static class ImageBackground extends AbstractBackground { - - private BufferedImage mBufferedImage; - private Image mImage; - - ImageBackground() { - } - - ImageBackground(BufferedImage image, Display display) { - setImage(image, display); - } - - @Override - public void paintBackground(IFigure figure, Graphics graphics, Insets insets) { - if (mImage != null) { - Rectangle rect = getPaintRectangle(figure, insets); - graphics.drawImage(mImage, rect.x, rect.y); - } - } - - void setImage(BufferedImage image, Display display) { - if (image != null) { - int[] data = ((DataBufferInt)image.getData().getDataBuffer()).getData(); - - ImageData imageData = new ImageData(image.getWidth(), image.getHeight(), 32, - new PaletteData(0x00FF0000, 0x0000FF00, 0x000000FF)); - - imageData.setPixels(0, 0, data.length, data, 0); - - mImage = new Image(display, imageData); - } else { - mImage = null; - } - } - - BufferedImage getBufferedImage() { - return mBufferedImage; - } - } - - public UiDocumentEditPart(UiDocumentNode uiDocumentNode, Display display) { - super(uiDocumentNode); - mDisplay = display; - } - - @Override - protected IFigure createFigure() { - mLayer = new FreeformLayer(); - mLayer.setLayoutManager(new FreeformLayout()); - - mLayer.setOpaque(true); - mLayer.setBackgroundColor(ColorConstants.lightGray); - - return mLayer; - } - - @Override - protected void refreshVisuals() { - UiElementNode model = (UiElementNode)getModel(); - - Object editData = model.getEditData(); - if (editData instanceof BufferedImage) { - BufferedImage image = (BufferedImage)editData; - - if (mImage == null || image != mImage.getBufferedImage()) { - mImage = new ImageBackground(image, mDisplay); - } - - mLayer.setBorder(mImage); - - if (mChild != null && mChild.getParent() == mLayer) { - mLayer.remove(mChild); - } - } else if (editData instanceof String) { - mLayer.setBorder(null); - if (mChild == null) { - mChild = new Label(); - } - mChild.setText((String)editData); - - if (mChild != null && mChild.getParent() != mLayer) { - mLayer.add(mChild); - } - Rectangle bounds = mChild.getTextBounds(); - bounds.x = bounds.y = 0; - mLayer.setConstraint(mChild, bounds); - } - - // refresh the children as well - refreshChildrenVisuals(); - } - - @Override - protected void hideSelection() { - // no selection at this level. - } - - @Override - protected void showSelection() { - // no selection at this level. - } - - @Override - protected void createEditPolicies() { - super.createEditPolicies(); - - // This policy indicates this a root component that cannot be removed - installEditPolicy(EditPolicy.COMPONENT_ROLE, new RootComponentEditPolicy()); - - installLayoutEditPolicy(this); - } - - /** - * Returns the EditPart that should be used as the target for the specified Request. - * For instance this is called during drag'n'drop with a CreateRequest. - *

- * For the root document, we want the first child edit part to the be the target - * since an XML document can have only one root element. - * - * {@inheritDoc} - */ - @Override - public EditPart getTargetEditPart(Request request) { - if (request != null && request.getType() == RequestConstants.REQ_CREATE) { - // We refuse the drop if it's not in the bounds of the document. - if (request instanceof DropRequest) { - Point where = ((DropRequest) request).getLocation().getCopy(); - UiElementNode uiNode = getUiNode(); - if (uiNode instanceof UiDocumentNode) { - // Take the bounds of the background image as the valid drop zone - Object editData = uiNode.getEditData(); - if (editData instanceof BufferedImage) { - BufferedImage image = (BufferedImage)editData; - int w = image.getWidth(); - int h = image.getHeight(); - if (where.x > w || where.y > h) { - return null; - } - } - - } - } - - // For the root document, we want the first child edit part to the be the target - // since an XML document can have only one root element. - if (getChildren().size() > 0) { - Object o = getChildren().get(0); - if (o instanceof EditPart) { - return ((EditPart) o).getTargetEditPart(request); - } - } - } - return super.getTargetEditPart(request); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiDocumentTreeEditPart.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiDocumentTreeEditPart.java deleted file mode 100644 index b78c519..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiDocumentTreeEditPart.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.adt.internal.editors.layout.parts; - -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiDocumentNode; - -import java.util.List; - -/** - * Implementation of {@link UiElementTreeEditPart} for the document root. - * - * @since GLE1 - */ -public class UiDocumentTreeEditPart extends UiElementTreeEditPart { - - public UiDocumentTreeEditPart(UiDocumentNode model) { - super(model); - } - - @SuppressWarnings("unchecked") - @Override - protected List getModelChildren() { - return getUiNode().getUiChildren(); - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiElementEditPart.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiElementEditPart.java deleted file mode 100644 index 75c7b6d..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiElementEditPart.java +++ /dev/null @@ -1,347 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.adt.internal.editors.layout.parts; - -import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor; -import com.android.ide.eclipse.adt.internal.editors.uimodel.IUiUpdateListener; -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; -import com.android.sdklib.SdkConstants; - -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.draw2d.geometry.Rectangle; -import org.eclipse.gef.DragTracker; -import org.eclipse.gef.EditPart; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.GraphicalEditPart; -import org.eclipse.gef.Request; -import org.eclipse.gef.RequestConstants; -import org.eclipse.gef.commands.Command; -import org.eclipse.gef.editparts.AbstractGraphicalEditPart; -import org.eclipse.gef.editpolicies.LayoutEditPolicy; -import org.eclipse.gef.editpolicies.SelectionEditPolicy; -import org.eclipse.gef.requests.CreateRequest; -import org.eclipse.gef.requests.DropRequest; -import org.eclipse.gef.tools.SelectEditPartTracker; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - -import java.util.List; - -/** - * An {@link EditPart} for a {@link UiElementNode}. - * - * @since GLE1 - */ -public abstract class UiElementEditPart extends AbstractGraphicalEditPart - implements IUiUpdateListener { - - public UiElementEditPart(UiElementNode uiElementNode) { - setModel(uiElementNode); - } - - //------------------------- - // Derived classes must define these - - abstract protected void hideSelection(); - abstract protected void showSelection(); - - //------------------------- - // Base class overrides - - @Override - public DragTracker getDragTracker(Request request) { - return new SelectEditPartTracker(this); - } - - @Override - protected void createEditPolicies() { - /* - * This is no longer needed, as a selection edit policy is set by the parent layout. - * Leave this code commented out right now, I'll want to play with this later. - * - installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, - new NonResizableSelectionEditPolicy(this)); - */ - } - - /* (non-javadoc) - * Returns a List containing the children model objects. - * Must not return null, instead use the super which returns an empty list. - */ - @SuppressWarnings("unchecked") - @Override - protected List getModelChildren() { - return getUiNode().getUiChildren(); - } - - @Override - public void activate() { - super.activate(); - getUiNode().addUpdateListener(this); - } - - @Override - public void deactivate() { - super.deactivate(); - getUiNode().removeUpdateListener(this); - } - - @Override - protected void refreshVisuals() { - if (getFigure().getParent() != null) { - ((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), getBounds()); - } - - // update the visuals of the children as well - refreshChildrenVisuals(); - } - - protected void refreshChildrenVisuals() { - if (children != null) { - for (Object child : children) { - if (child instanceof UiElementEditPart) { - UiElementEditPart childPart = (UiElementEditPart)child; - childPart.refreshVisuals(); - } - } - } - } - - //------------------------- - // IUiUpdateListener implementation - - public void uiElementNodeUpdated(UiElementNode ui_node, UiUpdateState state) { - // TODO: optimize by refreshing only when needed - switch(state) { - case ATTR_UPDATED: - refreshVisuals(); - break; - case CHILDREN_CHANGED: - refreshChildren(); - - // new children list, need to update the layout - refreshVisuals(); - break; - case CREATED: - refreshVisuals(); - break; - case DELETED: - // pass - break; - } - } - - //------------------------- - // Local methods - - /** @return The object model casted to an {@link UiElementNode} */ - public final UiElementNode getUiNode() { - return (UiElementNode) getModel(); - } - - protected final ElementDescriptor getDescriptor() { - return getUiNode().getDescriptor(); - } - - protected final UiElementEditPart getEditPartParent() { - EditPart parent = getParent(); - if (parent instanceof UiElementEditPart) { - return (UiElementEditPart)parent; - } - return null; - } - - /** - * Returns a given XML attribute. - * @param attrName The local name of the attribute. - * @return the attribute as a {@link String}, if it exists, or null - */ - protected final String getStringAttr(String attrName) { - UiElementNode uiNode = getUiNode(); - if (uiNode.getXmlNode() != null) { - Node xmlNode = uiNode.getXmlNode(); - if (xmlNode != null) { - NamedNodeMap nodeAttributes = xmlNode.getAttributes(); - if (nodeAttributes != null) { - Node attr = nodeAttributes.getNamedItemNS( - SdkConstants.NS_RESOURCES, attrName); - if (attr != null) { - return attr.getNodeValue(); - } - } - } - } - return null; - } - - protected final Rectangle getBounds() { - UiElementNode model = (UiElementNode)getModel(); - - Object editData = model.getEditData(); - - if (editData != null) { - // assert with fully qualified class name to prevent import changes to another - // Rectangle class. - assert (editData instanceof org.eclipse.draw2d.geometry.Rectangle); - - return (Rectangle)editData; - } - - // return a dummy rect - return new Rectangle(0, 0, 0, 0); - } - - /** - * Returns the EditPart that should be used as the target for the specified Request. - *

- * For instance this is called during drag'n'drop with a CreateRequest. - *

- * Reject being a target for elements which descriptor does not allow children. - * - * {@inheritDoc} - */ - @Override - public EditPart getTargetEditPart(Request request) { - if (request != null && request.getType() == RequestConstants.REQ_CREATE) { - // Reject being a target for elements which descriptor does not allow children. - if (!getUiNode().getDescriptor().hasChildren()) { - return null; - } - } - return super.getTargetEditPart(request); - } - - /** - * Used by derived classes {@link UiDocumentEditPart} and {@link UiLayoutEditPart} - * to accept drag'n'drop of new items from the palette. - * - * @param layoutEditPart The layout edit part where this policy is installed. It can - * be either a {@link UiDocumentEditPart} or a {@link UiLayoutEditPart}. - */ - protected void installLayoutEditPolicy(final UiElementEditPart layoutEditPart) { - // This policy indicates how elements can be constrained by the layout. - // TODO Right now we use the XY layout policy since our constraints are - // handled by the android rendering engine rather than GEF. Tweak as - // appropriate. - installEditPolicy(EditPolicy.LAYOUT_ROLE, new LayoutEditPolicy() { - - /** - * We don't allow layout children to be resized yet. - *

- * Typical choices would be: - *

    - *
  • ResizableEditPolicy, to allow for selection, move and resize. - *
  • NonResizableEditPolicy, to allow for selection, move but not resize. - *
  • SelectionEditPolicy to allow for only selection. - *
- *

- * TODO: make this depend on the part layout. For an AbsoluteLayout we should - * probably use a NonResizableEditPolicy and SelectionEditPolicy for the rest. - * Whether to use ResizableEditPolicy or NonResizableEditPolicy should depend - * on the child in an AbsoluteLayout. - */ - @Override - protected EditPolicy createChildEditPolicy(EditPart child) { - if (child instanceof UiElementEditPart) { - return new NonResizableSelectionEditPolicy((UiElementEditPart) child); - } - return null; - } - - @Override - protected Command getCreateCommand(CreateRequest request) { - // We store the ElementDescriptor in the request.factory.type - Object newType = request.getNewObjectType(); - if (newType instanceof ElementDescriptor) { - Point where = request.getLocation().getCopy(); - Point origin = getLayoutContainer().getClientArea().getLocation(); - where.translate(origin.getNegated()); - - // The host is the EditPart where this policy is installed, - // e.g. this UiElementEditPart. - EditPart host = getHost(); - if (host instanceof UiElementEditPart) { - - return new ElementCreateCommand((ElementDescriptor) newType, - (UiElementEditPart) host, - where); - } - } - - return null; - } - - @Override - protected Command getMoveChildrenCommand(Request request) { - // TODO Auto-generated method stub - return null; - } - - @Override - public void showLayoutTargetFeedback(Request request) { - super.showLayoutTargetFeedback(request); - - // for debugging - // System.out.println("target: " + request.toString() + " -- " + layoutEditPart.getUiNode().getBreadcrumbTrailDescription(false)); - - if (layoutEditPart instanceof UiLayoutEditPart && - request instanceof DropRequest) { - Point where = ((DropRequest) request).getLocation().getCopy(); - Point origin = getLayoutContainer().getClientArea().getLocation(); - where.translate(origin.getNegated()); - - ((UiLayoutEditPart) layoutEditPart).showDropTarget(where); - } - } - - @Override - protected void eraseLayoutTargetFeedback(Request request) { - super.eraseLayoutTargetFeedback(request); - if (layoutEditPart instanceof UiLayoutEditPart) { - ((UiLayoutEditPart) layoutEditPart).hideDropTarget(); - } - } - - @Override - protected IFigure createSizeOnDropFeedback(CreateRequest createRequest) { - // TODO understand if this is useful for us or remove - return super.createSizeOnDropFeedback(createRequest); - } - - }); - } - - protected static class NonResizableSelectionEditPolicy extends SelectionEditPolicy { - - private final UiElementEditPart mEditPart; - - public NonResizableSelectionEditPolicy(UiElementEditPart editPart) { - mEditPart = editPart; - } - - @Override - protected void hideSelection() { - mEditPart.hideSelection(); - } - - @Override - protected void showSelection() { - mEditPart.showSelection(); - } - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiElementTreeEditPart.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiElementTreeEditPart.java deleted file mode 100644 index 81737f8..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiElementTreeEditPart.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.adt.internal.editors.layout.parts; - -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; - -import org.eclipse.gef.editparts.AbstractTreeEditPart; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.views.contentoutline.IContentOutlinePage; - -/** - * Base {@link AbstractTreeEditPart} to represent {@link UiElementNode} objects in the - * {@link IContentOutlinePage} linked to the layout editor. - * - * @since GLE1 - */ -public class UiElementTreeEditPart extends AbstractTreeEditPart { - - public UiElementTreeEditPart(UiElementNode uiElementNode) { - setModel(uiElementNode); - } - - @Override - protected void createEditPolicies() { - // TODO Auto-generated method stub - super.createEditPolicies(); - } - - @Override - protected Image getImage() { - return getUiNode().getDescriptor().getIcon(); - } - - @Override - protected String getText() { - return getUiNode().getShortDescription(); - } - - @Override - public void activate() { - if (!isActive()) { - super.activate(); - // TODO - } - } - - @Override - public void deactivate() { - if (isActive()) { - super.deactivate(); - // TODO - } - } - - /** - * Returns the casted model object represented by this {@link AbstractTreeEditPart}. - */ - protected UiElementNode getUiNode() { - return (UiElementNode)getModel(); - } - -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiElementTreeEditPartFactory.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiElementTreeEditPartFactory.java deleted file mode 100644 index c10298c..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiElementTreeEditPartFactory.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.adt.internal.editors.layout.parts; - -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiDocumentNode; -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; - -import org.eclipse.gef.EditPart; -import org.eclipse.gef.EditPartFactory; -import org.eclipse.gef.editparts.AbstractTreeEditPart; -import org.eclipse.ui.views.contentoutline.IContentOutlinePage; - -/** - * {@link EditPartFactory} to create {@link AbstractTreeEditPart} for {@link UiElementNode} objects. - * These objects are used in the {@link IContentOutlinePage} linked to the layout editor. - * - * @since GLE1 - */ -public class UiElementTreeEditPartFactory implements EditPartFactory { - - public EditPart createEditPart(EditPart context, Object model) { - if (model instanceof UiDocumentNode) { - return new UiDocumentTreeEditPart((UiDocumentNode) model); - } else if (model instanceof UiElementNode) { - UiElementNode node = (UiElementNode) model; - if (node.getDescriptor().hasChildren()) { - return new UiLayoutTreeEditPart(node); - } else { - return new UiViewTreeEditPart(node); - } - } - return null; - } - -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiElementsEditPartFactory.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiElementsEditPartFactory.java deleted file mode 100644 index 31a1e2e..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiElementsEditPartFactory.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.adt.internal.editors.layout.parts; - -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiDocumentNode; -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; - -import org.eclipse.gef.EditPart; -import org.eclipse.gef.EditPartFactory; -import org.eclipse.swt.widgets.Display; - -/** - * A factory that returns the appropriate {@link EditPart} for a given model object. - *

- * The only model objects we use are {@link UiElementNode} objects and they are - * edited using {@link UiElementEditPart}. - * - * @since GLE1 - */ -public class UiElementsEditPartFactory implements EditPartFactory { - - private Display mDisplay; - private boolean mShowOutline = false; - private IOutlineProvider mProvider; - - public interface IOutlineProvider { - boolean hasOutline(); - } - - public UiElementsEditPartFactory(Display display, IOutlineProvider provider) { - mDisplay = display; - mProvider = provider; - } - - public EditPart createEditPart(EditPart context, Object model) { - if (model instanceof UiDocumentNode) { - return new UiDocumentEditPart((UiDocumentNode) model, mDisplay); - } else if (model instanceof UiElementNode) { - UiElementNode node = (UiElementNode) model; - - if (node.getDescriptor().hasChildren()) { - return new UiLayoutEditPart(node, mProvider); - } - - return new UiViewEditPart(node); - } - return null; - } - - public void setShowOutline(boolean showOutline) { - mShowOutline = showOutline; - } - -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiLayoutEditPart.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiLayoutEditPart.java deleted file mode 100644 index d0495e2..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiLayoutEditPart.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.adt.internal.editors.layout.parts; - -import com.android.ide.eclipse.adt.internal.editors.layout.parts.UiElementsEditPartFactory.IOutlineProvider; -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; - -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.XYLayout; -import org.eclipse.draw2d.geometry.Point; -import org.eclipse.gef.EditPolicy; -import org.eclipse.gef.commands.Command; -import org.eclipse.gef.editpolicies.ContainerEditPolicy; -import org.eclipse.gef.requests.CreateRequest; - -/** - * Graphical edit part for an {@link UiElementNode} that represents a ViewLayout. - *

- * It acts as a simple container. - * - * @since GLE1 - */ -public final class UiLayoutEditPart extends UiElementEditPart { - - static class HighlightInfo { - public boolean drawDropBorder; - public UiElementEditPart[] childParts; - public Point anchorPoint; - public Point linePoints[]; - - public final Point tempPoints[] = new Point[] { new Point(), new Point() }; - - public void clear() { - drawDropBorder = false; - childParts = null; - anchorPoint = null; - linePoints = null; - } - } - - private final HighlightInfo mHighlightInfo = new HighlightInfo(); - private final IOutlineProvider mProvider; - - public UiLayoutEditPart(UiElementNode uiElementNode, IOutlineProvider provider) { - super(uiElementNode); - mProvider = provider; - } - - @Override - protected void createEditPolicies() { - super.createEditPolicies(); - - installEditPolicy(EditPolicy.CONTAINER_ROLE, new ContainerEditPolicy() { - @Override - protected Command getCreateCommand(CreateRequest request) { - return null; - } - }); - - installLayoutEditPolicy(this); - } - - @Override - protected IFigure createFigure() { - IFigure f = new LayoutFigure(mProvider); - f.setLayoutManager(new XYLayout()); - return f; - } - - @Override - protected void showSelection() { - IFigure f = getFigure(); - if (f instanceof ElementFigure) { - ((ElementFigure) f).setSelected(true); - } - } - - @Override - protected void hideSelection() { - IFigure f = getFigure(); - if (f instanceof ElementFigure) { - ((ElementFigure) f).setSelected(false); - } - } - - public void showDropTarget(Point where) { - if (where != null) { - mHighlightInfo.clear(); - mHighlightInfo.drawDropBorder = true; - DropFeedback.computeDropFeedback(this, mHighlightInfo, where); - - IFigure f = getFigure(); - if (f instanceof LayoutFigure) { - ((LayoutFigure) f).setHighlighInfo(mHighlightInfo); - } - } - } - - public void hideDropTarget() { - mHighlightInfo.clear(); - IFigure f = getFigure(); - if (f instanceof LayoutFigure) { - ((LayoutFigure) f).setHighlighInfo(mHighlightInfo); - } - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiLayoutTreeEditPart.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiLayoutTreeEditPart.java deleted file mode 100644 index 5e78b46..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiLayoutTreeEditPart.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.adt.internal.editors.layout.parts; - -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; - -import java.util.List; - -/** - * Implementation of {@link UiElementTreeEditPart} for layout objects. - * - * @since GLE1 - */ -public class UiLayoutTreeEditPart extends UiElementTreeEditPart { - - public UiLayoutTreeEditPart(UiElementNode node) { - super(node); - } - - @SuppressWarnings("unchecked") - @Override - protected List getModelChildren() { - return getUiNode().getUiChildren(); - } - - -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiViewEditPart.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiViewEditPart.java deleted file mode 100644 index f90bd67..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiViewEditPart.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.adt.internal.editors.layout.parts; - -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; - -import org.eclipse.draw2d.IFigure; -import org.eclipse.draw2d.XYLayout; - -/** - * Graphical edit part for an {@link UiElementNode} that represents a View. - * - * @since GLE1 - */ -public class UiViewEditPart extends UiElementEditPart { - - public UiViewEditPart(UiElementNode uiElementNode) { - super(uiElementNode); - } - - @Override - protected IFigure createFigure() { - IFigure f = new ElementFigure(null); - f.setLayoutManager(new XYLayout()); - return f; - } - - @Override - protected void showSelection() { - IFigure f = getFigure(); - if (f instanceof ElementFigure) { - ((ElementFigure) f).setSelected(true); - } - } - - @Override - protected void hideSelection() { - IFigure f = getFigure(); - if (f instanceof ElementFigure) { - ((ElementFigure) f).setSelected(false); - } - } -} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiViewTreeEditPart.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiViewTreeEditPart.java deleted file mode 100644 index 22cc952..0000000 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/parts/UiViewTreeEditPart.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Eclipse Public License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.eclipse.org/org/documents/epl-v10.php - * - * 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.android.ide.eclipse.adt.internal.editors.layout.parts; - -import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; - -/** - * Implementation of {@link UiElementTreeEditPart} for view objects. - * - * @since GLE1 - */ -public class UiViewTreeEditPart extends UiElementTreeEditPart { - - public UiViewTreeEditPart(UiElementNode node) { - super(node); - } - -} -- cgit v1.1