Merge change 22555 into eclair

* changes:
  ADT: Skeleton for GLE2.
This commit is contained in:
Android (Google) Code Review
2009-08-25 14:43:37 -07:00
5 changed files with 317 additions and 141 deletions

View File

@@ -0,0 +1,172 @@
/*
* Copyright (C) 2009 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;
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 org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.gef.ui.parts.SelectionSynchronizer;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;
/**
* Graphical layout editor, version 2.
*/
public class GLE2 extends EditorPart implements IGraphicalLayoutEditor {
/*
* Useful notes:
* To understand Drag'n'drop:
* http://www.eclipse.org/articles/Article-Workbench-DND/drag_drop.html
*/
/** Reference to the layout editor */
private final LayoutEditor mLayoutEditor;
public GLE2(LayoutEditor layoutEditor) {
mLayoutEditor = layoutEditor;
setPartName("Graphical Layout");
}
// ------------------------------------
// Methods overridden from base classes
//------------------------------------
/**
* Initializes the editor part with a site and input.
* {@inheritDoc}
*/
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
setSite(site);
setInput(input);
}
@Override
public void dispose() {
super.dispose();
}
@Override
public void doSave(IProgressMonitor monitor) {
// TODO Auto-generated method stub
}
@Override
public void doSaveAs() {
// TODO Auto-generated method stub
}
@Override
public boolean isDirty() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isSaveAsAllowed() {
// TODO Auto-generated method stub
return false;
}
@Override
public void createPartControl(Composite parent) {
// TODO Auto-generated method stub
}
@Override
public void setFocus() {
// TODO Auto-generated method stub
}
public void activated() {
// TODO Auto-generated method stub
}
public void deactivated() {
// TODO Auto-generated method stub
}
public void editNewFile(FolderConfiguration configuration) {
// TODO Auto-generated method stub
}
public Clipboard getClipboard() {
// TODO Auto-generated method stub
return null;
}
public LayoutEditor getLayoutEditor() {
// TODO Auto-generated method stub
return null;
}
public UiDocumentNode getModel() {
// TODO Auto-generated method stub
return null;
}
public SelectionSynchronizer getSelectionSynchronizer() {
// TODO Auto-generated method stub
return null;
}
public void onXmlModelChanged() {
// TODO Auto-generated method stub
}
public void recomputeLayout() {
// TODO Auto-generated method stub
}
public void reloadEditor() {
// TODO Auto-generated method stub
}
public void reloadPalette() {
// TODO Auto-generated method stub
}
public void selectModel(UiElementNode uiNodeModel) {
// TODO Auto-generated method stub
}
public void reloadLayout(boolean codeChange, boolean rChange,
boolean resChange) {
// TODO Auto-generated method stub
}
}

View File

