Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Tessier2016-03-03 09:01:08 +0000
committerPatrick Tessier2016-03-03 09:02:32 +0000
commit1e9056acfc0f91ea1c9fd1ea8734de8ff984e1cf (patch)
treedb5aa836cb7d93a866333aef208e6d4654489baa /extraplugins
parentbcce94efa94b1a752a4ec90c9ced15946f2dd52f (diff)
downloadorg.eclipse.papyrus-1e9056acfc0f91ea1c9fd1ea8734de8ff984e1cf.tar.gz
org.eclipse.papyrus-1e9056acfc0f91ea1c9fd1ea8734de8ff984e1cf.tar.xz
org.eclipse.papyrus-1e9056acfc0f91ea1c9fd1ea8734de8ff984e1cf.zip
Bug 447667: [Revision module] a module about revision model shall be
integrated to Papyrus Change-Id: I32533135c531cd8fe07474963380e2ce5c0a243c Signed-off-by: Patrick Tessier <Patrick.Tessier@cea.fr>
Diffstat (limited to 'extraplugins')
-rw-r--r--extraplugins/revision/org.eclipse.papyrus.revisiontool/META-INF/MANIFEST.MF3
-rw-r--r--extraplugins/revision/org.eclipse.papyrus.revisiontool/plugin.xml37
-rw-r--r--extraplugins/revision/org.eclipse.papyrus.revisiontool/src/org/eclipse/papyrus/revision/tool/handlers/DisplayStatHandler.java138
-rw-r--r--extraplugins/revision/org.eclipse.papyrus.revisiontool/src/org/eclipse/papyrus/revision/tool/handlers/IDMAbstractHandler.java135
-rw-r--r--extraplugins/revision/org.eclipse.papyrus.revisiontool/src/org/eclipse/papyrus/revision/tool/ui/SWTQualitativeInfo.java166
5 files changed, 478 insertions, 1 deletions
diff --git a/extraplugins/revision/org.eclipse.papyrus.revisiontool/META-INF/MANIFEST.MF b/extraplugins/revision/org.eclipse.papyrus.revisiontool/META-INF/MANIFEST.MF
index 61d2c2eaab4..92442be4432 100644
--- a/extraplugins/revision/org.eclipse.papyrus.revisiontool/META-INF/MANIFEST.MF
+++ b/extraplugins/revision/org.eclipse.papyrus.revisiontool/META-INF/MANIFEST.MF
@@ -34,7 +34,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.1.0",
org.eclipse.papyrus.infra.services.edit,
org.eclipse.papyrus.infra.ui;bundle-version="1.2.0",
- org.eclipse.papyrus.infra.ui.emf;bundle-version="1.2.0"
+ org.eclipse.papyrus.infra.ui.emf;bundle-version="1.2.0",
+ org.eclipse.papyrus.editor
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: org.eclipse.papyrus.revision.tool,
org.eclipse.papyrus.revision.tool.core,
diff --git a/extraplugins/revision/org.eclipse.papyrus.revisiontool/plugin.xml b/extraplugins/revision/org.eclipse.papyrus.revisiontool/plugin.xml
index e5e97075e60..3f672151b2c 100644
--- a/extraplugins/revision/org.eclipse.papyrus.revisiontool/plugin.xml
+++ b/extraplugins/revision/org.eclipse.papyrus.revisiontool/plugin.xml
@@ -246,4 +246,41 @@
file="resource/revision.custom">
</modeldeclaration>
</extension>
+<extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.papyrus.views.modelexplorer.modelexplorer.popup">
+ <menu
+ id="revision.idm"
+ label="Revision">
+ <visibleWhen
+ checkEnabled="true">
+ <with
+ variable="activeEditorId">
+ <equals
+ value="org.eclipse.papyrus.infra.core.papyrusEditor">
+ </equals>
+ </with>
+ </visibleWhen>
+ <command
+ commandId="org.eclipse.papyrus.revision.tool.handlers.DisplayStatHandler"
+ id="org.eclipse.papyrus.revision.tool.handlers.DisplayStatHandler.menu"
+ label="Display stats"
+ style="push">
+ <visibleWhen
+ checkEnabled="true">
+ </visibleWhen>
+ </command>
+ </menu>
+ </menuContribution>
+</extension>
+<extension
+ point="org.eclipse.ui.commands">
+ <command
+ defaultHandler="org.eclipse.papyrus.revision.tool.handlers.DisplayStatHandler"
+ id="org.eclipse.papyrus.revision.tool.handlers.DisplayStatHandler"
+ name="Display stats">
+ </command>
+</extension>
</plugin>
diff --git a/extraplugins/revision/org.eclipse.papyrus.revisiontool/src/org/eclipse/papyrus/revision/tool/handlers/DisplayStatHandler.java b/extraplugins/revision/org.eclipse.papyrus.revisiontool/src/org/eclipse/papyrus/revision/tool/handlers/DisplayStatHandler.java
new file mode 100644
index 00000000000..354f205eb7a
--- /dev/null
+++ b/extraplugins/revision/org.eclipse.papyrus.revisiontool/src/org/eclipse/papyrus/revision/tool/handlers/DisplayStatHandler.java
@@ -0,0 +1,138 @@
+/*****************************************************************************
+ * Copyright (c) 2014, 2015 CEA LIST, Christian W. Damus, and others.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 468079
+ * Christian W. Damus - bug 471836
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.revision.tool.handlers;
+
+import java.util.Iterator;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.DifferenceKind;
+import org.eclipse.emf.compare.ReferenceChange;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.revision.tool.core.ReviewResourceManager;
+import org.eclipse.papyrus.revision.tool.ui.ReviewsEditor;
+import org.eclipse.papyrus.revision.tool.ui.SWTQualitativeInfo;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Device;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.uml2.uml.Model;
+
+/**
+ * This class is used to create and html developper doc file.
+ *
+ */
+public class DisplayStatHandler extends IDMAbstractHandler {
+
+ protected static final String INTERNAL_DIRECTORY_NAME = "/doc"; //$NON-NLS-1$
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ super.execute(event);
+ IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("org.eclipse.papyrus.revisiontool.commentview");
+ if(part instanceof ReviewsEditor) {
+ ReviewResourceManager reviewResourceManager = ((ReviewsEditor)part).getReviewResourceManager();
+ if(reviewResourceManager.getCurrentReviewModelWithoutLoading() != null) {
+ Comparison comparison = reviewResourceManager.getDiffModel();
+ Model model = (Model)getSelection();
+ int elementNumber = 0;
+ int addedElement = 0;
+ int modifiedElement = 0;
+ int removedElement = 0;
+ int stableElement = 0;
+ Iterator<EObject> iterator = model.eAllContents();
+ while(iterator.hasNext()) {
+ EObject eObject = iterator.next();
+ elementNumber++;
+ if(comparison.getMatch(eObject) != null) {
+ modifiedElement++;
+ }
+ if(comparison.getDifferences(eObject).size() > 0) {
+ if(comparison.getDifferences(eObject).get(0).getKind().equals(DifferenceKind.DELETE) && isChangeAboutContaiment(comparison, eObject)) {
+ removedElement++;
+ } else if(comparison.getDifferences(eObject).get(0).getKind().equals(DifferenceKind.ADD) && isChangeAboutContaiment(comparison, eObject)) {
+ addedElement++;
+ } else if(comparison.getDifferences(eObject).get(0).getKind().equals(DifferenceKind.CHANGE)) {
+ modifiedElement++;
+ }
+ } else {
+ stableElement++;
+ }
+ }
+ final Shell shell = new Shell(Display.getCurrent());
+ int pourcentA = addedElement * 100 / elementNumber;
+ if(pourcentA == 0 && addedElement > 0) {
+ pourcentA = 1;
+ }
+ int pourcentM = modifiedElement * 100 / elementNumber;
+ if(pourcentM == 0 && modifiedElement > 0) {
+ pourcentM = 1;
+ }
+ int pourcentR = removedElement * 100 / elementNumber;
+ if(pourcentR == 0 && removedElement > 0) {
+ pourcentR = 1;
+ }
+ int pourcentS = stableElement * 100 / elementNumber;
+ if(pourcentS == 0 && stableElement > 0) {
+ pourcentS = 1;
+ }
+ int[] pourcent = { pourcentA, pourcentM, pourcentR, pourcentS };
+ String[] labels = { "Added " + addedElement + ":", "Modified " + modifiedElement + ":", "Deleted " + removedElement + ":", "Stable " + stableElement + ":" };
+ Device device = Display.getCurrent();
+ org.eclipse.swt.graphics.Color[] colors = { device.getSystemColor(SWT.COLOR_GREEN), device.getSystemColor(SWT.COLOR_BLUE), device.getSystemColor(SWT.COLOR_RED), device.getSystemColor(SWT.COLOR_GRAY) };
+ SWTQualitativeInfo canva = new SWTQualitativeInfo(shell, SWT.NULL, pourcent, labels, colors, SWTQualitativeInfo.HISTOGRAMME);
+ shell.setLayout(new FillLayout());
+ shell.pack();
+ shell.setSize(300, 300);
+ shell.setText("Statistic about modifications");
+ shell.open();
+ }
+ }
+ return null;
+ }
+
+ protected boolean isChangeAboutContaiment(Comparison comparison, EObject element) {
+ if(comparison.getDifferences(element).get(0) instanceof ReferenceChange) {
+ ReferenceChange refChange = (ReferenceChange)comparison.getDifferences(element).get(0);
+ if(refChange.getReference().isContainment()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ if(getSelection() instanceof Model) {
+ Model model = (Model)getSelection();
+ IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("org.eclipse.papyrus.revisiontool.commentview");
+ if(part instanceof ReviewsEditor) {
+ ReviewResourceManager reviewResourceManager = ((ReviewsEditor)part).getReviewResourceManager();
+ if(reviewResourceManager.getCurrentReviewModelWithoutLoading() != null) {
+ Comparison comparison = reviewResourceManager.getDiffModel();
+ if(comparison != null) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+}
diff --git a/extraplugins/revision/org.eclipse.papyrus.revisiontool/src/org/eclipse/papyrus/revision/tool/handlers/IDMAbstractHandler.java b/extraplugins/revision/org.eclipse.papyrus.revisiontool/src/org/eclipse/papyrus/revision/tool/handlers/IDMAbstractHandler.java
new file mode 100644
index 00000000000..3fca33c00a4
--- /dev/null
+++ b/extraplugins/revision/org.eclipse.papyrus.revisiontool/src/org/eclipse/papyrus/revision/tool/handlers/IDMAbstractHandler.java
@@ -0,0 +1,135 @@
+/*****************************************************************************
+ * Copyright (c) 2014, 2015 CEA LIST, Christian W. Damus, and others.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 468079
+ * Christian W. Damus - bug 471836
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.revision.tool.handlers;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.editor.PapyrusMultiDiagramEditor;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.ui.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.infra.ui.util.ServiceUtilsForHandlers;
+import org.eclipse.ui.ISelectionService;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Package;
+
+/**
+ * Abstract handler in order to connect to papyrus
+ *
+ */
+public abstract class IDMAbstractHandler extends AbstractHandler {
+
+ protected TransactionalEditingDomain transactionalEditingDomain = null;
+
+ protected PapyrusMultiDiagramEditor papyrusEditor;
+
+ private static Map<Element, Element> elt2DocElt = new HashMap<Element, Element>();
+
+ private static Map<String, String> href2DocHREF = new HashMap<String, String>();
+
+ private static Map<Package, Package> Toc2DocElt = new HashMap<Package, Package>();
+
+ /**
+ * get the root package
+ *
+ * @param elem
+ * @return the root package
+ */
+ public Package getToPackage(Element elem) {
+ Package tmp = elem.getNearestPackage();
+ while(tmp.getOwner() != null && (tmp.getOwner() instanceof Package)) {
+ tmp = (Package)tmp.getOwner();
+ }
+ return tmp;
+ }
+
+ // @Override
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ try {
+ papyrusEditor = (PapyrusMultiDiagramEditor)ServiceUtilsForHandlers.getInstance().getService(IMultiDiagramEditor.class, event);
+ transactionalEditingDomain = ServiceUtilsForHandlers.getInstance().getService(org.eclipse.emf.transaction.TransactionalEditingDomain.class, event);
+ } catch (Exception e) {
+ System.err.println("impossible to get the Transactional Editing Domain " + e); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ /**
+ * getSelected element in the diagram or in hte model explorer
+ *
+ * @return Element or null
+ */
+ protected Element getSelection() {
+ ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
+ ISelection selection = selectionService.getSelection();
+ if(selection instanceof IStructuredSelection) {
+ Object selectedobject = ((IStructuredSelection)selection).getFirstElement();
+ EObject selectedElement = EMFHelper.getEObject(selectedobject);
+ if(selectedElement instanceof Element) {
+ return (Element)selectedElement;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * getSelected element in the diagram or in hte model explorer
+ *
+ * @return Element or null
+ */
+ protected ArrayList<Element> getSelectionSet() {
+ ArrayList<Element> selectedSet = new ArrayList<Element>();
+ ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
+ ISelection selection = selectionService.getSelection();
+ // look for papyrus
+ if(selection instanceof IStructuredSelection) {
+ @SuppressWarnings("rawtypes")
+ Iterator selectedobjectIteractor = ((IStructuredSelection)selection).iterator();
+ while(selectedobjectIteractor.hasNext()) {
+ Object currentSelection = selectedobjectIteractor.next();
+ EObject selectedElement = EMFHelper.getEObject(currentSelection);
+ if(selectedElement instanceof Element) {
+ selectedSet.add((Element)selectedElement);
+ }
+ }
+ }
+ return selectedSet;
+ }
+
+ protected IProject getCurrentProject() {
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IWorkspaceRoot root = workspace.getRoot();
+ IPath path = new Path(getSelection().eResource().getURI().toPlatformString(true));
+ return root.getProject(path.segment(0));
+ }
+}
diff --git a/extraplugins/revision/org.eclipse.papyrus.revisiontool/src/org/eclipse/papyrus/revision/tool/ui/SWTQualitativeInfo.java b/extraplugins/revision/org.eclipse.papyrus.revisiontool/src/org/eclipse/papyrus/revision/tool/ui/SWTQualitativeInfo.java
new file mode 100644
index 00000000000..5331abdc8ca
--- /dev/null
+++ b/extraplugins/revision/org.eclipse.papyrus.revisiontool/src/org/eclipse/papyrus/revision/tool/ui/SWTQualitativeInfo.java
@@ -0,0 +1,166 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are 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
+ *
+ * Contributors:
+ * Patrick Tessier CEA LIST-implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.revision.tool.ui;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Device;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * This class is to display a info like camembert, bar or histogramme
+ * <BR>
+ * <img src="camembert.png">
+ * <BR>
+ * <h3>How to use:</h3>
+ * <BR>
+ * <code>
+ * int[] pourcent = { 30, 20, 10, 40 };<BR>
+ * String[] labels = { "Added", "Modified", "Deleted", "Stable" };<BR>
+ * Device device = Display.getCurrent();<BR>
+ * org.eclipse.swt.graphics.Color[] colors = { device.getSystemColor(SWT.COLOR_GREEN), device.getSystemColor(SWT.COLOR_CYAN),<BR>
+ * device.getSystemColor(SWT.COLOR_RED), device.getSystemColor(SWT.COLOR_YELLOW) };<BR>
+ * SWTQualitativeInfo canva = new SWTQualitativeInfo(shell, SWT.NULL, pourcent, labels, colors, HISTOGRAMME);<BR>
+ * </code>
+ **/
+public class SWTQualitativeInfo extends Canvas {
+
+ /** to display as a disk **/
+ public static int DISK = 0;
+
+ /** to display as histogram **/
+ public static int HISTOGRAMME = 1;
+
+ /** to display as bar **/
+ public static int BAR = 2;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param parent
+ * the composite owner
+ * @param style
+ * SWT style
+ * @param pourcent
+ * list of pourcent
+ * @param labels
+ * list of label that represent pourcent
+ * @param colors
+ * list of color for each pourcent
+ * @param type
+ * type of diagram DISK, HISTOGRAMME, BAR
+ */
+ public SWTQualitativeInfo(Composite parent, int style, final int[] pourcent, final String[] labels, final org.eclipse.swt.graphics.Color[] colors, final int type) {
+ super(parent, style);
+ this.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
+ addPaintListener(new PaintListener() {
+
+ @Override
+ public void paintControl(PaintEvent e) {
+ e.gc.setBackground(e.gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
+ e.gc.fillRectangle(0, 0, 300, 300);
+ if(type == BAR) {
+ e.gc.setBackground(e.gc.getDevice().getSystemColor(SWT.COLOR_BLACK));
+ e.gc.fillRectangle(29, 29, 102, 202);
+ int x = 30;
+ int y = 30;
+ for(int i = 0; i < pourcent.length; i++) {
+ e.gc.setBackground(colors[i]);
+ e.gc.fillRectangle(x, y, 100, pourcent[i] * 2);
+ e.gc.setBackground(e.gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
+ e.gc.setForeground(e.gc.getDevice().getSystemColor(SWT.COLOR_BLACK));
+ e.gc.drawString(labels[i] + " " + pourcent[i] + "%", x + 110, y + 10);
+ y = y + pourcent[i] * 2;
+ }
+ } else if(type == DISK) {
+ e.gc.setBackground(e.gc.getDevice().getSystemColor(SWT.COLOR_BLACK));
+ //e.gc.fillOval(28, 28, 203, 203);
+ int startAngle = 0;
+ int arcAngle = 0;
+ int x = 30;
+ int y = 240;
+ for(int i = 0; i < pourcent.length; i++) {
+ e.gc.setBackground(colors[i]);
+ arcAngle = (int)(pourcent[i] * 3.6);
+ e.gc.fillArc(30, 30, 200, 200, startAngle, arcAngle);
+ e.gc.fillRectangle(x, y, 10, 10);
+ e.gc.setBackground(e.gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
+ e.gc.setForeground(e.gc.getDevice().getSystemColor(SWT.COLOR_BLACK));
+ e.gc.drawString(labels[i] + " " + pourcent[i] + "%", x + 20, y - 2);
+ y = y + 20;
+ startAngle = startAngle + arcAngle;
+ }
+ } else {
+ e.gc.setBackground(e.gc.getDevice().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
+ e.gc.fillRectangle(35, 29, labels.length * 30, 200);
+ e.gc.setBackground(e.gc.getDevice().getSystemColor(SWT.COLOR_BLACK));
+ e.gc.fillRectangle(29, 29, 5, 2);
+ e.gc.fillRectangle(29, 77, 5, 2);
+ e.gc.fillRectangle(29, 127, 5, 2);
+ e.gc.fillRectangle(29, 177, 5, 2);
+ e.gc.fillRectangle(29, 227, 5, 2);
+ e.gc.setBackground(e.gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
+ e.gc.setForeground(e.gc.getDevice().getSystemColor(SWT.COLOR_BLACK));
+ e.gc.drawString("100%", 2, 19);
+ e.gc.drawString("75%", 2, 67);
+ e.gc.drawString("50%", 2, 117);
+ e.gc.drawString("25%", 2, 167);
+ e.gc.drawString("0%", 2, 217);
+ int x = 39;
+ int y = 30;
+ for(int i = 0; i < pourcent.length; i++) {
+ e.gc.setBackground(colors[i]);
+ e.gc.fillRectangle(x, (100 - pourcent[i]) * 2 + 29, 20, pourcent[i] * 2);
+ e.gc.fillRectangle(labels.length * 30 + 40, y + 10, 10, 10);
+ e.gc.setBackground(e.gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
+ e.gc.setForeground(e.gc.getDevice().getSystemColor(SWT.COLOR_BLACK));
+ e.gc.drawString(labels[i] + " " + pourcent[i] + "%", labels.length * 30 + 50, y + 10);
+ y = y + 20;
+ x = x + 30;
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * static main to execute the example
+ *
+ * @param a
+ */
+ public static void main(String[] a) {
+ final Display display = new Display();
+ final Shell shell = new Shell(display);
+ int[] pourcent = { 30, 20, 10, 40 };
+ String[] labels = { "Added", "Modified", "Deleted", "Stable" };
+ Device device = Display.getCurrent();
+ org.eclipse.swt.graphics.Color[] colors = { device.getSystemColor(SWT.COLOR_GREEN), device.getSystemColor(SWT.COLOR_CYAN), device.getSystemColor(SWT.COLOR_RED), device.getSystemColor(SWT.COLOR_YELLOW) };
+ SWTQualitativeInfo canva = new SWTQualitativeInfo(shell, SWT.NULL, pourcent, labels, colors, BAR);
+ shell.setLayout(new FillLayout());
+ shell.pack();
+ shell.setSize(300, 300);
+ shell.setText("Repartition");
+ shell.open();
+ while(!shell.isDisposed()) {
+ if(!display.readAndDispatch())
+ display.sleep();
+ }
+ }
+}

Back to the top