`
liugang594
  • 浏览: 981952 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

(译)Eclipse Zest一

    博客分类:
  • GEF
阅读更多

1. Eclipse Zest

1.1 概述

Eclipse Zest是一个可视化的图形工具。它基于SWT/Draw2D。Zest还支持JFace中Viewer的概念,因此允许模型和视图的分离。这篇文章假设你已经熟悉了Eclipse RCP或Eclipse Plugin开发。

 

(我注:其实也可以在一个普通的SWT程序中使用Zest)

 

1.2 组件

Eclipse Zest有以下组件:

 

  • GraphNode                --             graph中,带属性的结点
  • GraphConnections     --             graph中,用来连接两个结点的边线
  • GraphContainer         --             graph中,用来包含其他结点的容器
  • Graph                         --             根,用来包含所有其他的结点(nodes,connections,container)
(我注:graph可以理解为画板,用来画这些结点的)

1.3 布局

Zest提供了一些布局管理器,用来决定怎么布局graph上的结点。下面列出的就是所提供的一些布局:

表1 布局管理器

 

 

TreeLayoutAlgorithm Graph is displayed in the form of a vertical tree
HorizontalTreeLayoutAlgorithm Similar to TreeLayoutAlgorithm, but layout is horizontal
RadialLayoutAlgorithm Root is the center, the others nodes are placed around this node

GridLayoutAlgorithm

SpringLayoutAlgorithm

layout the graph, so that all connections should have approx the same length and that the edges overlap minimal
HorizontalShift move overlapping nodes to the right
CompositeLayoutAlgorithm combines other layout algorithms, for example, HorizontalShift can be the second layout algorithm to move nodes which were still overlapping if another algorithm is used.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1.4 Filter

可以通过调用setFilter(filter)方法,在布局上增加过滤器(org.eclipse.zest.layouts.filter),用于决定哪些结点和边线是可见的。filter收到一个LayoutItem对象,实际的graph结点可以通过方法getGraphData()得到。

2. 安装

(我注:好像现在安装完GEF后,自动就有了,所以这里略了)

3 你的第一个Zest工程

3.1 开始

创建一个Eclipse RCP应用“de.vogella.zest.first”。选择模板"Eclipse RCP with a view“。 增加"org.eclipse.zest.core" 和 "org.eclipse.zest.layouts" 依赖项。

 

修改"View.java"的代码如下,用于创建一个简单的graph和连接它的元素:

package de.vogella.zest.first;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.core.widgets.ZestStyles;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;
import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm;

public class View extends ViewPart {
	public static final String ID = "de.vogella.zest.first.view";
	private Graph graph;
	private int layout = 1;

	public void createPartControl(Composite parent) {
		// Graph will hold all other objects
		graph = new Graph(parent, SWT.NONE);
		// Now a few nodes
		GraphNode node1 = new GraphNode(graph, SWT.NONE, "Jim");
		GraphNode node2 = new GraphNode(graph, SWT.NONE, "Jack");
		GraphNode node3 = new GraphNode(graph, SWT.NONE, "Joe");
		GraphNode node4 = new GraphNode(graph, SWT.NONE, "Bill");
		// Lets have a directed connection
		new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, node1,
				node2);
		// Lets have a dotted graph connection
		new GraphConnection(graph, ZestStyles.CONNECTIONS_DOT, node2, node3);
		// Standard connection
		new GraphConnection(graph, SWT.NONE, node3, node1);
		// Change line color and line width
		GraphConnection graphConnection = new GraphConnection(graph, SWT.NONE,
				node1, node4);
		graphConnection.changeLineColor(parent.getDisplay().getSystemColor(
				SWT.COLOR_GREEN));
		// Also set a text
		graphConnection.setText("This is a text");
		graphConnection.setHighlightColor(parent.getDisplay().getSystemColor(
				SWT.COLOR_RED));
		graphConnection.setLineWidth(3);
		graphConnection.addListener(SWT.SELECTED, new Listener() {

			@Override
			public void handleEvent(Event event) {
				System.out.println("Selected");
			}

		});
		graph.setLayoutAlgorithm(new SpringLayoutAlgorithm(
				LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);

	}

	public void setLayoutManager() {
		switch (layout) {
		case 1:
			graph.setLayoutAlgorithm(new TreeLayoutAlgorithm(
					LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
			layout++;
			break;
		case 2:
			graph.setLayoutAlgorithm(new SpringLayoutAlgorithm(
					LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
			layout = 1;
			break;

		}

	}

	/**
	 * Passing the focus request to the viewer's control.
	 */
	public void setFocus() {
	}
}

 

运行以后,得到下图:

3.2 通过command来改变布局

创建一个command,并把以下"de.vogella.zest.first.handler.ChangeLayout"作为它的handler,此handler用于更改布局。最后把这个command加到一个menu上:

package de.vogella.zest.first.handler;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.handlers.HandlerUtil;

import de.vogella.zest.first.View;

public class ChangeLayout extends AbstractHandler {

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		IViewPart findView = HandlerUtil.getActiveWorkbenchWindow(event)
				.getActivePage().findView("de.vogella.zest.first.view");
		View view = (View) findView;
		view.setLayoutManager();
		return null;
	}

}

 运行应用,如果你选择了上面的菜单,视图的布局将会改变

4.Zest和JFace

JFace提供了viewers用于分离数据和展现。请看Eclipse JFace TableViewer Eclipse JFace TreeViewer 。JFace要求一个content provider和一个label provider。Zest提供了一个"GraphViewer“作为一个viewer。content provider则是基于connections或者是nodes的。

 

标准的Zest content providers有:

Content Provider Description
IGraphContentProvider Based on the connections. The connections contain the information which nodes they refer to. Cannot display nodes without connections.
IGraphEntityContentProvider Based on the Node which contain the information about which relationship they have. These relationship are available in the label provider as EntityConnectionData objects.
IGraphEntityRelationshipContentProvider Node based, the content provider defines getRelationShips(sourceNode, destinationNode) which determines the connections. The advantages compared with IGraphEntityContentProvider is that you decide which objects you return.

 

Zest的label provider可以是一个标准的JFace的 ILabelProvider,也可以是Zest特定的IEntityStyleProvider。

 

分享到:
评论

相关推荐

    maven_eclipse_GEF-zest-3.7.1_m2e-extras_m2e.zip

    总结来说,"maven_eclipse_GEF-zest-3.7.1_m2e-extras_m2e.zip"这个压缩包集合了Maven、Eclipse、GEF-Zest和m2e-extras的关键组件,旨在提供一个完整的、集成了图形化开发和Maven构建的开发环境。通过这个集成,...

    maven与eclipse集成所需插件

    1. **安装Maven插件**: Eclipse集成Maven主要依赖Maven Integration for Eclipse (M2E)插件。首先,打开Eclipse的“Help” > “Eclipse Marketplace”,搜索“Maven”,找到"M2E - Maven Integration for Eclipse"并...

    maven插件安装以及eclipse安装maven插件的资料

    Eclipse是一款流行的集成开发环境(IDE),它通过插件系统可以扩展各种功能,包括对Maven的支持。本文将详细介绍如何安装和配置Maven,以及在Eclipse中安装Maven插件。 首先,我们来了解Maven的基本概念。Maven基于...

    m2eclipse插件

    1. `org.eclipse.zest.core_1.3.0.v20110221-2050.jar`:这是Eclipse Zest核心库的一个版本,Zest是一个用于在Eclipse RCP应用程序中创建图形表示的库,可以用于构建网络图、流程图等。在m2eclipse插件中,可能用于...

    org.eclipse.gef

    9. **Zest 图形库**:作为 GEF 的一部分,Zest 是一个专门用于构建图形图表的库,适用于生成流程图、关系图和其他类型的可视化信息。 综上所述,"org.eclipse.gef" 插件为 Eclipse 开发者提供了一套强大的工具,...

    eclipse常用插件安装

    1. **Subclipse**:这是一个用于Eclipse的Subversion客户端,使得用户可以直接在IDE内部管理版本控制系统中的代码。安装Subclipse,你可以访问其更新站点:http://subclipse.tigris.org/update_1.6.x。 2. **m2...

    Eclipse插件开发:GEF入门系列宝典

    1. **Eclipse插件体系结构**: - 插件是Eclipse的核心组成部分,它们通过OSGi模块系统相互交互。 - 每个插件都是一个独立的Java项目,包含了代码、资源和元数据(plugin.xml)。 - 插件之间通过声明依赖关系来...

    Eclipse Indigo 离线安装maven插件m2eclipse

    旧版本eclipse,比如indigo版本要安装maven,旧的在线安装方式已经失效,因为依赖的zest和m2eclipse的location url都已经无法访问。所以从已经安装这两个包的eclipse中分离出离线的安装包,拷贝到对应的features和...

    eclipse的GEF插件

    Eclipse的GEF(Graphical Editing Framework)插件是一个强大的工具,用于在Eclipse集成开发环境中创建、编辑和展示图形用户界面。它为开发者提供了一种框架,支持创建可定制的、交互式的图形编辑器,使得开发人员...

    eclipse插件 GEF-SDK-3.4.0.zip

    - **Zest图表库**:GEF的一部分,用于创建复杂的图表和图形网络,如流程图、关系图等。 5. **插件安装与集成** 将"GEF-SDK-3.4.0.zip"解压后,开发者可以通过Eclipse的"Install New Software"功能将插件导入到...

    eclipse_gef_example.rar

    1. **org.eclipse.gef.examples.text** 这个部分主要展示了如何在GEF环境中处理文本。它涵盖了添加、编辑和格式化文本的基本功能,以及如何将文本与图形元素结合。开发者可以学习如何创建文本图形编辑部件,并理解...

    eclipse gef 插件 最新版本

    - **Zest图库**:作为GEF的一部分,Zest提供了用于创建图表的强大库,如树图、网络图等。 - **Marlin 3D绘图**:对于需要三维视图的项目,Marlin是GEF的一个扩展,提供3D图形支持。 总之,Eclipse GEF插件通过其...

    eclipse及gef相关文档

    5. **Zest图表库**:如果包含,可能会提及Zest,它是GEF的一个扩展,用于创建图表和图形表示。 6. **自定义编辑器**:介绍如何使用GEF创建针对特定领域或技术的图形编辑器。 通过学习这两个文档,开发者不仅可以...

    Eclipse插件开发--gef开发指南与入门系列宝典

    1. 创建Eclipse插件项目:了解如何使用Eclipse的New Plug-in Project向导,配置项目的依赖关系。 2. GEF的基本概念:深入理解模型、表示层、编辑器和控制器的概念。 3. 编辑器的生命周期:学习编辑器的创建、打开、...

    ECLIPSE GEF 5.4.0

    5. **Zest图渲染库**:ECLIPSE GEF 5.4.0可能集成了Zest库,这是一个用于绘制图表和图形网络的库,可以创建有吸引力的视觉表示。 6. **插件体系**:Eclipse本身就是一个插件化的开发环境,GEF也是通过插件形式集成...

    Eclipse GEF Reference(Plugins&Examples;,with source)

    1. **基本概念**:GEF提供了一个模型-视图-控制器(MVC)架构,用于创建图形编辑器。模型存储数据,视图负责显示数据,控制器处理用户输入和交互。 2. **Draw2D**: Draw2D是GEF的基础,它是一个二维图形绘制库,...

    GEF的Eclipse官方示例(源代码)

    **GEF(Graphical Editing Framework)**是Eclipse平台下的一个图形编辑框架,它为构建图形用户界面(GUI)提供了一种强大的工具,特别适用于创建复杂的图形编辑器。GEF主要用于设计和实现基于模型的图形编辑器,...

    西数WDC WD3200BPVT固件-80ZEST0-板号1672-WD-WXB1AC064983-01.01A01-0015002M-256-1091-KL

    标题中的“西数WDC WD3200BPVT固件-80ZEST0-板号1672-WD-WXB1AC064983-01.01A01-0015002M-256-1091-KL”涉及到的是西部数据(Western Digital,简称WD)的一款硬盘,具体型号为WD3200BPVT。固件是硬盘的重要组成部分...

    GEF-zest-3.6.1.zip

    GEF-zest-3.6.1.zipGEF-zest-3.6.1.zipGEF-zest-3.6.1.zipGEF-zest-3.6.1.zipGEF-zest-3.6.1.zipGEF-zest-3.6.1.zip

    pom editor 插件

    - 将解压得到的jar文件(如org.eclipse.zest.core_1.3.0.v20110221-2050.jar和org.eclipse.zest.layouts_1.1.0.v20110425-2050.jar)复制到`plugins`目录。 - 重启Eclipse,插件就会自动安装并启用。 - 在Eclipse...

Global site tag (gtag.js) - Google Analytics