org.eclipse.ui.actions.OpenResourceAction源码实例Demo

类org.eclipse.ui.actions.OpenResourceAction源码实例Demo

下面列出了org.eclipse.ui.actions.OpenResourceAction 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Creates a new <code>OpenProjectAction</code>. The action requires
 * that the selection provided by the site's selection provider is of type <code>
 * org.eclipse.jface.viewers.IStructuredSelection</code>.
 *
 * @param site the site providing context information for this action
 */
public OpenProjectAction(IWorkbenchSite site) {
	super(site);
	fWorkbenchAction= new OpenResourceAction(site);
	setText(fWorkbenchAction.getText());
	setToolTipText(fWorkbenchAction.getToolTipText());
	PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.OPEN_PROJECT_ACTION);
	setEnabled(hasClosedProjectsInWorkspace());
}
 
protected void makeActions() {
	IShellProvider sp = new IShellProvider() {
		public Shell getShell() {
			return shell;
		}
	};

	openProjectAction = new OpenResourceAction(sp);
	openProjectAction.setText(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_openProjectAction);

	closeProjectAction = new CloseResourceAction(sp);
	closeProjectAction.setText(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_closeProjectAction);
	//
	// closeUnrelatedProjectsAction = new CloseUnrelatedProjectsAction(sp);
	// closeUnrelatedProjectsAction.setText("关闭无关的项目");

	refreshAction = new RefreshAction(sp) {
		public void run() {
			final IStatus[] errorStatus = new IStatus[1];
			errorStatus[0] = Status.OK_STATUS;
			final WorkspaceModifyOperation op = (WorkspaceModifyOperation) createOperation(errorStatus);
			WorkspaceJob job = new WorkspaceJob("refresh") { //$NON-NLS-1$

				public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
					try {
						op.run(monitor);
						if (shell != null && !shell.isDisposed()) {
							shell.getDisplay().asyncExec(new Runnable() {
								public void run() {
									StructuredViewer viewer = getActionSite().getStructuredViewer();
									if (viewer != null && viewer.getControl() != null
											&& !viewer.getControl().isDisposed()) {
										viewer.refresh();
									}
								}
							});
						}
					} catch (InvocationTargetException e) {
						String msg = NLS.bind(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_logTitle,
								getClass().getName(), e.getTargetException());
						throw new CoreException(new Status(IStatus.ERROR, NavigatorPlugin.PLUGIN_ID, IStatus.ERROR,
								msg, e.getTargetException()));
					} catch (InterruptedException e) {
						return Status.CANCEL_STATUS;
					}
					return errorStatus[0];
				}

			};
			ISchedulingRule rule = op.getRule();
			if (rule != null) {
				job.setRule(rule);
			}
			job.setUser(true);
			job.schedule();
		}
	};
	refreshAction.setText(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_refreshAction);
	refreshAction.setDisabledImageDescriptor(getImageDescriptor("dlcl16/refresh_nav.gif"));//$NON-NLS-1$
	refreshAction.setImageDescriptor(getImageDescriptor("elcl16/refresh_nav.gif"));//$NON-NLS-1$
	refreshAction.setActionDefinitionId(IWorkbenchCommandConstants.FILE_REFRESH);
	if (getContext() == null) {
		refreshAction.setEnabled(false);
	} else {
		IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
		refreshAction.selectionChanged(selection);
		refreshAction.setEnabled(!selection.isEmpty());
	}

	// buildAction = new BuildAction(sp, IncrementalProjectBuilder.INCREMENTAL_BUILD);
	// buildAction.setActionDefinitionId(IWorkbenchCommandConstants.PROJECT_BUILD_PROJECT);
}
 
源代码3 项目: tmxeditor8   文件: ResourceMgmtActionProvider.java
protected void makeActions() {
	IShellProvider sp = new IShellProvider() {
		public Shell getShell() {
			return shell;
		}
	};

	openProjectAction = new OpenResourceAction(sp);
	openProjectAction.setText(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_openProjectAction);

	closeProjectAction = new CloseResourceAction(sp);
	closeProjectAction.setText(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_closeProjectAction);
	//
	// closeUnrelatedProjectsAction = new CloseUnrelatedProjectsAction(sp);
	// closeUnrelatedProjectsAction.setText("关闭无关的项目");

	refreshAction = new RefreshAction(sp) {
		public void run() {
			final IStatus[] errorStatus = new IStatus[1];
			errorStatus[0] = Status.OK_STATUS;
			final WorkspaceModifyOperation op = (WorkspaceModifyOperation) createOperation(errorStatus);
			WorkspaceJob job = new WorkspaceJob("refresh") { //$NON-NLS-1$

				public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
					try {
						op.run(monitor);
						if (shell != null && !shell.isDisposed()) {
							shell.getDisplay().asyncExec(new Runnable() {
								public void run() {
									StructuredViewer viewer = getActionSite().getStructuredViewer();
									if (viewer != null && viewer.getControl() != null
											&& !viewer.getControl().isDisposed()) {
										viewer.refresh();
									}
								}
							});
						}
					} catch (InvocationTargetException e) {
						String msg = NLS.bind(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_logTitle,
								getClass().getName(), e.getTargetException());
						throw new CoreException(new Status(IStatus.ERROR, NavigatorPlugin.PLUGIN_ID, IStatus.ERROR,
								msg, e.getTargetException()));
					} catch (InterruptedException e) {
						return Status.CANCEL_STATUS;
					}
					return errorStatus[0];
				}

			};
			ISchedulingRule rule = op.getRule();
			if (rule != null) {
				job.setRule(rule);
			}
			job.setUser(true);
			job.schedule();
		}
	};
	refreshAction.setText(WorkbenchNavigatorMessages.actions_ResourceMgmtActionProvider_refreshAction);
	refreshAction.setDisabledImageDescriptor(getImageDescriptor("dlcl16/refresh_nav.gif"));//$NON-NLS-1$
	refreshAction.setImageDescriptor(getImageDescriptor("elcl16/refresh_nav.gif"));//$NON-NLS-1$
	refreshAction.setActionDefinitionId(IWorkbenchCommandConstants.FILE_REFRESH);
	if (getContext() == null) {
		refreshAction.setEnabled(false);
	} else {
		IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
		refreshAction.selectionChanged(selection);
		refreshAction.setEnabled(!selection.isEmpty());
	}

	// buildAction = new BuildAction(sp, IncrementalProjectBuilder.INCREMENTAL_BUILD);
	// buildAction.setActionDefinitionId(IWorkbenchCommandConstants.PROJECT_BUILD_PROJECT);
}
 
源代码评论
动弹
沙发等你来抢
 类所在包
 类方法
 同包方法