am 846c7d8b: am b1e9793d: ADT GLE: change error display to a separate sash.

Merge commit '846c7d8b2ee81da0c0905bd51f32065d2ebf7ef2'

* commit '846c7d8b2ee81da0c0905bd51f32065d2ebf7ef2':
  ADT GLE: change error display to a separate sash.
This commit is contained in:
Raphael
2009-09-02 14:08:30 -07:00
committed by Android Git Automerger
3 changed files with 163 additions and 154 deletions

View File

@@ -58,12 +58,12 @@ import org.eclipse.gef.ui.parts.SelectionSynchronizer;
import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.StackLayout; import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.dnd.Clipboard; import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite; import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException; import org.eclipse.ui.PartInitException;
@@ -112,7 +112,8 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
private ConfigurationComposite mConfigComposite; private ConfigurationComposite mConfigComposite;
/** The sash that splits the palette from the canvas. */ /** The sash that splits the palette from the canvas. */
private SashForm mSash; private SashForm mSashPalette;
private SashForm mSashError;
/** The palette displayed on the left of the sash. */ /** The palette displayed on the left of the sash. */
private PaletteComposite mPalette; private PaletteComposite mPalette;
@@ -120,6 +121,8 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
/** The layout canvas displayed o the right of the sash. */ /** The layout canvas displayed o the right of the sash. */
private LayoutCanvas mLayoutCanvas; private LayoutCanvas mLayoutCanvas;
private StyledText mErrorLabel;
/** The {@link FolderConfiguration} being edited. */ /** The {@link FolderConfiguration} being edited. */
private FolderConfiguration mEditedConfig; private FolderConfiguration mEditedConfig;
@@ -135,14 +138,9 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
private ConfigListener mConfigListener; private ConfigListener mConfigListener;
private Composite mCanvasOrErrorStack;
private StackLayout mCanvasOrErrorStackLayout;
private Label mErrorLabel;
private ReloadListener mReloadListener; private ReloadListener mReloadListener;
public GraphicalEditorPart(LayoutEditor layoutEditor) { public GraphicalEditorPart(LayoutEditor layoutEditor) {
mLayoutEditor = layoutEditor; mLayoutEditor = layoutEditor;
setPartName("Graphical Layout"); setPartName("Graphical Layout");
@@ -202,7 +200,8 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
@Override @Override
public void createPartControl(Composite parent) { public void createPartControl(Composite parent) {
mClipboard = new Clipboard(parent.getDisplay()); Display d = parent.getDisplay();
mClipboard = new Clipboard(d);
GridLayout gl = new GridLayout(1, false); GridLayout gl = new GridLayout(1, false);
parent.setLayout(gl); parent.setLayout(gl);
@@ -213,33 +212,28 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
mConfigComposite = new ConfigurationComposite(mConfigListener, parent, SWT.BORDER); mConfigComposite = new ConfigurationComposite(mConfigListener, parent, SWT.BORDER);
mConfigComposite.updateUIFromResources(); mConfigComposite.updateUIFromResources();
mSash = new SashForm(parent, SWT.HORIZONTAL); mSashPalette = new SashForm(parent, SWT.HORIZONTAL);
mSash.setLayoutData(new GridData(GridData.FILL_BOTH)); mSashPalette.setLayoutData(new GridData(GridData.FILL_BOTH));
mPalette = new PaletteComposite(mSash); mPalette = new PaletteComposite(mSashPalette);
mCanvasOrErrorStack = new Composite(mSash, SWT.NONE); mSashError = new SashForm(mSashPalette, SWT.VERTICAL | SWT.BORDER);
mCanvasOrErrorStackLayout = new StackLayout(); mSashError.setLayoutData(new GridData(GridData.FILL_BOTH));
mCanvasOrErrorStack.setLayout(mCanvasOrErrorStackLayout);
mLayoutCanvas = new LayoutCanvas(mCanvasOrErrorStack); mLayoutCanvas = new LayoutCanvas(mSashError, SWT.NONE);
mErrorLabel = new Label(mCanvasOrErrorStack, SWT.NONE); mErrorLabel = new StyledText(mSashError, SWT.READ_ONLY);
mCanvasOrErrorStackLayout.topControl = mLayoutCanvas; mErrorLabel.setEditable(false);
mErrorLabel.setBackground(d.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
mErrorLabel.setForeground(d.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
mSash.setWeights(new int[] { 20, 80 }); mSashPalette.setWeights(new int[] { 20, 80 });
mSashError.setWeights(new int[] { 80, 20 });
mSashError.setMaximizedControl(mLayoutCanvas);
// Initialize the state // Initialize the state
reloadPalette(); reloadPalette();
} }
/** Switches the stack to display the canvas and hide the error label. */
private void displayCanvas() {
if (mCanvasOrErrorStackLayout.topControl != mLayoutCanvas) {
mCanvasOrErrorStackLayout.topControl = mLayoutCanvas;
mCanvasOrErrorStack.layout();
}
}
/** /**
* Switches the stack to display the error label and hide the canvas. * Switches the stack to display the error label and hide the canvas.
* @param errorFormat The new error to display if not null. * @param errorFormat The new error to display if not null.
@@ -249,10 +243,12 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
if (errorFormat != null) { if (errorFormat != null) {
mErrorLabel.setText(String.format(errorFormat, parameters)); mErrorLabel.setText(String.format(errorFormat, parameters));
} }
if (mCanvasOrErrorStackLayout.topControl != mErrorLabel) { mSashError.setMaximizedControl(null);
mCanvasOrErrorStackLayout.topControl = mErrorLabel;
mCanvasOrErrorStack.layout();
} }
/** Displays the canvas and hides the error label. */
private void hideError() {
mSashError.setMaximizedControl(mLayoutCanvas);
} }
@Override @Override
@@ -275,6 +271,10 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
super.dispose(); super.dispose();
} }
/**
* Listens to changes from the Configuration UI banner and triggers layout rendering when
* changed. Also provide the Configuration UI with the list of resources/layout to display.
*/
private class ConfigListener implements IConfigListener { private class ConfigListener implements IConfigListener {
/** /**
@@ -542,6 +542,9 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
} }
} }
/**
* Listens to target changed in the current project, to trigger a new layout rendering.
*/
private class TargetListener implements ITargetChangeListener { private class TargetListener implements ITargetChangeListener {
public void onProjectTargetChange(IProject changedProject) { public void onProjectTargetChange(IProject changedProject) {
@@ -861,19 +864,13 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
configuredProjectRes, frameworkResources, mProjectCallback, configuredProjectRes, frameworkResources, mProjectCallback,
mLogger); mLogger);
mLayoutCanvas.setResult(result);
// update the UiElementNode with the layout info. // update the UiElementNode with the layout info.
if (result.getSuccess() == ILayoutResult.SUCCESS) { if (result.getSuccess() == ILayoutResult.SUCCESS) {
hideError();
// Update the image and make sure we're displaying the canvas.
mLayoutCanvas.setImage(result.getImage());
displayCanvas();
updateNodeWithBounds(result.getRootView());
} else { } else {
displayError(result.getErrorMessage()); displayError(result.getErrorMessage());
// Reset the edit data for all the nodes.
resetNodeBounds(model);
} }
model.refreshUi(); model.refreshUi();
@@ -957,6 +954,7 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
return mConfigComposite.getScreenBounds(); return mConfigComposite.getScreenBounds();
} }
/** @deprecated for GLE2 */
private void resetNodeBounds(UiElementNode node) { private void resetNodeBounds(UiElementNode node) {
node.setEditData(null); node.setEditData(null);
@@ -966,6 +964,7 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
} }
} }
/** @deprecated for GLE2 */
private void updateNodeWithBounds(ILayoutViewInfo r) { private void updateNodeWithBounds(ILayoutViewInfo r) {
if (r != null) { if (r != null) {
// update the node itself, as the viewKey is the XML node in this implementation. // update the node itself, as the viewKey is the XML node in this implementation.

View File

@@ -16,11 +16,8 @@
package com.android.ide.eclipse.adt.internal.editors.layout; package com.android.ide.eclipse.adt.internal.editors.layout;
import java.awt.image.BufferedImage; import com.android.layoutlib.api.ILayoutResult;
import java.awt.image.DataBufferInt;
import java.awt.image.Raster;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.GC;
@@ -30,6 +27,10 @@ import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.awt.image.Raster;
/** /**
* Displays the image rendered by the {@link GraphicalEditorPart} and handles * Displays the image rendered by the {@link GraphicalEditorPart} and handles
* the interaction with the widgets. * the interaction with the widgets.
@@ -50,8 +51,8 @@ public class LayoutCanvas extends Canvas {
private Image mImage; private Image mImage;
public LayoutCanvas(Composite parent) { public LayoutCanvas(Composite parent, int style) {
super(parent, SWT.BORDER); super(parent, style);
addPaintListener(new PaintListener() { addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) { public void paintControl(PaintEvent e) {
@@ -60,7 +61,13 @@ public class LayoutCanvas extends Canvas {
}); });
} }
public void setImage(BufferedImage awtImage) { public void setResult(ILayoutResult result) {
if (result.getSuccess() == ILayoutResult.SUCCESS) {
setImage(result.getImage());
}
}
private void setImage(BufferedImage awtImage) {
// Convert the AWT image into an SWT image. // Convert the AWT image into an SWT image.
int width = awtImage.getWidth(); int width = awtImage.getWidth();
int height = awtImage.getHeight(); int height = awtImage.getHeight();

View File

@@ -1104,6 +1104,9 @@ public class UiElementNode implements IPropertySource {
/** /**
* Sets the temporary data used by the editors. * Sets the temporary data used by the editors.
* @param data the data. * @param data the data.
*
* @since GLE1
* @deprecated Used by GLE1. Should be deprecated for GLE2.
*/ */
public void setEditData(Object data) { public void setEditData(Object data) {
mEditData = data; mEditData = data;