Skip to content

Commit

Permalink
Start progressbar with percent to display stats.
Browse files Browse the repository at this point in the history
  • Loading branch information
angelozerr committed Aug 8, 2012
1 parent 0b4033f commit 2c57472
Show file tree
Hide file tree
Showing 16 changed files with 381 additions and 53 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,11 @@ public List<Collection> getCollections() {
public List<CollectionStats> createStats() throws UnknownHostException,
MongoException {
List<Collection> collections = getCollections();
List<CollectionStats> collectionStats = new CollectionListStats(
CollectionListStats collectionStats = new CollectionListStats(
collections.size());
for (Collection collection : collections) {
collectionStats.add(new CollectionStats(collection));
collectionStats
.addCollection(collection);
}
return collectionStats;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
package fr.opensagres.mongodb.ide.core.model.stats;

import java.net.UnknownHostException;
import java.util.ArrayList;

import com.mongodb.MongoException;

import fr.opensagres.mongodb.ide.core.model.Collection;

public class CollectionListStats extends ArrayList<CollectionStats> {

private double totalSize;
private double totalCount;

public CollectionListStats(int size) {
super(size);
this.totalSize = 0;
}

@Override
public boolean add(CollectionStats stats) {
double size = stats.getSize();
totalSize += size;
double count = stats.getCount();
totalCount += count;
return super.add(stats);
}

public double getTotalSize() {
return totalSize;
}

public void addCollection(Collection collection)
throws UnknownHostException, MongoException {
add(new CollectionStats(this, collection));
}

public double getTotalCount() {
return totalCount;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@

public class CollectionStats {

private final CollectionListStats listStats;
private final Collection collection;
private double size;
private double count;

public CollectionStats(Collection collection) throws UnknownHostException,
MongoException {
public CollectionStats(CollectionListStats listStats, Collection collection)
throws UnknownHostException, MongoException {
this.listStats = listStats;
this.collection = collection;
CommandResult stats = collection.getShellCommandManager()
.getDBCollectionGetStats(collection.getDBCollection());
size = stats.getDouble("size");
count = stats.getDouble("count");

//System.err.println(stats);
// System.err.println(stats);
}

public Collection getCollection() {
Expand All @@ -29,4 +33,24 @@ public Collection getCollection() {
public double getSize() {
return size;
}

public double getPercentSize() {
double totalSize = listStats.getTotalSize();
if (size == 0) {
return 0;
}
return (size / totalSize) * 100;
}

public double getCount() {
return count;
}

public double getPercentCount() {
double totalCount = listStats.getTotalCount();
if (count == 0) {
return 0;
}
return (size / totalCount) * 100;
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,5 @@ columnType=Type
columnUsername=Username
columnReadonly=Readonly?
columnName=Name
columnSize=Size
columnSize=Size
columnCount=Count
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@

import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.custom.TreeEditor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.widgets.FormToolkit;
Expand All @@ -31,6 +27,7 @@
import fr.opensagres.mongodb.ide.ui.internal.Messages;
import fr.opensagres.mongodb.ide.ui.singlesourcing.SingleSourcingUtils;
import fr.opensagres.mongodb.ide.ui.viewers.StatsContentProvider;
import fr.opensagres.mongodb.ide.ui.viewers.StatsCountColumnLabelProvider;
import fr.opensagres.mongodb.ide.ui.viewers.StatsNameColumnLabelProvider;
import fr.opensagres.mongodb.ide.ui.viewers.StatsSizeColumnLabelProvider;
import fr.opensagres.mongodb.ide.ui.viewers.ViewerHelper;
Expand Down Expand Up @@ -85,47 +82,48 @@ private void createStatsSection(Composite parent, FormToolkit toolkit) {
final Tree treeStats = toolkit.createTree(sbody, SWT.MULTI
| SWT.H_SCROLL | SWT.V_SCROLL);
treeStats.setLayoutData(new GridData(GridData.FILL_BOTH));

viewer = new TreeViewer(treeStats);
viewer.setContentProvider(StatsContentProvider.getInstance());
// viewer.setLabelProvider(StatsLabelProvider.getInstance());

treeStats.setHeaderVisible(true);
treeStats.setLinesVisible(true);

// 3) Create Tree columns with sort of paginated list.
createColumns(viewer);

// treeStats.addListener(SWT.PaintItem, new Listener() {
// int[] percents = new int[] { 50, 30, 5, 15 };
//
// public void handleEvent(Event event) {
// if (event.index == 1) {
// GC gc = event.gc;
// TreeItem item = (TreeItem) event.item;
// int index = treeStats.indexOf(item);
// int percent = percents[index];
// Color foreground = gc.getForeground();
// Color background = gc.getBackground();
// Display display = treeStats.getDisplay();
// gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
// gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
// int width = (100 - 1) * percent / 100;//(column2.getWidth() - 1) * percent / 100;
// gc.fillGradientRectangle(event.x, event.y, width,
// event.height, true);
// Rectangle rect2 = new Rectangle(event.x, event.y,
// width - 1, event.height - 1);
// gc.drawRectangle(rect2);
// gc.setForeground(display
// .getSystemColor(SWT.COLOR_LIST_FOREGROUND));
// String text = percent + "%";
// Point size = event.gc.textExtent(text);
// int offset = Math.max(0, (event.height - size.y) / 2);
// gc.drawText(text, event.x + 2, event.y + offset, true);
// gc.setForeground(background);
// gc.setBackground(foreground);
// }
// }
// });
// treeStats.addListener(SWT.PaintItem, new Listener() {
// int[] percents = new int[] { 50, 30, 5, 15 };
//
// public void handleEvent(Event event) {
// if (event.index == 1) {
// GC gc = event.gc;
// TreeItem item = (TreeItem) event.item;
// int index = treeStats.indexOf(item);
// int percent = percents[index];
// Color foreground = gc.getForeground();
// Color background = gc.getBackground();
// Display display = treeStats.getDisplay();
// gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
// gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
// int width = (100 - 1) * percent / 100;//(column2.getWidth() - 1) *
// percent / 100;
// gc.fillGradientRectangle(event.x, event.y, width,
// event.height, true);
// Rectangle rect2 = new Rectangle(event.x, event.y,
// width - 1, event.height - 1);
// gc.drawRectangle(rect2);
// gc.setForeground(display
// .getSystemColor(SWT.COLOR_LIST_FOREGROUND));
// String text = percent + "%";
// Point size = event.gc.textExtent(text);
// int offset = Math.max(0, (event.height - size.y) / 2);
// gc.drawText(text, event.x + 2, event.y + offset, true);
// gc.setForeground(background);
// gc.setBackground(foreground);
// }
// }
// });

SingleSourcingUtils.FormToolkit_paintBordersFor(toolkit, sbody);

Expand All @@ -145,11 +143,15 @@ private void initialize() {
private static void createColumns(final TreeViewer viewer) {

// Name collection column
ViewerHelper.createColumn(viewer, Messages.columnName, 200,
ViewerHelper.createColumn(viewer, Messages.columnName, 150,
StatsNameColumnLabelProvider.getInstance());

// Name collection column
ViewerHelper.createColumn(viewer, Messages.columnSize, 200,
// Count column
ViewerHelper.createColumn(viewer, Messages.columnCount, 50,
StatsCountColumnLabelProvider.getInstance());

// Size column
ViewerHelper.createColumn(viewer, Messages.columnSize, 50,
StatsSizeColumnLabelProvider.getInstance());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public class Messages extends NLS {

public static String columnName;
public static String columnSize;
public static String columnCount;

static {
// load message values from bundle file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,5 @@ columnType=Type
columnUsername=Username
columnReadonly=Readonly?
columnName=Name
columnSize=Size
columnSize=Size
columnCount=Count
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package fr.opensagres.mongodb.ide.ui.viewers;

import org.eclipse.swt.graphics.Image;

import fr.opensagres.mongodb.ide.core.model.stats.CollectionStats;
import fr.opensagres.mongodb.ide.ui.viewers.editor.GradientProgressBarColumnLabelProvider;

public class StatsCountColumnLabelProvider extends
GradientProgressBarColumnLabelProvider {

private static StatsCountColumnLabelProvider instance;

public static StatsCountColumnLabelProvider getInstance() {
synchronized (StatsCountColumnLabelProvider.class) {
if (instance == null) {
instance = new StatsCountColumnLabelProvider();
}
return instance;
}
}

@Override
public String getText(Object element) {
if (element instanceof CollectionStats) {
double count = ((CollectionStats) element).getCount();
return String.valueOf(count);
}
return super.getText(element);
}

@Override
public Image getImage(Object element) {
return super.getImage(element);
}

@Override
protected long getPercent(Object element) {
if (element instanceof CollectionStats) {
CollectionStats stats = (CollectionStats) element;
return Math.round(stats.getPercentSize());

}
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package fr.opensagres.mongodb.ide.ui.viewers;

import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.swt.graphics.Image;

import fr.opensagres.mongodb.ide.core.model.Collection;
import fr.opensagres.mongodb.ide.core.model.stats.CollectionStats;
import fr.opensagres.mongodb.ide.ui.internal.ImageResources;
import fr.opensagres.mongodb.ide.ui.viewers.editor.GradientProgressBarColumnLabelProvider;

public class StatsSizeColumnLabelProvider extends ColumnLabelProvider {
public class StatsSizeColumnLabelProvider extends
GradientProgressBarColumnLabelProvider {

private static StatsSizeColumnLabelProvider instance;

Expand All @@ -33,4 +32,14 @@ public String getText(Object element) {
public Image getImage(Object element) {
return super.getImage(element);
}

@Override
protected long getPercent(Object element) {
if (element instanceof CollectionStats) {
CollectionStats stats = (CollectionStats) element;
return Math.round(stats.getPercentSize());

}
return 0;
}
}
Loading

0 comments on commit 2c57472

Please sign in to comment.