Home Database Mysql Tutorial Eclipse GEF常用技巧

Eclipse GEF常用技巧

Jun 07, 2016 pm 03:05 PM
eclipse java Commonly used Skill Enter

欢迎进入Java社区论坛,与200万技术人员互动交流 >>进入 1、大纲视图右键菜单项受editpart的createEditPolicies()方法影响。例如 :虽然右键菜单提供了删除选项,但只要相关的treeeditpart没有install ComponentEditPolicy,那么当鼠标打开该节点的右键菜单

欢迎进入Java社区论坛,与200万技术人员互动交流 >>进入

  1、大纲视图右键菜单项受editpart的createEditPolicies()方法影响。例如 :虽然右键菜单提供了删除选项,但只要相关的treeeditpart没有install ComponentEditPolicy,那么当鼠标打开该节点的右键菜单时,是不会看到“删除”项的。

  2、和1类似,有时候某些作为容器元素的对象不希望被用户选中,也是通过修改policy来实现的。具体如下:

  editpart实现

  public class BoardPart extends ContainerPart {

  protected void createEditPolicies() {

  super.createEditPolicies();

  installEditPolicy(EditPolicy.LAYOUT_ROLE, new BoardLayoutEditPolicy());

  }

  }

  policy实现

  public class BoardLayoutEditPolicy extends XYLayoutEditPolicy {

  ...

  protected Command createChangeConstraintCommand(EditPart child,

  Object constraint) {

  return null;

  }

  ...

  }

  从上面的代码可以看出,只要createChangeConstraintCommand()返回null,那么容器元素就不会被选中。

  3、如果一个或多个图元的属性校验出错,希望自动选中,那么考虑对界面元素进行校验,然后使用下面的方法:

  /**

  * 选中未做关联的显示框

  * @param errorEls 错误显示框ArrayList

  */

  private void selectErrors(ArrayList errorEls) {

  EditPartViewer viewer = getGraphicalViewer();

  viewer.deselectAll(); //去掉所有选择项

  EditPart last = null;

  for(ElementView element:errorEls) {

  EditPart editpart = (EditPart) viewer.getEditPartRegistry().get(element);

  viewer.appendSelection(editpart); //添加选择元素

  last = editpart;

  }

  viewer.reveal(last); //将最后选中元素放到窗口可视区域

  }

  4、退出编辑器时提示保存

  根据国际惯例,编辑器退出却未保存时,一般都会弹出对话框提示用户选择是否关闭编辑器。这时我首先想到的是覆盖父类的dispose()方法,判断未保存就返回而不退出。可实践证明,eclipse RCP并不支持这样做。经过一番探索得知,需要实现ISaveablePart2接口,在promptToSaveOnClose()添加处理。代码如下:

  @Override

  public int promptToSaveOnClose() {

  if(this.isDirty && !UIHelper.comfirm("关闭提示", title + "还未保存,确定退出?"))

  return ISaveablePart2.CANCEL;

  else

  return ISaveablePart2.NO;

  }

  5、鼠标拖动自动调用选择工具

  处理此问题要从画布元素的editpart类入手。第一步修改createFigure()方法:

  protected IFigure createFigure() {

  ...

  fig.setOpaque(true);

  return fig;

  }

  第二步覆盖getDragTracker()方法:

  public DragTracker getDragTracker(Request request) {

  if (request instanceof SelectionRequest &&

  ((SelectionRequest) request).getLastButtonPressed() == 3)

  {

  return new DeselectAllTracker(this);

  }

  return new MarqueeDragTracker();

  }

  两个方法配合使用,否则无法达到目的。

  6、如何通过editpart修改editor保存状态(不通过setDirty()实现)

  由于editpart类是拿不到editor引用的,故想通过调用editor.setDirty()是不可能的。在我的项目中,拖动一个图元是可以触发修改标记,但是拖动连线后editor就不能自动设为修改状态。通过一番研究发现,可以在editpart类中增加如下方法来实现:

  public void commit() {

  getViewer().getEditDomain().getCommandStack().execute(new Command(){});

  }

Eclipse GEF常用技巧

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Perfect Number in Java Perfect Number in Java Aug 30, 2024 pm 04:28 PM

Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Random Number Generator in Java Random Number Generator in Java Aug 30, 2024 pm 04:27 PM

Guide to Random Number Generator in Java. Here we discuss Functions in Java with examples and two different Generators with ther examples.

Weka in Java Weka in Java Aug 30, 2024 pm 04:28 PM

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Smith Number in Java Smith Number in Java Aug 30, 2024 pm 04:28 PM

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

Java Spring Interview Questions Java Spring Interview Questions Aug 30, 2024 pm 04:29 PM

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Break or return from Java 8 stream forEach? Break or return from Java 8 stream forEach? Feb 07, 2025 pm 12:09 PM

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

TimeStamp to Date in Java TimeStamp to Date in Java Aug 30, 2024 pm 04:28 PM

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.

15 commonly used currency circle escape index technology analysis 15 commonly used currency circle escape index technology analysis Mar 03, 2025 pm 05:48 PM

In-depth analysis of the top 15 Bitcoin Escape Index: Market Outlook for 2025 This article deeply analyzes fifteen commonly used Bitcoin Escape Index, among which the Bitcoin Rhodl ratio, USDT current wealth management and altcoin seasonal index have reached the Escape Index in 2024, attracting market attention. How should investors deal with potential risks? Let us interpret these indicators one by one and explore reasonable response strategies. 1. Detailed explanation of key indicators AHR999 coin hoarding indicator: Created by ahr999, assisting Bitcoin fixed investment strategy. The current value is 1.21, which is in the wait-and-see range, so it is recommended to be cautious. Link to AHR999 Escape Top Indicator: A supplement to AHR999 Coin Hoarding Indicator, used to identify the top of the market. The current value is 2.48, this week

See all articles