@@ -19,7 +19,6 @@ package com.android.ide.eclipse.adt.internal.editors.layout;
import com.android.ide.eclipse.adt.AdtPlugin; import com.android.ide.eclipse.adt.AdtPlugin;
import com.android.ide.eclipse.adt.internal.editors.IconFactory; import com.android.ide.eclipse.adt.internal.editors.IconFactory;
import com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor.UiEditorActions; import com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor.UiEditorActions;
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.ConfigurationComposite;
import com.android.ide.eclipse.adt.internal.editors.layout.configuration.ConfigurationComposite.IConfigListener; 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.descriptors.ViewElementDescriptor;
@@ -71,6 +70,8 @@ import org.eclipse.gef.dnd.TemplateTransferDropTargetListener;
import org.eclipse.gef.editparts.ScalableFreeformRootEditPart; import org.eclipse.gef.editparts.ScalableFreeformRootEditPart;
import org.eclipse.gef.palette.PaletteRoot; import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.gef.requests.CreationFactory; 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.Action;
import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IMenuManager;
@@ -111,8 +112,8 @@ import java.util.Map;
* <p/> * <p/>
* To understand Drag'n'drop: http://www.eclipse.org/articles/Article-Workbench-DND/drag_drop.html * To understand Drag'n'drop: http://www.eclipse.org/articles/Article-Workbench-DND/drag_drop.html
*/ */
public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor public class GraphicalLayoutEditor extends GraphicalEditorWithPalette
implements ILayoutReloadListener, IConfigListener { implements IGraphicalLayoutEditor, IConfigListener {
/** Reference to the layout editor */ /** Reference to the layout editor */
@@ -233,6 +234,31 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
super.dispose(); super.dispose();
} }
/**
* Returns the selection synchronizer object.
* The synchronizer can be used to sync the selection of 2 or more EditPartViewers.
* <p/>
* 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.
* <p/>
* 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) /* (non-Javadoc)
* Creates the palette root. * Creates the palette root.
*/ */
@@ -243,7 +269,6 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
return mPaletteRoot; return mPaletteRoot;
} }
@Override
public Clipboard getClipboard() { public Clipboard getClipboard() {
return mClipboard; return mClipboard;
} }
@@ -365,8 +390,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
* *
* @param uiNodeModel The {@link UiElementNode} to select. * @param uiNodeModel The {@link UiElementNode} to select.
*/ */
@Override public void selectModel(UiElementNode uiNodeModel) {
void selectModel(UiElementNode uiNodeModel) {
GraphicalViewer viewer = getGraphicalViewer(); GraphicalViewer viewer = getGraphicalViewer();
// Give focus to the graphical viewer (in case the outline has it) // Give focus to the graphical viewer (in case the outline has it)
@@ -384,7 +408,6 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
// Local methods // Local methods
//-------------- //--------------
@Override
public LayoutEditor getLayoutEditor() { public LayoutEditor getLayoutEditor() {
return mLayoutEditor; return mLayoutEditor;
} }
@@ -514,8 +537,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
* Sets the UI for the edition of a new file. * Sets the UI for the edition of a new file.
* @param configuration the configuration of the new file. * @param configuration the configuration of the new file.
*/ */
@Override public void editNewFile(FolderConfiguration configuration) {
void editNewFile(FolderConfiguration configuration) {
// update the configuration UI // update the configuration UI
setConfiguration(configuration, true /*force*/); setConfiguration(configuration, true /*force*/);
@@ -625,8 +647,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
/** /**
* Reloads this editor, by getting the new model from the {@link LayoutEditor}. * Reloads this editor, by getting the new model from the {@link LayoutEditor}.
*/ */
@Override public void reloadEditor() {
void reloadEditor() {
GraphicalViewer viewer = getGraphicalViewer(); GraphicalViewer viewer = getGraphicalViewer();
viewer.setContents(getModel()); viewer.setContents(getModel());
@@ -647,8 +668,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
/** /**
* Callback for XML model changed. Only update/recompute the layout if the editor is visible * Callback for XML model changed. Only update/recompute the layout if the editor is visible
*/ */
@Override public void onXmlModelChanged() {
void onXmlModelChanged() {
if (mLayoutEditor.isGraphicalEditorActive()) { if (mLayoutEditor.isGraphicalEditorActive()) {
doXmlReload(true /* force */); doXmlReload(true /* force */);
recomputeLayout(); recomputeLayout();
@@ -697,13 +717,11 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
} }
@Override public UiDocumentNode getModel() {
UiDocumentNode getModel() {
return mLayoutEditor.getUiRootNode(); return mLayoutEditor.getUiRootNode();
} }
@Override public void reloadPalette() {
void reloadPalette() {
PaletteFactory.createPaletteRoot(mPaletteRoot, mLayoutEditor.getTargetData()); PaletteFactory.createPaletteRoot(mPaletteRoot, mLayoutEditor.getTargetData());
} }
@@ -794,9 +812,8 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
/** /**
* Recomputes the layout with the help of layoutlib. * Recomputes the layout with the help of layoutlib.
*/ */
@Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
void recomputeLayout() { public void recomputeLayout() {
doXmlReload(false /* force */); doXmlReload(false /* force */);
try { try {
// check that the resource exists. If the file is opened but the project is closed // check that the resource exists. If the file is opened but the project is closed
@@ -1072,8 +1089,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
/** /**
* Responds to a page change that made the Graphical editor page the activated page. * Responds to a page change that made the Graphical editor page the activated page.
*/ */
@Override public void activated() {
void activated() {
if (mNeedsRecompute || mNeedsXmlReload) { if (mNeedsRecompute || mNeedsXmlReload) {
recomputeLayout(); recomputeLayout();
} }
@@ -1082,8 +1098,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
/** /**
* Responds to a page change that made the Graphical editor page the deactivated page * Responds to a page change that made the Graphical editor page the deactivated page
*/ */
@Override public void deactivated() {
void deactivated() {
// nothing to be done here for now. // nothing to be done here for now.
} }
@@ -1093,11 +1108,11 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
if (frameworkRes == null) { if (frameworkRes == null) {
AdtPlugin.log(IStatus.ERROR, "Failed to get ProjectResource for the framework"); 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());
} }
// get the framework resource values based on the current config
mConfiguredFrameworkRes = frameworkRes.getConfiguredResources(
mConfigComposite.getCurrentConfig());
} }
return mConfiguredFrameworkRes; return mConfiguredFrameworkRes;

View File

@@ -4,7 +4,7 @@
* Licensed under the Eclipse Public License, Version 1.0 (the "License"); * 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 not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.eclipse.org/org/documents/epl-v10.php * http://www.eclipse.org/org/documents/epl-v10.php
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
@@ -22,17 +22,14 @@ 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.editors.uimodel.UiElementNode;
import com.android.ide.eclipse.adt.internal.resources.configurations.FolderConfiguration; import com.android.ide.eclipse.adt.internal.resources.configurations.FolderConfiguration;
import org.eclipse.gef.DefaultEditDomain;
import org.eclipse.gef.ui.parts.GraphicalEditorWithPalette;
import org.eclipse.gef.ui.parts.SelectionSynchronizer; import org.eclipse.gef.ui.parts.SelectionSynchronizer;
import org.eclipse.swt.dnd.Clipboard; import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IEditorPart;
/** /**
* Abstract GraphicalLayoutEditor. * Interface defining what {@link LayoutEditor} expects from a GraphicalLayoutEditor part.
*/ */
/*package*/ abstract class AbstractGraphicalLayoutEditor extends GraphicalEditorWithPalette /*package*/ interface IGraphicalLayoutEditor extends IEditorPart, ILayoutReloadListener {
implements IWorkbenchPart, ILayoutReloadListener {
/** /**
* Sets the UI for the edition of a new file. * Sets the UI for the edition of a new file.
@@ -63,7 +60,7 @@ import org.eclipse.ui.IWorkbenchPart;
/** /**
* Used by LayoutEditor.UiEditorActions.selectUiNode to select a new UI Node * Used by LayoutEditor.UiEditorActions.selectUiNode to select a new UI Node
* created by {@link ElementCreateCommand#execute()}. * created by {@link ElementCreateCommand#execute()}.
* *
* @param uiNodeModel The {@link UiElementNode} to select. * @param uiNodeModel The {@link UiElementNode} to select.
*/ */
abstract void selectModel(UiElementNode uiNodeModel); abstract void selectModel(UiElementNode uiNodeModel);
@@ -71,27 +68,8 @@ import org.eclipse.ui.IWorkbenchPart;
/** /**
* Returns the selection synchronizer object. * Returns the selection synchronizer object.
* The synchronizer can be used to sync the selection of 2 or more EditPartViewers. * The synchronizer can be used to sync the selection of 2 or more EditPartViewers.
* <p/>
* This is changed from protected to public so that the outline can use it.
*
* @return the synchronizer
*/ */
@Override abstract public SelectionSynchronizer getSelectionSynchronizer();
public SelectionSynchronizer getSelectionSynchronizer() {
return super.getSelectionSynchronizer();
}
/**
* Returns the edit domain.
* <p/>
* 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();
}
abstract void reloadPalette(); abstract void reloadPalette();

View File

@@ -46,7 +46,7 @@ import org.eclipse.ui.views.properties.IPropertySheetPage;
import org.w3c.dom.Document; import org.w3c.dom.Document;
/** /**
* Multi-page form editor for /res/layout XML files. * Multi-page form editor for /res/layout XML files.
*/ */
public class LayoutEditor extends AndroidEditor implements IShowEditorInput, IPartListener { public class LayoutEditor extends AndroidEditor implements IShowEditorInput, IPartListener {
@@ -54,8 +54,8 @@ public class LayoutEditor extends AndroidEditor implements IShowEditorInput, IPa
/** Root node of the UI element hierarchy */ /** Root node of the UI element hierarchy */
private UiDocumentNode mUiRootNode; private UiDocumentNode mUiRootNode;
private AbstractGraphicalLayoutEditor mGraphicalEditor; private IGraphicalLayoutEditor mGraphicalEditor;
private int mGraphicalEditorIndex; private int mGraphicalEditorIndex;
/** Implementation of the {@link IContentOutlinePage} for this editor */ /** Implementation of the {@link IContentOutlinePage} for this editor */
private UiContentOutlinePage mOutline; private UiContentOutlinePage mOutline;
@@ -63,7 +63,7 @@ public class LayoutEditor extends AndroidEditor implements IShowEditorInput, IPa
private UiPropertySheetPage mPropertyPage; private UiPropertySheetPage mPropertyPage;
private UiEditorActions mUiEditorActions; private UiEditorActions mUiEditorActions;
/** /**
* Creates the form editor for resources XML files. * Creates the form editor for resources XML files.
*/ */
@@ -87,7 +87,7 @@ public class LayoutEditor extends AndroidEditor implements IShowEditorInput, IPa
super.dispose(); super.dispose();
} }
/** /**
* Save the XML. * Save the XML.
* <p/> * <p/>
@@ -105,12 +105,12 @@ public class LayoutEditor extends AndroidEditor implements IShowEditorInput, IPa
mGraphicalEditor.doSave(monitor); mGraphicalEditor.doSave(monitor);
} }
} }
/** /**
* Returns whether the "save as" operation is supported by this editor. * Returns whether the "save as" operation is supported by this editor.
* <p/> * <p/>
* Save-As is a valid operation for the ManifestEditor since it acts on a * Save-As is a valid operation for the ManifestEditor since it acts on a
* single source file. * single source file.
* *
* @see IEditorPart * @see IEditorPart
*/ */
@@ -128,9 +128,15 @@ public class LayoutEditor extends AndroidEditor implements IShowEditorInput, IPa
// The graphical layout editor is now enabled by default. // The graphical layout editor is now enabled by default.
// In case there's an issue we provide a way to disable it using an // In case there's an issue we provide a way to disable it using an
// env variable. // env variable.
if (System.getenv("ANDROID_DISABLE_LAYOUT") == null) { if (System.getenv("ANDROID_DISABLE_LAYOUT") == null) { //$NON-NLS-1$
if (mGraphicalEditor == null) { if (mGraphicalEditor == null) {
mGraphicalEditor = new GraphicalLayoutEditor(this);
if (System.getenv("USE_GLE2") != null) { //$NON-NLS-1$ //$NON-NLS-2$
mGraphicalEditor = new GLE2(this);
} else {
mGraphicalEditor = new GraphicalLayoutEditor(this);
}
mGraphicalEditorIndex = addPage(mGraphicalEditor, getEditorInput()); mGraphicalEditorIndex = addPage(mGraphicalEditor, getEditorInput());
setPageText(mGraphicalEditorIndex, mGraphicalEditor.getTitle()); setPageText(mGraphicalEditorIndex, mGraphicalEditor.getTitle());
} else { } else {
@@ -174,7 +180,7 @@ public class LayoutEditor extends AndroidEditor implements IShowEditorInput, IPa
super.setInputWithNotify(input); super.setInputWithNotify(input);
handleNewInput(input); handleNewInput(input);
} }
/** /**
* Called to replace the current {@link IEditorInput} with another one. * Called to replace the current {@link IEditorInput} with another one.
* <p/>This is used when {@link MatchingStrategy} returned <code>true</code> which means we're * <p/>This is used when {@link MatchingStrategy} returned <code>true</code> which means we're
@@ -183,10 +189,10 @@ public class LayoutEditor extends AndroidEditor implements IShowEditorInput, IPa
public void showEditorInput(IEditorInput editorInput) { public void showEditorInput(IEditorInput editorInput) {
// save the current editor input. // save the current editor input.
doSave(new NullProgressMonitor()); doSave(new NullProgressMonitor());
// get the current page // get the current page
int currentPage = getActivePage(); int currentPage = getActivePage();
// remove the pages, except for the graphical editor, which will be dynamically adapted // remove the pages, except for the graphical editor, which will be dynamically adapted
// to the new model. // to the new model.
// page after the graphical editor: // page after the graphical editor:
@@ -198,10 +204,10 @@ public class LayoutEditor extends AndroidEditor implements IShowEditorInput, IPa
for (int i = mGraphicalEditorIndex - 1 ; i >= 0 ; i--) { for (int i = mGraphicalEditorIndex - 1 ; i >= 0 ; i--) {
removePage(i); removePage(i);
} }
// set the current input. // set the current input.
setInputWithNotify(editorInput); setInputWithNotify(editorInput);
// re-create or reload the pages with the default page shown as the previous active page. // re-create or reload the pages with the default page shown as the previous active page.
createAndroidPages(); createAndroidPages();
selectDefaultPage(Integer.toString(currentPage)); selectDefaultPage(Integer.toString(currentPage));
@@ -211,10 +217,10 @@ public class LayoutEditor extends AndroidEditor implements IShowEditorInput, IPa
mOutline.reloadModel(); mOutline.reloadModel();
} }
} }
/** /**
* Processes the new XML Model, which XML root node is given. * Processes the new XML Model, which XML root node is given.
* *
* @param xml_doc The XML document, if available, or null if none exists. * @param xml_doc The XML document, if available, or null if none exists.
*/ */
@Override @Override
@@ -226,16 +232,16 @@ public class LayoutEditor extends AndroidEditor implements IShowEditorInput, IPa
// update the model first, since it is used by the viewers. // update the model first, since it is used by the viewers.
super.xmlModelChanged(xml_doc); super.xmlModelChanged(xml_doc);
if (mGraphicalEditor != null) { if (mGraphicalEditor != null) {
mGraphicalEditor.onXmlModelChanged(); mGraphicalEditor.onXmlModelChanged();
} }
if (mOutline != null) { if (mOutline != null) {
mOutline.reloadModel(); mOutline.reloadModel();
} }
} }
/* (non-java doc) /* (non-java doc)
* Returns the IContentOutlinePage when asked for it. * Returns the IContentOutlinePage when asked for it.
*/ */
@@ -246,29 +252,33 @@ public class LayoutEditor extends AndroidEditor implements IShowEditorInput, IPa
// This fixes the case where a layout file is opened in XML view first and the outline // This fixes the case where a layout file is opened in XML view first and the outline
// gets stuck in the XML outline. // gets stuck in the XML outline.
if (IContentOutlinePage.class == adapter && mGraphicalEditor != null) { if (IContentOutlinePage.class == adapter && mGraphicalEditor != null) {
if (mOutline == null) {
mOutline = new UiContentOutlinePage(mGraphicalEditor, new TreeViewer()); if (mOutline == null && mGraphicalEditor instanceof GraphicalLayoutEditor) {
// TODO add support for GLE2
mOutline = new UiContentOutlinePage(
(GraphicalLayoutEditor) mGraphicalEditor,
new TreeViewer());
} }
return mOutline; return mOutline;
} }
if (IPropertySheetPage.class == adapter && mGraphicalEditor != null) { if (IPropertySheetPage.class == adapter && mGraphicalEditor != null) {
if (mPropertyPage == null) { if (mPropertyPage == null) {
mPropertyPage = new UiPropertySheetPage(); mPropertyPage = new UiPropertySheetPage();
} }
return mPropertyPage; return mPropertyPage;
} }
// return default // return default
return super.getAdapter(adapter); return super.getAdapter(adapter);
} }
@Override @Override
protected void pageChange(int newPageIndex) { protected void pageChange(int newPageIndex) {
super.pageChange(newPageIndex); super.pageChange(newPageIndex);
if (mGraphicalEditor != null) { if (mGraphicalEditor != null) {
if (newPageIndex == mGraphicalEditorIndex) { if (newPageIndex == mGraphicalEditorIndex) {
mGraphicalEditor.activated(); mGraphicalEditor.activated();
@@ -277,9 +287,9 @@ public class LayoutEditor extends AndroidEditor implements IShowEditorInput, IPa
} }
} }
} }
// ----- IPartListener Methods ---- // ----- IPartListener Methods ----
public void partActivated(IWorkbenchPart part) { public void partActivated(IWorkbenchPart part) {
if (part == this) { if (part == this) {
if (mGraphicalEditor != null) { if (mGraphicalEditor != null) {
@@ -312,7 +322,7 @@ public class LayoutEditor extends AndroidEditor implements IShowEditorInput, IPa
EclipseUiHelper.showView(EclipseUiHelper.CONTENT_OUTLINE_VIEW_ID, false /* activate */); EclipseUiHelper.showView(EclipseUiHelper.CONTENT_OUTLINE_VIEW_ID, false /* activate */);
EclipseUiHelper.showView(EclipseUiHelper.PROPERTY_SHEET_VIEW_ID, false /* activate */); EclipseUiHelper.showView(EclipseUiHelper.PROPERTY_SHEET_VIEW_ID, false /* activate */);
} }
public class UiEditorActions extends UiActions { public class UiEditorActions extends UiActions {
@Override @Override
@@ -331,16 +341,16 @@ public class LayoutEditor extends AndroidEditor implements IShowEditorInput, IPa
// Pass. There is nothing to commit before the XML is changed here. // Pass. There is nothing to commit before the XML is changed here.
} }
} }
public UiEditorActions getUiEditorActions() { public UiEditorActions getUiEditorActions() {
if (mUiEditorActions == null) { if (mUiEditorActions == null) {
mUiEditorActions = new UiEditorActions(); mUiEditorActions = new UiEditorActions();
} }
return mUiEditorActions; return mUiEditorActions;
} }
// ---- Local Methods ---- // ---- Local Methods ----
/** /**
* Returns true if the Graphics editor page is visible. This <b>must</b> be * Returns true if the Graphics editor page is visible. This <b>must</b> be
* called from the UI thread. * called from the UI thread.
@@ -357,20 +367,20 @@ public class LayoutEditor extends AndroidEditor implements IShowEditorInput, IPa
} }
return false; return false;
} }
@Override @Override
protected void initUiRootNode(boolean force) { protected void initUiRootNode(boolean force) {
// The root UI node is always created, even if there's no corresponding XML node. // The root UI node is always created, even if there's no corresponding XML node.
if (mUiRootNode == null || force) { if (mUiRootNode == null || force) {
// get the target data from the opened file (and its project) // get the target data from the opened file (and its project)
AndroidTargetData data = getTargetData(); AndroidTargetData data = getTargetData();
Document doc = null; Document doc = null;
if (mUiRootNode != null) { if (mUiRootNode != null) {
doc = mUiRootNode.getXmlDocument(); doc = mUiRootNode.getXmlDocument();
} }
DocumentDescriptor desc; DocumentDescriptor desc;
if (data == null) { if (data == null) {
desc = new DocumentDescriptor("temp", null /*children*/); desc = new DocumentDescriptor("temp", null /*children*/);
@@ -385,18 +395,18 @@ public class LayoutEditor extends AndroidEditor implements IShowEditorInput, IPa
onDescriptorsChanged(doc); onDescriptorsChanged(doc);
} }
} }
private void onDescriptorsChanged(Document document) { private void onDescriptorsChanged(Document document) {
if (document != null) { if (document != null) {
mUiRootNode.loadFromXmlNode(document); mUiRootNode.loadFromXmlNode(document);
} else { } else {
mUiRootNode.reloadFromXmlNode(mUiRootNode.getXmlDocument()); mUiRootNode.reloadFromXmlNode(mUiRootNode.getXmlDocument());
} }
if (mOutline != null) { if (mOutline != null) {
mOutline.reloadModel(); mOutline.reloadModel();
} }
if (mGraphicalEditor != null) { if (mGraphicalEditor != null) {
mGraphicalEditor.reloadEditor(); mGraphicalEditor.reloadEditor();
mGraphicalEditor.reloadPalette(); mGraphicalEditor.reloadPalette();

View File

@@ -70,26 +70,26 @@ import java.util.List;
*/ */
class UiContentOutlinePage extends ContentOutlinePage { class UiContentOutlinePage extends ContentOutlinePage {
private AbstractGraphicalLayoutEditor mEditor; private GraphicalLayoutEditor mEditor;
private Action mAddAction; private Action mAddAction;
private Action mDeleteAction; private Action mDeleteAction;
private Action mUpAction; private Action mUpAction;
private Action mDownAction; private Action mDownAction;
private UiOutlineActions mUiActions = new UiOutlineActions(); private UiOutlineActions mUiActions = new UiOutlineActions();
public UiContentOutlinePage(AbstractGraphicalLayoutEditor editor, final EditPartViewer viewer) { public UiContentOutlinePage(GraphicalLayoutEditor editor, final EditPartViewer viewer) {
super(viewer); super(viewer);
mEditor = editor; mEditor = editor;
IconFactory factory = IconFactory.getInstance(); IconFactory factory = IconFactory.getInstance();
mAddAction = new Action("Add...") { mAddAction = new Action("Add...") {
@Override @Override
public void run() { public void run() {
List<UiElementNode> nodes = getModelSelections(); List<UiElementNode> nodes = getModelSelections();
UiElementNode node = nodes != null && nodes.size() > 0 ? nodes.get(0) : null; UiElementNode node = nodes != null && nodes.size() > 0 ? nodes.get(0) : null;
mUiActions.doAdd(node, viewer.getControl().getShell()); mUiActions.doAdd(node, viewer.getControl().getShell());
} }
}; };
@@ -100,7 +100,7 @@ class UiContentOutlinePage extends ContentOutlinePage {
@Override @Override
public void run() { public void run() {
List<UiElementNode> nodes = getModelSelections(); List<UiElementNode> nodes = getModelSelections();
mUiActions.doRemove(nodes, viewer.getControl().getShell()); mUiActions.doRemove(nodes, viewer.getControl().getShell());
} }
}; };
@@ -111,7 +111,7 @@ class UiContentOutlinePage extends ContentOutlinePage {
@Override @Override
public void run() { public void run() {
List<UiElementNode> nodes = getModelSelections(); List<UiElementNode> nodes = getModelSelections();
mUiActions.doUp(nodes); mUiActions.doUp(nodes);
} }
}; };
@@ -122,7 +122,7 @@ class UiContentOutlinePage extends ContentOutlinePage {
@Override @Override
public void run() { public void run() {
List<UiElementNode> nodes = getModelSelections(); List<UiElementNode> nodes = getModelSelections();
mUiActions.doDown(nodes); mUiActions.doDown(nodes);
} }
}; };
@@ -138,7 +138,7 @@ class UiContentOutlinePage extends ContentOutlinePage {
addSelectionChangedListener(new ISelectionChangedListener() { addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) { public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection(); ISelection selection = event.getSelection();
// the selection is never empty. The least it'll contain is the // the selection is never empty. The least it'll contain is the
// UiDocumentTreeEditPart object. // UiDocumentTreeEditPart object.
if (selection instanceof StructuredSelection) { if (selection instanceof StructuredSelection) {
@@ -162,7 +162,7 @@ class UiContentOutlinePage extends ContentOutlinePage {
} }
}); });
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite) * @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite)
@@ -184,7 +184,7 @@ class UiContentOutlinePage extends ContentOutlinePage {
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.eclipse.ui.part.Page#setActionBars(org.eclipse.ui.IActionBars) * @see org.eclipse.ui.part.Page#setActionBars(org.eclipse.ui.IActionBars)
* *
* Called automatically after createControl * Called automatically after createControl
*/ */
@Override @Override
@@ -195,7 +195,7 @@ class UiContentOutlinePage extends ContentOutlinePage {
toolBarManager.add(new Separator()); toolBarManager.add(new Separator());
toolBarManager.add(mUpAction); toolBarManager.add(mUpAction);
toolBarManager.add(mDownAction); toolBarManager.add(mDownAction);
IMenuManager menuManager = actionBars.getMenuManager(); IMenuManager menuManager = actionBars.getMenuManager();
menuManager.add(mAddAction); menuManager.add(mAddAction);
menuManager.add(mDeleteAction); menuManager.add(mDeleteAction);
@@ -222,18 +222,19 @@ class UiContentOutlinePage extends ContentOutlinePage {
public Control getControl() { public Control getControl() {
return getViewer().getControl(); return getViewer().getControl();
} }
void setNewEditor(GraphicalLayoutEditor editor) { void setNewEditor(GraphicalLayoutEditor editor) {
mEditor = editor; mEditor = editor;
setupOutline(); setupOutline();
} }
void breakConnectionWithEditor() { void breakConnectionWithEditor() {
// unhook outline viewer // unhook outline viewer
mEditor.getSelectionSynchronizer().removeViewer(getViewer()); mEditor.getSelectionSynchronizer().removeViewer(getViewer());
} }
private void setupOutline() { private void setupOutline() {
getViewer().setEditDomain(mEditor.getEditDomain()); getViewer().setEditDomain(mEditor.getEditDomain());
// hook outline viewer // hook outline viewer
@@ -255,13 +256,13 @@ class UiContentOutlinePage extends ContentOutlinePage {
*/ */
public void menuAboutToShow(IMenuManager manager) { public void menuAboutToShow(IMenuManager manager) {
List<UiElementNode> selected = getModelSelections(); List<UiElementNode> selected = getModelSelections();
if (selected != null) { if (selected != null) {
doCreateMenuAction(manager, selected); doCreateMenuAction(manager, selected);
return; return;
} }
doCreateMenuAction(manager, null /* ui_node */); doCreateMenuAction(manager, null /* ui_node */);
} }
}); });
Control control = getControl(); Control control = getControl();
Menu contextMenu = menuManager.createContextMenu(control); Menu contextMenu = menuManager.createContextMenu(control);
@@ -271,13 +272,13 @@ class UiContentOutlinePage extends ContentOutlinePage {
/** /**
* Adds the menu actions to the context menu when the given UI node is selected in * Adds the menu actions to the context menu when the given UI node is selected in
* the tree view. * the tree view.
* *
* @param manager The context menu manager * @param manager The context menu manager
* @param selected The UI node selected in the tree. Can be null, in which case the root * @param selected The UI node selected in the tree. Can be null, in which case the root
* is to be modified. * is to be modified.
*/ */
private void doCreateMenuAction(IMenuManager manager, List<UiElementNode> selected) { private void doCreateMenuAction(IMenuManager manager, List<UiElementNode> selected) {
if (selected != null) { if (selected != null) {
boolean hasXml = false; boolean hasXml = false;
for (UiElementNode uiNode : selected) { for (UiElementNode uiNode : selected) {
@@ -323,14 +324,14 @@ class UiContentOutlinePage extends ContentOutlinePage {
if (selected != null) { if (selected != null) {
manager.add(mDeleteAction); manager.add(mDeleteAction);
manager.add(new Separator()); manager.add(new Separator());
manager.add(mUpAction); manager.add(mUpAction);
manager.add(mDownAction); manager.add(mDownAction);
} }
if (selected != null && selected.size() == 1) { if (selected != null && selected.size() == 1) {
manager.add(new Separator()); manager.add(new Separator());
Action propertiesAction = new Action("Properties") { Action propertiesAction = new Action("Properties") {
@Override @Override
public void run() { public void run() {
@@ -344,7 +345,7 @@ class UiContentOutlinePage extends ContentOutlinePage {
} }
/** /**
* Updates the outline view with the model of the {@link GraphicalLayoutEditor}. * Updates the outline view with the model of the {@link IGraphicalLayoutEditor}.
* <p/> * <p/>
* This attemps to preserve the selection, if any. * This attemps to preserve the selection, if any.
*/ */
@@ -380,22 +381,22 @@ class UiContentOutlinePage extends ContentOutlinePage {
ISelection selection = getSelection(); ISelection selection = getSelection();
if (selection instanceof StructuredSelection) { if (selection instanceof StructuredSelection) {
StructuredSelection structuredSelection = (StructuredSelection)selection; StructuredSelection structuredSelection = (StructuredSelection)selection;
if (structuredSelection.size() > 0) { if (structuredSelection.size() > 0) {
ArrayList<UiElementTreeEditPart> selected = new ArrayList<UiElementTreeEditPart>(); ArrayList<UiElementTreeEditPart> selected = new ArrayList<UiElementTreeEditPart>();
for (Iterator it = structuredSelection.iterator(); it.hasNext(); ) { for (Iterator it = structuredSelection.iterator(); it.hasNext(); ) {
Object selectedObj = it.next(); Object selectedObj = it.next();
if (selectedObj instanceof UiElementTreeEditPart) { if (selectedObj instanceof UiElementTreeEditPart) {
selected.add((UiElementTreeEditPart) selectedObj); selected.add((UiElementTreeEditPart) selectedObj);
} }
} }
return selected.size() > 0 ? selected : null; return selected.size() > 0 ? selected : null;
} }
} }
return null; return null;
} }
@@ -412,16 +413,16 @@ class UiContentOutlinePage extends ContentOutlinePage {
if (parts != null) { if (parts != null) {
ArrayList<UiElementNode> selected = new ArrayList<UiElementNode>(); ArrayList<UiElementNode> selected = new ArrayList<UiElementNode>();
for (UiElementTreeEditPart part : parts) { for (UiElementTreeEditPart part : parts) {
if (part instanceof UiViewTreeEditPart || part instanceof UiLayoutTreeEditPart) { if (part instanceof UiViewTreeEditPart || part instanceof UiLayoutTreeEditPart) {
selected.add((UiElementNode) part.getModel()); selected.add((UiElementNode) part.getModel());
} }
} }
return selected.size() > 0 ? selected : null; return selected.size() > 0 ? selected : null;
} }
return null; return null;
} }
@@ -440,17 +441,17 @@ class UiContentOutlinePage extends ContentOutlinePage {
} }
} }
/** /**
* Selects the corresponding model element in the tree viewer. * Selects the corresponding model element in the tree viewer.
*/ */
private void setModelSelection(UiElementNode uiNodeToSelect) { private void setModelSelection(UiElementNode uiNodeToSelect) {
if (uiNodeToSelect != null) { if (uiNodeToSelect != null) {
// find an edit part that has the requested model element // find an edit part that has the requested model element
UiElementTreeEditPart part = findPartForModel( UiElementTreeEditPart part = findPartForModel(
(UiElementTreeEditPart) getViewer().getContents(), (UiElementTreeEditPart) getViewer().getContents(),
uiNodeToSelect); uiNodeToSelect);
// if we found a part, select it and reveal it // if we found a part, select it and reveal it
if (part != null) { if (part != null) {
setViewerSelection(part); setViewerSelection(part);
@@ -461,7 +462,7 @@ class UiContentOutlinePage extends ContentOutlinePage {
/** /**
* Utility method that tries to find an edit part that matches a given model UI node. * 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 rootPart The root of the viewer edit parts
* @param uiNode The UI node model to find * @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. * @return The part that matches the model or null if it's not in the sub tree.
@@ -471,7 +472,7 @@ class UiContentOutlinePage extends ContentOutlinePage {
if (rootPart.getModel() == uiNode) { if (rootPart.getModel() == uiNode) {
return rootPart; return rootPart;
} }
for (Object part : rootPart.getChildren()) { for (Object part : rootPart.getChildren()) {
if (part instanceof UiElementTreeEditPart) { if (part instanceof UiElementTreeEditPart) {
UiElementTreeEditPart found = findPartForModel( UiElementTreeEditPart found = findPartForModel(
@@ -492,16 +493,16 @@ class UiContentOutlinePage extends ContentOutlinePage {
*/ */
private void setupTooltip() { private void setupTooltip() {
final Tree tree = (Tree) getControl(); final Tree tree = (Tree) getControl();
/* /*
* Reference: * Reference:
* http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet125.java?view=markup * 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() { final Listener listener = new Listener() {
Shell tip = null; Shell tip = null;
Label label = null; Label label = null;
public void handleEvent(Event event) { public void handleEvent(Event event) {
switch(event.type) { switch(event.type) {
case SWT.Dispose: case SWT.Dispose:
@@ -523,7 +524,7 @@ class UiContentOutlinePage extends ContentOutlinePage {
} }
String tooltip = null; String tooltip = null;
TreeItem item = tree.getItem(new Point(event.x, event.y)); TreeItem item = tree.getItem(new Point(event.x, event.y));
if (item != null) { if (item != null) {
Object data = item.getData(); Object data = item.getData();
@@ -540,12 +541,12 @@ class UiContentOutlinePage extends ContentOutlinePage {
tooltip = item.getText() + ":\r" + tooltip; tooltip = item.getText() + ":\r" + tooltip;
} }
} }
if (tooltip != null) { if (tooltip != null) {
Shell shell = tree.getShell(); Shell shell = tree.getShell();
Display display = tree.getDisplay(); Display display = tree.getDisplay();
tip = new Shell(shell, SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL); tip = new Shell(shell, SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
tip.setBackground(display .getSystemColor(SWT.COLOR_INFO_BACKGROUND)); tip.setBackground(display .getSystemColor(SWT.COLOR_INFO_BACKGROUND));
FillLayout layout = new FillLayout(); FillLayout layout = new FillLayout();
@@ -567,7 +568,7 @@ class UiContentOutlinePage extends ContentOutlinePage {
} }
} }
}; };
tree.addListener(SWT.Dispose, listener); tree.addListener(SWT.Dispose, listener);
tree.addListener(SWT.KeyDown, listener); tree.addListener(SWT.KeyDown, listener);
tree.addListener(SWT.MouseMove, listener); tree.addListener(SWT.MouseMove, listener);
@@ -592,7 +593,7 @@ class UiContentOutlinePage extends ContentOutlinePage {
} }
// --------------- // ---------------
private class UiOutlineActions extends UiActions { private class UiOutlineActions extends UiActions {
@Override @Override
@@ -610,6 +611,6 @@ class UiContentOutlinePage extends ContentOutlinePage {
public void commitPendingXmlChanges() { public void commitPendingXmlChanges() {
// Pass. There is nothing to commit before the XML is changed here. // Pass. There is nothing to commit before the XML is changed here.
} }
} }
} }