use of org.eclipse.ui.IPerspectiveDescriptor in project tdi-studio-se by Talend.
the class CreateDiagramAction method setRepositoryNode.
private void setRepositoryNode(Properties params) {
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (null == workbenchWindow) {
return;
}
IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
if (null == workbenchPage) {
return;
}
IPerspectiveDescriptor currentPerspective = workbenchPage.getPerspective();
if (!IBrandingConfiguration.PERSPECTIVE_DI_ID.equals(currentPerspective.getId())) {
// show di perspective
try {
workbenchWindow.getWorkbench().showPerspective(IBrandingConfiguration.PERSPECTIVE_DI_ID, workbenchWindow);
workbenchPage = workbenchWindow.getActivePage();
} catch (WorkbenchException e) {
ExceptionHandler.process(e);
return;
}
}
// bug 16594
IRepositoryView view = RepositoryManagerHelper.getRepositoryView();
if (view != null) {
Object type = params.get("type");
if (ERepositoryObjectType.BUSINESS_PROCESS != null && ERepositoryObjectType.BUSINESS_PROCESS.name().equals(type)) {
RepositoryNode processNode = ((ProjectRepositoryNode) view.getRoot()).getRootRepositoryNode(ERepositoryObjectType.BUSINESS_PROCESS);
final StructuredViewer viewer = view.getViewer();
if (viewer instanceof TreeViewer) {
((TreeViewer) viewer).expandToLevel(processNode, 1);
}
this.repositoryNode = processNode;
}
}
}
use of org.eclipse.ui.IPerspectiveDescriptor in project bndtools by bndtools.
the class WorkspaceSetupWizard method performFinish.
@Override
public boolean performFinish() {
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
final File targetDir = previewPage.getTargetDir();
final Set<String> checkedPaths = previewPage.getCheckedPaths();
final boolean cleanBuild = setupPage.isCleanBuild();
try {
// Expand the template
ResourceMap outputs = previewPage.getTemplateOutputs();
final Set<File> topLevelFolders = new HashSet<>();
for (Entry<String, Resource> entry : outputs.entries()) {
String path = entry.getKey();
if (checkedPaths.contains(path)) {
Resource resource = entry.getValue();
// Create the folder or file resource
File file = new File(targetDir, path);
switch(resource.getType()) {
case Folder:
Files.createDirectories(file.toPath());
break;
case File:
File parentDir = file.getParentFile();
Files.createDirectories(parentDir.toPath());
try (InputStream in = resource.getContent()) {
IO.copy(in, file);
}
break;
default:
throw new IllegalArgumentException("Unknown resource type " + resource.getType());
}
// Remember the top-level folders we create, for importing below
if (file.getParentFile().equals(targetDir))
topLevelFolders.add(file);
}
}
// Import anything that looks like an Eclipse project & do a full rebuild
final IWorkspaceRunnable importProjectsRunnable = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
File[] children = targetDir.listFiles();
if (children != null) {
int work = children.length;
if (cleanBuild)
work += 2;
SubMonitor progress = SubMonitor.convert(monitor, work);
for (File folder : children) {
if (folder.isDirectory() && topLevelFolders.contains(folder)) {
String projectName = folder.getName();
File projectFile = new File(folder, IProjectDescription.DESCRIPTION_FILE_NAME);
if (projectFile.exists()) {
IProject project = workspace.getRoot().getProject(projectName);
if (!project.exists()) {
// No existing project in the workspace, so import the generated project.
SubMonitor subProgress = progress.newChild(1);
project.create(subProgress.newChild(1));
project.open(subProgress.newChild(1));
// Now make sure it is associated with the right location
IProjectDescription description = project.getDescription();
IPath path = Path.fromOSString(projectFile.getParentFile().getAbsolutePath());
description.setLocation(path);
project.move(description, IResource.REPLACE, progress);
} else {
// If a project with the same name exists, does it live in the same location? If not, we can't import the generated project.
File existingLocation = project.getLocation().toFile();
if (!existingLocation.equals(folder)) {
String message = String.format("Cannot import generated project from %s. A project named %s already exists in the workspace and is mapped to location %s", folder.getAbsolutePath(), projectName, existingLocation);
throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, message, null));
}
SubMonitor subProgress = progress.newChild(1);
// Open it if closed
project.open(subProgress.newChild(1));
// Refresh, as the template may have generated new content
project.refreshLocal(IResource.DEPTH_INFINITE, subProgress.newChild(1));
}
}
}
}
if (cleanBuild)
workspace.build(IncrementalProjectBuilder.CLEAN_BUILD, progress.newChild(2));
}
}
};
getContainer().run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
workspace.run(importProjectsRunnable, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
new WorkspaceJob("Load Repositories") {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
try {
Central.refreshPlugins();
} catch (Exception e) {
// There may be no workspace yet
}
return Status.OK_STATUS;
}
}.schedule();
}
});
// Prompt to switch to the bndtools perspective
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
IPerspectiveDescriptor currentPerspective = window.getActivePage().getPerspective();
if (!"bndtools.perspective".equals(currentPerspective.getId())) {
if (MessageDialog.openQuestion(getShell(), "Bndtools Perspective", "Switch to the Bndtools perspective?")) {
workbench.showPerspective("bndtools.perspective", window);
}
}
return true;
} catch (InvocationTargetException e) {
ErrorDialog.openError(getShell(), "Error", null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error generating template output", e.getTargetException()));
return false;
} catch (Exception e) {
ErrorDialog.openError(getShell(), "Error", null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error generating template output", e));
return false;
}
}
use of org.eclipse.ui.IPerspectiveDescriptor in project translationstudio8 by heartsome.
the class ApplicationWorkbenchWindowAdvisor method setListenerToPespective.
/**
* 给默认透视图添加监听,当透视图发生改变时,触发相关事件 robert 2012-10-18
* @param commandService
*/
private void setListenerToPespective(final ICommandService commandService) {
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IPerspectiveListener perspectiveListener = new IPerspectiveListener() {
public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, String changeId) {
}
public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
// 改变透视图时,发出监听去检查品质检查结果视图的状态,从而让 视图 菜单的状态与之保持一致。
commandService.refreshElements("net.heartsome.cat.ts.ui.qa.handlers.OpenQAResultViewCommand", null);
// 显示状态栏与工具栏
IHandlerService handlerService = (IHandlerService) window.getService(IHandlerService.class);
IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
boolean statusVisible = preferenceStore.getBoolean(TsPreferencesConstant.TS_statusBar_status);
if (!statusVisible) {
preferenceStore.setValue(TsPreferencesConstant.TS_statusBar_status, false);
try {
handlerService.executeCommand("net.heartsome.cat.ts.command.openStatusBar", null);
} catch (Exception ex) {
throw new RuntimeException("CommandTest.exitcommand not found");
}
}
WorkbenchWindow window_1 = (WorkbenchWindow) window;
if (!window_1.getCoolBarVisible()) {
try {
window_1.toggleToolbarVisibility();
commandService.refreshElements("net.heartsome.cat.ts.command.openToolBar", null);
} catch (Exception ex) {
throw new RuntimeException("CommandTest.exitcommand not found");
}
}
}
};
window.addPerspectiveListener(perspectiveListener);
}
use of org.eclipse.ui.IPerspectiveDescriptor in project tdi-studio-se by Talend.
the class OpenDiagramAction method getSelectedObject.
private ISelection getSelectedObject() {
if (params == null) {
return getSelection();
} else {
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (null == workbenchWindow) {
return null;
}
IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
if (null == workbenchPage) {
return null;
}
IPerspectiveDescriptor currentPerspective = workbenchPage.getPerspective();
if (!IBrandingConfiguration.PERSPECTIVE_DI_ID.equals(currentPerspective.getId())) {
// show di perspective
try {
workbenchWindow.getWorkbench().showPerspective(IBrandingConfiguration.PERSPECTIVE_DI_ID, workbenchWindow);
workbenchPage = workbenchWindow.getActivePage();
} catch (WorkbenchException e) {
ExceptionHandler.process(e);
return null;
}
}
RepositoryNode repositoryNode = RepositoryNodeUtilities.getRepositoryNode(params.getProperty("nodeId"), false);
IRepositoryView viewPart = getViewPart();
if (repositoryNode != null && viewPart != null) {
RepositoryNodeUtilities.expandParentNode(viewPart, repositoryNode);
return new StructuredSelection(repositoryNode);
}
return null;
}
}
use of org.eclipse.ui.IPerspectiveDescriptor in project tdi-studio-se by Talend.
the class CreateProcess method selectRootObject.
protected final void selectRootObject(Properties params) {
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (null == workbenchWindow) {
return;
}
IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
if (null == workbenchPage) {
return;
}
IPerspectiveDescriptor currentPerspective = workbenchPage.getPerspective();
if (!getPerspectiveId().equals(currentPerspective.getId())) {
// show di perspective
try {
workbenchWindow.getWorkbench().showPerspective(getPerspectiveId(), workbenchWindow);
workbenchPage = workbenchWindow.getActivePage();
} catch (WorkbenchException e) {
ExceptionHandler.process(e);
return;
}
}
IRepositoryView view = RepositoryManagerHelper.getRepositoryView();
if (view != null) {
Object type = params.get("type");
if (getProcessType().name().equals(type)) {
IRepositoryNode processNode = ((ProjectRepositoryNode) view.getRoot()).getRootRepositoryNode(getProcessType());
if (processNode != null) {
setWorkbenchPart(view);
final StructuredViewer viewer = view.getViewer();
if (viewer instanceof TreeViewer) {
((TreeViewer) viewer).expandToLevel(processNode, 1);
}
viewer.setSelection(new StructuredSelection(processNode));
}
}
}
}
Aggregations