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.swt.SWT;
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.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
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.IEditorSite;
import org.eclipse.ui.PartInitException;
@@ -112,7 +112,8 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
private ConfigurationComposite mConfigComposite;
/** 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. */
private PaletteComposite mPalette;
@@ -120,6 +121,8 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
/** The layout canvas displayed o the right of the sash. */
private LayoutCanvas mLayoutCanvas;
private StyledText mErrorLabel;
/** The {@link FolderConfiguration} being edited. */
private FolderConfiguration mEditedConfig;
@@ -135,14 +138,9 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
private ConfigListener mConfigListener;
private Composite mCanvasOrErrorStack;
private StackLayout mCanvasOrErrorStackLayout;
private Label mErrorLabel;
private ReloadListener mReloadListener;
public GraphicalEditorPart(LayoutEditor layoutEditor) {
mLayoutEditor = layoutEditor;
setPartName("Graphical Layout");
@@ -202,7 +200,8 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
@Override
public void createPartControl(Composite parent) {
mClipboard = new Clipboard(parent.getDisplay());
Display d = parent.getDisplay();
mClipboard = new Clipboard(d);
GridLayout gl = new GridLayout(1, false);
parent.setLayout(gl);
@@ -213,33 +212,28 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
mConfigComposite = new ConfigurationComposite(mConfigListener, parent, SWT.BORDER);
mConfigComposite.updateUIFromResources();
mSash = new SashForm(parent, SWT.HORIZONTAL);
mSash.setLayoutData(new GridData(GridData.FILL_BOTH));
mSashPalette = new SashForm(parent, SWT.HORIZONTAL);
mSashPalette.setLayoutData(new GridData(GridData.FILL_BOTH));
mPalette = new PaletteComposite(mSash);
mPalette = new PaletteComposite(mSashPalette);
mCanvasOrErrorStack = new Composite(mSash, SWT.NONE);
mCanvasOrErrorStackLayout = new StackLayout();
mCanvasOrErrorStack.setLayout(mCanvasOrErrorStackLayout);
mSashError = new SashForm(mSashPalette, SWT.VERTICAL | SWT.BORDER);
mSashError.setLayoutData(new GridData(GridData.FILL_BOTH));
mLayoutCanvas = new LayoutCanvas(mCanvasOrErrorStack);
mErrorLabel = new Label(mCanvasOrErrorStack, SWT.NONE);
mCanvasOrErrorStackLayout.topControl = mLayoutCanvas;
mLayoutCanvas = new LayoutCanvas(mSashError, SWT.NONE);
mErrorLabel = new StyledText(mSashError, SWT.READ_ONLY);
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
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.
* @param errorFormat The new error to display if not null.
@@ -249,10 +243,12 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
if (errorFormat != null) {
mErrorLabel.setText(String.format(errorFormat, parameters));
}
if (mCanvasOrErrorStackLayout.topControl != mErrorLabel) {
mCanvasOrErrorStackLayout.topControl = mErrorLabel;
mCanvasOrErrorStack.layout();
mSashError.setMaximizedControl(null);
}
/** Displays the canvas and hides the error label. */
private void hideError() {
mSashError.setMaximizedControl(mLayoutCanvas);
}
@Override
@@ -275,6 +271,10 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
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 {
/**
@@ -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 {
public void onProjectTargetChange(IProject changedProject) {
@@ -861,19 +864,13 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
configuredProjectRes, frameworkResources, mProjectCallback,
mLogger);
mLayoutCanvas.setResult(result);
// update the UiElementNode with the layout info.
if (result.getSuccess() == ILayoutResult.SUCCESS) {
// Update the image and make sure we're displaying the canvas.
mLayoutCanvas.setImage(result.getImage());
displayCanvas();
updateNodeWithBounds(result.getRootView());
hideError();
} else {
displayError(result.getErrorMessage());
// Reset the edit data for all the nodes.
resetNodeBounds(model);
}
model.refreshUi();
@@ -957,6 +954,7 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
return mConfigComposite.getScreenBounds();
}
/** @deprecated for GLE2 */
private void resetNodeBounds(UiElementNode node) {
node.setEditData(null);
@@ -966,6 +964,7 @@ public class GraphicalEditorPart extends EditorPart implements IGraphicalLayoutE
}
}
/** @deprecated for GLE2 */
private void updateNodeWithBounds(ILayoutViewInfo r) {
if (r != null) {
// 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;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.awt.image.Raster;
import com.android.layoutlib.api.ILayoutResult;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
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.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
* the interaction with the widgets.
@@ -50,8 +51,8 @@ public class LayoutCanvas extends Canvas {
private Image mImage;
public LayoutCanvas(Composite parent) {
super(parent, SWT.BORDER);
public LayoutCanvas(Composite parent, int style) {
super(parent, style);
addPaintListener(new PaintListener() {
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.
int width = awtImage.getWidth();
int height = awtImage.getHeight();

View File

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