我是 eclipse 插件和 SWT 的新手。我正在设计一个具有一些功能的视图部分。但唯一的问题是我必须将它作为 Eclipse 插件启动才能检查。有什么方法可以从 main(String[] args) 方法调用它?
我正在发布我的示例视图部分代码
public class View extends ViewPart {
public static Display display=new Display();
public static final String ID = "Test.View"; //$NON-NLS-1$
private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
public View() {
}
/**
* Create contents of the view part.
* @param parent
*/
@Override
public void createPartControl(Composite parent) {
Composite container = toolkit.createComposite(parent, SWT.NONE);
toolkit.paintBordersFor(container);
{
Label lblNewLabel = new Label(container, SWT.NONE);
lblNewLabel.setBounds(25, 46, 49, 13);
toolkit.adapt(lblNewLabel, true, true);
lblNewLabel.setText("New Label");
}
Spinner spinner = new Spinner(container, SWT.BORDER);
spinner.setBounds(88, 105, 47, 21);
toolkit.adapt(spinner);
toolkit.paintBordersFor(spinner);
DragSource dragSource = new DragSource(container, DND.DROP_MOVE);
DropTarget dropTarget = new DropTarget(container, DND.DROP_MOVE);
Canvas canvas = new Canvas(container, SWT.NONE);
canvas.setBounds(94, 161, 174, 148);
toolkit.adapt(canvas);
toolkit.paintBordersFor(canvas);
createActions();
initializeToolBar();
initializeMenu();
}
public void dispose() {
toolkit.dispose();
super.dispose();
}
/**
* Create the actions.
*/
private void createActions() {
// Create the actions
}
/**
* Initialize the toolbar.
*/
private void initializeToolBar() {
IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
}
/**
* Initialize the menu.
*/
private void initializeMenu() {
IMenuManager manager = getViewSite().getActionBars().getMenuManager();
}
@Override
public void setFocus() {
// Set the focus
}
我可以写类似的东西吗
public static void main(String[] args){
View v=new View();
Shell shell=new Shell(display);
v.createPartControl(shell);
}