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.internal.editors.IconFactory;
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.IConfigListener;
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.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;
@@ -111,8 +112,8 @@ import java.util.Map;
* <p/>
* To understand Drag'n'drop: http://www.eclipse.org/articles/Article-Workbench-DND/drag_drop.html
*/
public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
implements ILayoutReloadListener, IConfigListener {
public class GraphicalLayoutEditor extends GraphicalEditorWithPalette
implements IGraphicalLayoutEditor, IConfigListener {
/** Reference to the layout editor */
@@ -233,6 +234,31 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
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)
* Creates the palette root.
*/
@@ -243,7 +269,6 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
return mPaletteRoot;
}
@Override
public Clipboard getClipboard() {
return mClipboard;
}
@@ -365,8 +390,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
*
* @param uiNodeModel The {@link UiElementNode} to select.
*/
@Override
void selectModel(UiElementNode uiNodeModel) {
public void selectModel(UiElementNode uiNodeModel) {
GraphicalViewer viewer = getGraphicalViewer();
// Give focus to the graphical viewer (in case the outline has it)
@@ -384,7 +408,6 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
// Local methods
//--------------
@Override
public LayoutEditor getLayoutEditor() {
return mLayoutEditor;
}
@@ -514,8 +537,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
* Sets the UI for the edition of a new file.
* @param configuration the configuration of the new file.
*/
@Override
void editNewFile(FolderConfiguration configuration) {
public void editNewFile(FolderConfiguration configuration) {
// update the configuration UI
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}.
*/
@Override
void reloadEditor() {
public void reloadEditor() {
GraphicalViewer viewer = getGraphicalViewer();
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
*/
@Override
void onXmlModelChanged() {
public void onXmlModelChanged() {
if (mLayoutEditor.isGraphicalEditorActive()) {
doXmlReload(true /* force */);
recomputeLayout();
@@ -697,13 +717,11 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
}
@Override
UiDocumentNode getModel() {
public UiDocumentNode getModel() {
return mLayoutEditor.getUiRootNode();
}
@Override
void reloadPalette() {
public void reloadPalette() {
PaletteFactory.createPaletteRoot(mPaletteRoot, mLayoutEditor.getTargetData());
}
@@ -794,9 +812,8 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
/**
* Recomputes the layout with the help of layoutlib.
*/
@Override
@SuppressWarnings("deprecation")
void recomputeLayout() {
public void recomputeLayout() {
doXmlReload(false /* force */);
try {
// 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.
*/
@Override
void activated() {
public void activated() {
if (mNeedsRecompute || mNeedsXmlReload) {
recomputeLayout();
}
@@ -1082,8 +1098,7 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
/**
* Responds to a page change that made the Graphical editor page the deactivated page
*/
@Override
void deactivated() {
public void deactivated() {
// nothing to be done here for now.
}
@@ -1093,12 +1108,12 @@ public class GraphicalLayoutEditor extends AbstractGraphicalLayoutEditor
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;
}

View File

@@ -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.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.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
implements IWorkbenchPart, ILayoutReloadListener {
/*package*/ interface IGraphicalLayoutEditor extends IEditorPart, ILayoutReloadListener {
/**
* Sets the UI for the edition of a new file.
@@ -71,27 +68,8 @@ import org.eclipse.ui.IWorkbenchPart;
/**
* 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();
}
abstract public SelectionSynchronizer getSelectionSynchronizer();
abstract void reloadPalette();

View File

@@ -55,7 +55,7 @@ public class LayoutEditor extends AndroidEditor implements IShowEditorInput, IPa
/** Root node of the UI element hierarchy */
private UiDocumentNode mUiRootNode;
private AbstractGraphicalLayoutEditor mGraphicalEditor;
private IGraphicalLayoutEditor mGraphicalEditor;
private int mGraphicalEditorIndex;
/** Implementation of the {@link IContentOutlinePage} for this editor */
private UiContentOutlinePage mOutline;
@@ -128,9 +128,15 @@ public class LayoutEditor extends AndroidEditor implements IShowEditorInput, IPa
// The graphical layout editor is now enabled by default.
// In case there's an issue we provide a way to disable it using an
// env variable.
if (System.getenv("ANDROID_DISABLE_LAYOUT") == null) {
if (System.getenv("ANDROID_DISABLE_LAYOUT") == null) { //$NON-NLS-1$
if (mGraphicalEditor == null) {
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());
setPageText(mGraphicalEditorIndex, mGraphicalEditor.getTitle());
} else {
@@ -246,8 +252,12 @@ 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
// gets stuck in the XML outline.
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;

View File

@@ -70,7 +70,7 @@ import java.util.List;
*/
class UiContentOutlinePage extends ContentOutlinePage {
private AbstractGraphicalLayoutEditor mEditor;
private GraphicalLayoutEditor mEditor;
private Action mAddAction;
private Action mDeleteAction;
@@ -79,7 +79,7 @@ class UiContentOutlinePage extends ContentOutlinePage {
private UiOutlineActions mUiActions = new UiOutlineActions();
public UiContentOutlinePage(AbstractGraphicalLayoutEditor editor, final EditPartViewer viewer) {
public UiContentOutlinePage(GraphicalLayoutEditor editor, final EditPartViewer viewer) {
super(viewer);
mEditor = editor;
IconFactory factory = IconFactory.getInstance();
@@ -234,6 +234,7 @@ class UiContentOutlinePage extends ContentOutlinePage {
}
private void setupOutline() {
getViewer().setEditDomain(mEditor.getEditDomain());
// hook outline viewer
@@ -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/>
* This attemps to preserve the selection, if any.
*/