在不使用查看器的情况下将按钮添加到 Eclipse 视图工具栏
Add Button to Eclipse view toolbar without using viewer
我正在尝试创建一个 Eclipse PDE 插件,该插件在视图的工具栏中有一个带有按钮的视图。该视图旨在显示文本,单击工具栏按钮时文本将更改格式。我一直在尝试使用查看器,因为 none 的查看器符合我的需要。我按照 this SO post 作为参考,但未能使该功能正常工作。 我的 plugin.xml 文件有问题吗? 我添加了视图的 ID 作为菜单贡献的位置 URI,但是插件没有在工具栏中显示按钮符合预期。
我在下面添加了我的 plugin.xml 和 ViewPart class 供您参考:
Plugin.xml:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.views">
<category
name="Sample Category"
id="asher">
</category>
<view
id="asher.views.id.SampleView"
name="Sample View"
icon="icons/daffodil.png"
class="asher.views.SampleView"
category="asher"
inject="true">
</view>
</extension>
<extension
point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension
targetID="org.eclipse.jdt.ui.JavaPerspective">
<view
id="asher.views.id.SampleView"
relative="org.eclipse.ui.views.ProblemView"
relationship="right"
ratio="0.5">
</view>
</perspectiveExtension>
</extension>
<extension
point="org.eclipse.help.contexts">
<contexts
file="contexts.xml">
</contexts>
</extension>
<extension
point="org.eclipse.ui.commands">
<category
id="asher.commands.unparse.category"
name="Unparse Category">
</category>
<command
categoryId="asher.commands.unparse.category"
name="UnParse"
id="asher.commands.unparseCommand">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="asher.handlers.UnparseHandler"
commandId="asher.commands.unparseCommand">
</handler>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
commandId="asher.commands.unparseCommand"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
contextId="org.eclipse.ui.contexts.window"
sequence="M1+7">
</key>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="true"
locationURI="toolbar:asher.views.id.SampleView?after=additions">
<menu
id="asher.menus.unparseMenu"
label="Unparse"
mnemonic="M">
<command
commandId="asher.commands.unparseCommand"
icon="icons/daffodil.png"
id="asher.menus.unparseCommand"
mnemonic="S"
tooltip="Unparse">
</command>
</menu>
</menuContribution>
</extension>
</plugin>
ViewPart Class:
public class SampleView extends ViewPart {
/**
* The ID of the view as specified by the extension.
*/
public static final String ID = "asher.views.id.SampleView";
@Inject IWorkbench workbench;
@Override
public void createPartControl(Composite parent) {
Text text = new Text(parent, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
File file = new File("/Users/user/Desktop/install.json");
Scanner sc;
try {
sc = new Scanner(file);
while (sc.hasNextLine())
text.setText(text.getText()+"\n"+sc.nextLine());
sc.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void setFocus() {
}
}
我找到了答案的解决方案。我所做的更改是从工具栏中删除标签。
这是固定的 plugin.xml 部分:
<menuContribution
allPopups="true"
locationURI="toolbar:asher.views.id.SampleView?after=additions">
<command
commandId="asher.commands.unparseCommand"
icon="icons/daffodil.png"
id="asher.menus.unparseCommand"
mnemonic="S"
tooltip="Unparse">
</command>
</menuContribution>
我正在尝试创建一个 Eclipse PDE 插件,该插件在视图的工具栏中有一个带有按钮的视图。该视图旨在显示文本,单击工具栏按钮时文本将更改格式。我一直在尝试使用查看器,因为 none 的查看器符合我的需要。我按照 this SO post 作为参考,但未能使该功能正常工作。 我的 plugin.xml 文件有问题吗? 我添加了视图的 ID 作为菜单贡献的位置 URI,但是插件没有在工具栏中显示按钮符合预期。
我在下面添加了我的 plugin.xml 和 ViewPart class 供您参考:
Plugin.xml:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.views">
<category
name="Sample Category"
id="asher">
</category>
<view
id="asher.views.id.SampleView"
name="Sample View"
icon="icons/daffodil.png"
class="asher.views.SampleView"
category="asher"
inject="true">
</view>
</extension>
<extension
point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension
targetID="org.eclipse.jdt.ui.JavaPerspective">
<view
id="asher.views.id.SampleView"
relative="org.eclipse.ui.views.ProblemView"
relationship="right"
ratio="0.5">
</view>
</perspectiveExtension>
</extension>
<extension
point="org.eclipse.help.contexts">
<contexts
file="contexts.xml">
</contexts>
</extension>
<extension
point="org.eclipse.ui.commands">
<category
id="asher.commands.unparse.category"
name="Unparse Category">
</category>
<command
categoryId="asher.commands.unparse.category"
name="UnParse"
id="asher.commands.unparseCommand">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="asher.handlers.UnparseHandler"
commandId="asher.commands.unparseCommand">
</handler>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key
commandId="asher.commands.unparseCommand"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
contextId="org.eclipse.ui.contexts.window"
sequence="M1+7">
</key>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="true"
locationURI="toolbar:asher.views.id.SampleView?after=additions">
<menu
id="asher.menus.unparseMenu"
label="Unparse"
mnemonic="M">
<command
commandId="asher.commands.unparseCommand"
icon="icons/daffodil.png"
id="asher.menus.unparseCommand"
mnemonic="S"
tooltip="Unparse">
</command>
</menu>
</menuContribution>
</extension>
</plugin>
ViewPart Class:
public class SampleView extends ViewPart {
/**
* The ID of the view as specified by the extension.
*/
public static final String ID = "asher.views.id.SampleView";
@Inject IWorkbench workbench;
@Override
public void createPartControl(Composite parent) {
Text text = new Text(parent, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
File file = new File("/Users/user/Desktop/install.json");
Scanner sc;
try {
sc = new Scanner(file);
while (sc.hasNextLine())
text.setText(text.getText()+"\n"+sc.nextLine());
sc.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void setFocus() {
}
}
我找到了答案的解决方案。我所做的更改是从工具栏中删除标签。
这是固定的 plugin.xml 部分:
<menuContribution
allPopups="true"
locationURI="toolbar:asher.views.id.SampleView?after=additions">
<command
commandId="asher.commands.unparseCommand"
icon="icons/daffodil.png"
id="asher.menus.unparseCommand"
mnemonic="S"
tooltip="Unparse">
</command>
</menuContribution>