Author: vyemialyanchyk
Date: 2011-02-07 11:22:09 -0500 (Mon, 07 Feb 2011)
New Revision: 29054
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/OverlayImageIcon.java
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/viewers/xpl/MTreeViewer.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchema.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java
Log:
https://issues.jboss.org/browse/JBIDE-8221 - add overlay image to DB node to display state
of DB connection - fixed
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/viewers/xpl/MTreeViewer.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/viewers/xpl/MTreeViewer.java 2011-02-07
16:20:10 UTC (rev 29053)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/viewers/xpl/MTreeViewer.java 2011-02-07
16:22:09 UTC (rev 29054)
@@ -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);
}
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchema.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchema.java 2011-02-07
16:20:10 UTC (rev 29053)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchema.java 2011-02-07
16:22:09 UTC (rev 29054)
@@ -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;
+ }
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java 2011-02-07
16:20:10 UTC (rev 29053)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java 2011-02-07
16:22:09 UTC (rev 29054)
@@ -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<String, List<Table>> entry = qualifierEntries.next();
result.add(new TableContainer(entry.getKey(), entry.getValue()));
}
- return toArray(result.iterator(), TableContainer.class, new
Comparator<TableContainer>() {
-
+ res = toArray(result.iterator(), TableContainer.class, new
Comparator<TableContainer>() {
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<String, Integer> imageMap = new HashMap<String, Integer>();
+ 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) {
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/OverlayImageIcon.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/OverlayImageIcon.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/OverlayImageIcon.java 2011-02-07
16:22:09 UTC (rev 29054)
@@ -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(a)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<String, Integer> imageMap;
+
+ /**
+ * Constructor for overlayImageIcon.
+ */
+ public OverlayImageIcon(Image baseImage, Map<String, Integer> 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<Map.Entry<String, Integer>> it = imageMap.entrySet().iterator();
+ for (; it.hasNext(); ) {
+ Map.Entry<String, Integer> 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();
+ }
+}