没有合适的资源?快使用搜索试试~ 我知道了~
首页eclipse插件开发-编辑器详解
资源详情
资源评论
资源推荐
ecl
【
打
IW
o
pa
g
操
作
1 p
ISe
2
3
edi
t
4
5
edi
t
6
7
edi
t
8 }
ipse 插件
打
开 editor
的
先来看
一
从结
构
o
rkbenchP
a
g
e 的管理。
看
作
:
【I
W
ublic inter
f
lectionSer
v
public I
E
t
orId)thro
w
public I
E
t
orId, bool
public I
E
t
orId, final
那到
这
Platfo
开发--打
开
的
接口讨论
】
一
下 workbe
构
图我们大
致
a
rt(无论是
看
了一下,
I
W
okbenchP
a
f
ace IWor
k
v
ice,ICom
p
E
ditorPart
o
w
s PartInit
E
ditorPart
o
ean activa
E
ditorPart
o
boolean
a
这
边,可能
很
rmUI.
g
et
开
编辑器(
上
nch 吧,w
o
致
就可以猜
测
eidtor par
t
I
Workben
c
ag
e 提供的
接
k
benchPa
ge
p
atibleWo
r
o
penEdito
(
Exception
;
o
penEdito
(
te) throw
s
o
penEdito
r
a
ctivate, fi
n
很
多人已经
知
Workben
c
上
)
o
rkbench
从
测
出来,wo
t
还是 view
c
hPa
g
e 接
口
接
口】
e
extends
r
kbenchPa
g
(
IEditorIn
p
;
(
IEditorIn
p
s
PartInitE
x
r
(final IEdi
n
al int ma
t
知
道了怎么
调
ch().
g
et
A
从
静态划分
应
rkbench p
a
part)的容
器
口
定义中确
实
IPartServi
c
g
e {
p
ut input,
S
p
ut input,
S
x
ception;
torInput i
n
t
chFla
g
s)t
h
调
用这些接
口
A
ctiveWo
r
应
该大致如
下
ag
e 作为一
个
器
,肯定会
接
实
提供给了如
c
e,
S
trin
g
S
trin
g
n
put, final
S
h
rows Part
I
口
了:
r
kbench
W
下
:
个
接
受 workb
e
下打开编辑
器
Strin
g
I
nitExcept
i
W
indow().
g
e
nch
器
的
i
on;
g
et
Ac
t
用
就
Pla
t
(o
Edi
t
做
V
实
现
懒
初
核
心
角
色
再
说
IEd
or
g
1 p
inp
u
2
3 p
inp
u
4
5 p
inp
u
t
ivePa
g
e(
(说
明
就
是让用户
获
t
form、Ja
v
我们
再
r
g
.eclipse.
t
or 的是一
个
V
iewFactor
y
现
中非常精
华
初
始化是如
何
上图
就
心
作用是延
迟
色
的核心作
用
说
下去有点
偏
【IDE
上面
itorInput
实
.eclipse.ui
ublic stati
c
u
t) throws
ublic stati
c
u
t, boolea
n
ublic stati
c
u
t, boolea
n
).openEd
明
:Platfor
m
获
取到 work
b
v
aCore、Ja
v
再
仔细看一
下
ui.internal
个
叫做 Edit
o
y
的东东)。
这
华
的部分,看
一
何
实现的了,
就
用来说明
w
迟
加载扩
展
(
延
用
是用来延
迟
偏
离主题了,
工具类提供
IWorkben
实
例,二是
指
.ide.IDE 中
c
IEditorPa
PartInitE
x
c
IEditorPa
n
activate)
c
IEditorPa
n
activate,
i
tor(...)
m
UI 可以看
作
b
ench。Ecli
p
v
aUI 等)
下
IWorkb
e
.Workben
c
o
rMana
g
er
这
里的 Edi
t
一
下里面的
实
如何实现 p
w
orkbench
是
延
迟加载用
户
迟
初时化具体
这部分,以
的接口】
c
hPa
g
e 提
供
指
定 editor i
提供了其他
rt openEdi
x
ception {
rt openEdi
throws P
a
rt openEdi
boolean
d
作
是整个 ecl
p
se 中存在
的
e
nchPa
g
e
对
c
hPa
g
e)
中
的东东(同
理
t
orMana
ge
实
现就会很
大
art 复用的
是如何来管
理
户
通过 edit
o
的 part(例
如
后有时间再
写
供
接口都需
要
d。有些用
户
的接口:
i
tor(IWork
b
}
i
tor(IWork
b
a
rtInitExc
e
i
tor(IWork
b
d
etermine
C
ipse ui 框
架
的
其他一些
门
对
应的实现
类
中
的以上接口
理
,view p
a
e
r 和 Vie
w
大
程度上理
解
...等等。
理
各种 part
o
rs 或者 vie
w
如
避免过早
的
写
要
用户准备
两
户
可能不想
干
b
enchPa
ge
b
enchPa
ge
ption {
}
b
enchPa
ge
C
ontentTy
p
架
的门面类,
门
面类如:R
e
类
的实现代码
,
a
rt 对应的
管
w
Factory
是
解
workbe
n
的,其中 d
e
w
s 提供的
扩
的
创建对应
的
两
样东西:
一
干
这两件事
情
e
pa
g
e, IFil
e
pa
g
e, IFil
}
e
pa
g
e, IFil
p
e) { }
当然最核
心
e
sourcesPl
,真正在管
理
管
理器角色
类
是
workb
e
n
ch 所谓
懒
e
scriptor 角
扩
展),refer
e
的
control
等
一
是创建
情
,所以在
工
l
e
l
e
l
e
的作
ug
in、
理
类
是叫
nch
加载、
色的
e
nce
等
等)。
具类
6
7 public static IEditorPart openEditor(IWorkbenchPage page, IFile input, String
editorId) throws PartInitException { }
8
9 public static IEditorPart openEditor(IWorkbenchPage page, IFile input, String
editorId, boolean activate) throws PartInitException { }
10
11
上面 5 个接口操作中, 对于上面的三个操作,Eclipse 会自动为你准备
IEditorInput 实例,并动态绑定合适的编辑器类型。对于下面的两个操作,Eclipse 会为你
自动准备 IEditorInput 实例,但是需要用户自己指定 editor id。
接下来我们看两个问题,一是如何创建 IEditorInput 实例的;而是如何动态计算
对应的 editor id 的。
【有关 FileEditorInput】
在 IDE 工具类中提供的 5 个接受 IFile 对象的 openEditor 接口中,在对应的实现
中都是默认构造了一个 FileEditorInput(org.eclipse.ui.part.FileEditorInput)实例,
这个实例也是 org.eclipse.ui.IFileEditorInput 接口的默认实现类(注意:Eclipse 中很
多地方都使用这种 Interface/Default Impl 的方式,Interface 会暴露,Default Impl
则根据情况选择是否暴露,一般是如果 Interface 希望用户来扩展继承,则会暴露对应的
Default Impl,如果 Interface 不希望用户来扩展继承,例如 IResource 系列接口,则一
般会将 Default Impl 丢如对应的 internal 包中)。
我们看一下 org.eclipse.ui.part.FileEditorInput 中是如何实现
IEditorInput.exists()接口的:
1 public class FileEditorInput implements IFileEditorInput,IPathEditorInput,IPe
rsistableElement {
2 private IFile file;
3
4 public boolean exists() {
5 return file.exists();
6 }
7 }
我们看到内部的实现是持有了
IFile 句柄,如果 IFile 代表的资源没有存在于工作区
之内,那么就会返回 false。(疑问:如果我们打开工作区外部的文件呢???显然,
FileEditorInput 并不合适,稍后看...)
【动态计算 editor id】
下面,我们再来看一下 IDE 类是如何计算所谓的默认 eidtor id 的。追踪实现,我
们看到了 IDE.getDefaultEditor
1 public static IEditorDescriptor getDefaultEditor(IFile
file, boolean determineContentType) {
剩余11页未读,继续阅读
sdhustyh
- 粉丝: 184
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
- SPC统计方法基础知识.pptx
- MW全能培训汽轮机调节保安系统PPT教学课件.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论5