use of org.eclipse.ui.IWorkbenchListener in project knime-core by knime.
the class KNIMEApplicationWorkbenchWindowAdvisor method addGlobalNodeTimerShutdownHook.
/**
* Adds a workbench shutdown listener to write and send usage data.
*/
private void addGlobalNodeTimerShutdownHook() {
IWorkbench wb = PlatformUI.getWorkbench();
wb.addWorkbenchListener(new IWorkbenchListener() {
@Override
public boolean preShutdown(final IWorkbench workbench, final boolean forced) {
// Write and send usage data.
NodeTimer.GLOBAL_TIMER.performShutdown();
// Don't interrupt regular shutdown!
return true;
}
@Override
public void postShutdown(final IWorkbench workbench) {
/*nothing to do*/
}
});
}
use of org.eclipse.ui.IWorkbenchListener in project epp.mpc by eclipse.
the class MarketplaceWizardDialog method configureShell.
@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
// make jface dialog accessible for swtbot
newShell.setData(this);
new MarketplaceDropAdapter() {
@Override
protected void proceedInstallation(String url) {
SolutionInstallationInfo info = MarketplaceUrlHandler.createSolutionInstallInfo(url);
CatalogDescriptor catalogDescriptor = info.getCatalogDescriptor();
String installItem = info.getInstallId();
// we ignore previous wizard state here, since the wizard is still open...
if (installItem != null && installItem.length() > 0) {
info.setState(null);
getWizard().handleInstallRequest(info, url);
}
}
@Override
protected void proceedFavorites(String url) {
getWizard().importFavorites(url);
}
}.installDropTarget(newShell);
final IWorkbenchListener workbenchListener = new IWorkbenchListener() {
public boolean preShutdown(IWorkbench workbench, boolean forced) {
MarketplaceWizardDialog wizardDialog = MarketplaceWizardDialog.this;
Shell wizardShell = wizardDialog.getShell();
if (wizardShell != null && !wizardShell.isDisposed()) {
if (!forced) {
MarketplaceWizard wizard = wizardDialog.getWizard();
boolean hasPendingActions = false;
IWizardPage currentPage = wizardDialog.getCurrentPage();
if (currentPage != null && wizard != null) {
if (currentPage == wizard.getCatalogPage()) {
hasPendingActions = !wizard.getSelectionModel().getSelectedCatalogItems().isEmpty();
} else {
hasPendingActions = true;
}
}
if (hasPendingActions) {
Shell parentShell = activate(wizardDialog.getShell());
MessageDialog messageDialog = new MessageDialog(parentShell, Messages.MarketplaceWizardDialog_PromptPendingActionsTitle, null, Messages.MarketplaceWizardDialog_PromptPendingActionsMessage, MessageDialog.QUESTION_WITH_CANCEL, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, SWT.NONE);
int result = messageDialog.open();
switch(result) {
case // yes
0:
finishWizard();
return false;
case // no
1:
break;
// cancel
case 3:
// [x]
case SWT.DEFAULT:
default:
return false;
}
}
}
if (forced) {
wizardShell.close();
} else {
boolean closed = wizardDialog.close();
return closed;
}
}
return true;
}
private void finishWizard() {
MarketplaceWizardDialog wizardDialog = MarketplaceWizardDialog.this;
MarketplaceWizard wizard = wizardDialog.getWizard();
IWizardPage currentPage = wizardDialog.getCurrentPage();
if (currentPage == wizard.getCatalogPage()) {
((MarketplacePage) currentPage).showNextPage();
}
}
private Shell activate(Shell shell) {
Shell activeShell = shell.getDisplay().getActiveShell();
if (activeShell != shell) {
Shell[] childShells = shell.getShells();
if (childShells.length == 0 || !Arrays.asList(childShells).contains(activeShell)) {
shell.forceActive();
shell.forceFocus();
}
}
if (activeShell == null) {
activeShell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
if (activeShell == null) {
activeShell = shell;
}
}
return activeShell;
}
public void postShutdown(IWorkbench workbench) {
}
};
PlatformUI.getWorkbench().addWorkbenchListener(workbenchListener);
newShell.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
PlatformUI.getWorkbench().removeWorkbenchListener(workbenchListener);
}
});
if (newShell.getParent() == null) {
// bug 500379 - root shells don't handle escape traversal by default
newShell.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
if (e.keyCode == SWT.ESC) {
Shell shell = (Shell) e.widget;
if (shell != null && !shell.isDisposed() && shell.isVisible() && shell.isEnabled()) {
shell.close();
}
}
}
});
}
}
use of org.eclipse.ui.IWorkbenchListener in project mdw-designer by CenturyLinkCloud.
the class WorkflowAssetFactory method deRegisterWorkbenchListener.
public static void deRegisterWorkbenchListener(IFile file) {
if (workbenchListeners != null) {
IWorkbenchListener listener = workbenchListeners.get(file);
if (listener != null) {
PlatformUI.getWorkbench().removeWorkbenchListener(listener);
workbenchListeners.remove(file);
}
}
}
use of org.eclipse.ui.IWorkbenchListener in project azure-tools-for-java by Microsoft.
the class ContainerRegistryExplorerEditor method init.
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
setSite(site);
setInput(input);
if (input instanceof ContainerRegistryExplorerEditorInput) {
ContainerRegistryExplorerEditorInput containerInput = (ContainerRegistryExplorerEditorInput) input;
this.setPartName(containerInput.getName());
this.subscriptionId = containerInput.getSubscriptionId();
this.registryId = containerInput.getId();
containerExplorerPresenter.onGetRegistryProperty(containerInput.getSubscriptionId(), containerInput.getId());
}
IWorkbench workbench = PlatformUI.getWorkbench();
final IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
workbench.addWorkbenchListener(new IWorkbenchListener() {
@Override
public boolean preShutdown(IWorkbench workbench, boolean forced) {
activePage.closeEditor(ContainerRegistryExplorerEditor.this, true);
return true;
}
@Override
public void postShutdown(IWorkbench workbench) {
}
});
}
use of org.eclipse.ui.IWorkbenchListener in project azure-tools-for-java by Microsoft.
the class RedisExplorerEditor method init.
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
setSite(site);
setInput(input);
if (input instanceof RedisExplorerEditorInput) {
RedisExplorerEditorInput redisInput = (RedisExplorerEditorInput) input;
this.redisExplorerPresenter.initializeResourceData(redisInput.getSubscriptionId(), redisInput.getId());
this.setPartName(redisInput.getRedisName());
this.redisExplorerPresenter.onReadDbNum();
}
IWorkbench workbench = PlatformUI.getWorkbench();
final IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
workbench.addWorkbenchListener(new IWorkbenchListener() {
public boolean preShutdown(IWorkbench workbench, boolean forced) {
activePage.closeEditor(RedisExplorerEditor.this, true);
return true;
}
public void postShutdown(IWorkbench workbench) {
}
});
}
Aggregations