### Eclipse Workspace Patch 1.0 #P org.hibernate.eclipse.console Index: src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java (revision 28615) +++ src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java (working copy) @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Comparator; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -48,7 +49,7 @@ import org.hibernate.mapping.Table; public class LazyDatabaseSchemaWorkbenchAdapter extends BasicWorkbenchAdapter { - + public Object[] getChildren(Object o) { return getChildren(o, new NullProgressMonitor()); } @@ -56,9 +57,10 @@ @SuppressWarnings("unchecked") public synchronized Object[] getChildren(Object o, final IProgressMonitor monitor) { LazyDatabaseSchema dbs = getLazyDatabaseSchema( o ); - + dbs.setConnected(false); + dbs.setErrorFlag(false); ConsoleConfiguration consoleConfiguration = dbs.getConsoleConfiguration(); - + Object[] res; try { DefaultDatabaseCollector db = readDatabaseSchema(monitor, consoleConfiguration, dbs.getReverseEngineeringStrategy()); @@ -69,20 +71,19 @@ Map.Entry> entry = qualifierEntries.next(); result.add(new TableContainer(entry.getKey(), entry.getValue())); } - return toArray(result.iterator(), TableContainer.class, new Comparator() { - + res = toArray(result.iterator(), TableContainer.class, new Comparator() { public int compare(TableContainer arg0, TableContainer arg1) { - return arg0.getName().compareTo(arg1.getName()); } - }); + dbs.setConnected(true); } catch (HibernateException e) { HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.LazyDatabaseSchemaWorkbenchAdapter_problems_while_reading_database_schema, e); String out = NLS.bind(HibernateConsoleMessages.LazyDatabaseSchemaWorkbenchAdapter_reading_schema_error, e.getMessage()); - return new Object[]{out}; + res = new Object[] { out }; + dbs.setErrorFlag(true); } - + return res; } private LazyDatabaseSchema getLazyDatabaseSchema(Object o) { @@ -90,7 +91,15 @@ } public ImageDescriptor getImageDescriptor(Object object) { - return EclipseImages.getImageDescriptor(ImageConstants.TABLE); + LazyDatabaseSchema dbs = getLazyDatabaseSchema(object); + Map imageMap = new HashMap(); + if (dbs.isConnected()) { + imageMap.put(ImageConstants.OVR_DBS_CONNECTED, OverlayImageIcon.BOTTOM_LEFT); + } + if (dbs.getErrorFlag()) { + imageMap.put(ImageConstants.OVR_WARNING, OverlayImageIcon.BOTTOM_LEFT); + } + return new OverlayImageIcon(EclipseImages.getImage(ImageConstants.TABLE), imageMap); } public String getLabel(Object o) { Index: src/org/hibernate/eclipse/console/viewers/xpl/MTreeViewer.java =================================================================== --- src/org/hibernate/eclipse/console/viewers/xpl/MTreeViewer.java (revision 28039) +++ src/org/hibernate/eclipse/console/viewers/xpl/MTreeViewer.java (working copy) @@ -98,6 +98,8 @@ for (int i = 0; i < widgets.length; i++) { internalAdd(widgets[i], parentElementOrTreePath, childElements); + // call this to refresh icon of parent item + updateItem(widgets[i], parentElementOrTreePath); } } Index: src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchema.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchema.java (revision 28039) +++ src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchema.java (working copy) @@ -29,6 +29,8 @@ private final ConsoleConfiguration ccfg; private final ReverseEngineeringStrategy res; + protected boolean connectedFlag = false; + protected boolean errorFlag = false; public LazyDatabaseSchema(ConsoleConfiguration ccfg) { this(ccfg, new DefaultReverseEngineeringStrategy()); @@ -45,5 +47,21 @@ public ReverseEngineeringStrategy getReverseEngineeringStrategy() { return res; } + + public boolean isConnected() { + return connectedFlag; + } + + public void setConnected(boolean connectedFlag) { + this.connectedFlag = connectedFlag; + } + + public boolean getErrorFlag() { + return errorFlag; + } + + public void setErrorFlag(boolean errorFlag) { + this.errorFlag = errorFlag; + } } Index: src/org/hibernate/eclipse/console/workbench/OverlayImageIcon.java =================================================================== --- src/org/hibernate/eclipse/console/workbench/OverlayImageIcon.java (revision 0) +++ src/org/hibernate/eclipse/console/workbench/OverlayImageIcon.java (revision 0) @@ -0,0 +1,117 @@ +/******************************************************************************* + * Copyright (c) 2011 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.hibernate.eclipse.console.workbench; + +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.jface.resource.CompositeImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.Point; +import org.hibernate.eclipse.console.utils.EclipseImages; + +/** + * based on the class from DTP plugins + * + * @author vy (vyemialyanchyk@gmail.com) + */ +public class OverlayImageIcon extends CompositeImageDescriptor { + + public static final int TOP_LEFT = 0; + public static final int TOP_RIGHT = 1; + public static final int BOTTOM_LEFT = 2; + public static final int BOTTOM_RIGHT = 3; + + /** + * Base image of the object + */ + private Image baseImage; + + /** + * Size of the base image + */ + private Point sizeOfImage; + + /** + * Map of ovr image to place + */ + private Map imageMap; + + /** + * Constructor for overlayImageIcon. + */ + public OverlayImageIcon(Image baseImage, Map imageMap) { + // Base image of the object + this.baseImage = baseImage; + this.imageMap = imageMap; + this.sizeOfImage = new Point(baseImage.getBounds().width, baseImage.getBounds().height); + } + + /** + * @see org.eclipse.jface.resource.CompositeImageDescriptor#drawCompositeImage(int, + * int) DrawCompositeImage is called to draw the composite image. + * + */ + @Override + protected void drawCompositeImage(int arg0, int arg1) { + // Draw the base image + drawImage(this.baseImage.getImageData(), 0, 0); + Iterator> it = imageMap.entrySet().iterator(); + for (; it.hasNext(); ) { + Map.Entry entry = it.next(); + ImageData imageData = + EclipseImages.getImageDescriptor(entry.getKey()).getImageData(); + switch (entry.getValue()) { + // Draw on the top left corner + case TOP_LEFT: + drawImage(imageData, 0, 0); + break; + + // Draw on top right corner + case TOP_RIGHT: + drawImage(imageData, this.sizeOfImage.x - imageData.width, 0); + break; + + // Draw on bottom left + case BOTTOM_LEFT: + drawImage(imageData, 0, this.sizeOfImage.y - imageData.height); + break; + + // Draw on bottom right corner + case BOTTOM_RIGHT: + drawImage(imageData, this.sizeOfImage.x - imageData.width, + this.sizeOfImage.y - imageData.height); + break; + + } + } + + } + + /** + * @see org.eclipse.jface.resource.CompositeImageDescriptor#getSize() get + * the size of the object + */ + @Override + protected Point getSize() { + return this.sizeOfImage; + } + + /** + * Get the image formed by overlaying different images on the base image + * + * @return composite image + */ + public Image getImage() { + return createImage(); + } +} #P org.hibernate.eclipse Index: src/org/hibernate/console/ImageMap.java =================================================================== --- src/org/hibernate/console/ImageMap.java (revision 28039) +++ src/org/hibernate/console/ImageMap.java (working copy) @@ -75,8 +75,14 @@ declareRegistryImage(CHECKBOX_FULL, "images/xpl/complete_tsk.gif"); //$NON-NLS-1$ declareRegistryImage(RELOAD, "images/reload.gif"); //$NON-NLS-1$ declareRegistryImage(ERROR, "images/error.gif"); //$NON-NLS-1$ + declareRegistryImage(EXCLAMATION, EXCLAMATION); declareRegistryImage(PINUP, PINUP_PATH); declareRegistryImage(PINDOWN, PINDOWN_PATH); + declareRegistryImage(OVR_ERROR, OVR_ERROR); + declareRegistryImage(OVR_ERROR2, OVR_ERROR2); + declareRegistryImage(OVR_DBS_OFF, OVR_DBS_OFF); + declareRegistryImage(OVR_DBS_CONNECTED, OVR_DBS_CONNECTED); + declareRegistryImage(OVR_WARNING, OVR_WARNING); declareRegistryImage(PRIMARY_KEY, "images/primary_key.gif"); //$NON-NLS-1$ declareRegistryImage(GENERATOR, "images/generator.gif"); //$NON-NLS-1$ } Index: src/org/hibernate/console/ImageConstants.java =================================================================== --- src/org/hibernate/console/ImageConstants.java (revision 28039) +++ src/org/hibernate/console/ImageConstants.java (working copy) @@ -124,13 +124,19 @@ public static final String CHECKBOX_EMPTY = "images/xpl/incomplete_tsk.gif"; //$NON-NLS-1$ public static final String RELOAD = "images/reload.gif"; //$NON-NLS-1$ public static final String ERROR = "images/error.gif"; //$NON-NLS-1$ + public static final String EXCLAMATION = "images/exclamation.gif"; //$NON-NLS-1$ public static final String PINUP = "PINUP"; //$NON-NLS-1$ public static final String PINUP_PATH = "images/pinup.png"; //$NON-NLS-1$ - public static final String PINDOWN = "PINDOWN"; //$NON-NLS-1$ public static final String PINDOWN_PATH = "images/pindown.png"; //$NON-NLS-1$ + + public static final String OVR_ERROR = "images/ovr16/error_co.gif"; //$NON-NLS-1$ + public static final String OVR_ERROR2 = "images/ovr16/obj_ovr_error.gif"; //$NON-NLS-1$ + public static final String OVR_DBS_OFF = "images/ovr16/obj_ovr_server_off.gif"; //$NON-NLS-1$ + public static final String OVR_DBS_CONNECTED = "images/ovr16/obj_ovr_server.gif"; //$NON-NLS-1$ + public static final String OVR_WARNING = "images/ovr16/warning_co.gif"; //$NON-NLS-1$ + public static final String PRIMARY_KEY = "PRIMARY_KEY";//$NON-NLS-1$ public static final String GENERATOR = "GENERATOR";//$NON-NLS-1$ - } \ No newline at end of file