Search in sources :

Example 1 with ISaveablePart

use of org.eclipse.ui.ISaveablePart in project tdi-studio-se by Talend.

the class ExportJobScriptAction method checkDirtyPart.

/**
     * DOC Administrator Comment method "checkDirtyPart".
     * 
     * @param workbench
     */
@SuppressWarnings("restriction")
private boolean checkDirtyPart(IWorkbench workbench) {
    ISaveablePart[] parts = null;
    IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
    for (IWorkbenchWindow window : windows) {
        IWorkbenchPage[] pages = window.getPages();
        for (IWorkbenchPage page : pages) {
            parts = page.getDirtyEditors();
        }
    }
    if (parts != null && parts.length > 0) {
        return true;
    }
    return false;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ISaveablePart(org.eclipse.ui.ISaveablePart)

Example 2 with ISaveablePart

use of org.eclipse.ui.ISaveablePart in project dbeaver by dbeaver.

the class DataSourceHandler method disconnectDataSource.

public static void disconnectDataSource(DBPDataSourceContainer dataSourceContainer, @Nullable final Runnable onFinish) {
    // Save users
    for (DBPDataSourceUser user : dataSourceContainer.getUsers()) {
        if (user instanceof ISaveablePart) {
            if (!SaveChangesHandler.validateAndSave(new VoidProgressMonitor(), (ISaveablePart) user)) {
                return;
            }
        }
    }
    if (!checkAndCloseActiveTransaction(dataSourceContainer)) {
        return;
    }
    if (dataSourceContainer instanceof DataSourceDescriptor && dataSourceContainer.isConnected()) {
        final DataSourceDescriptor dataSourceDescriptor = (DataSourceDescriptor) dataSourceContainer;
        if (!ArrayUtils.isEmpty(Job.getJobManager().find(dataSourceDescriptor))) {
            // Already connecting/disconnecting - just return
            return;
        }
        final DisconnectJob disconnectJob = new DisconnectJob(dataSourceDescriptor);
        disconnectJob.addJobChangeListener(new JobChangeAdapter() {

            @Override
            public void done(IJobChangeEvent event) {
                IStatus result = disconnectJob.getConnectStatus();
                if (onFinish != null) {
                    onFinish.run();
                } else if (!result.isOK()) {
                    DBUserInterface.getInstance().showError(disconnectJob.getName(), null, result);
                }
            }
        });
        // Run in UI thread to update actions (some Eclipse magic)
        DBeaverUI.asyncExec(new Runnable() {

            @Override
            public void run() {
                disconnectJob.schedule();
            }
        });
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DisconnectJob(org.jkiss.dbeaver.runtime.jobs.DisconnectJob) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) ISaveablePart(org.eclipse.ui.ISaveablePart) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor)

Example 3 with ISaveablePart

use of org.eclipse.ui.ISaveablePart in project yamcs-studio by yamcs.

the class OPIEditor method getPropertySheetPage.

/**
 * Returns the undoable <code>PropertySheetPage</code> for this editor.
 *
 * @return the undoable <code>PropertySheetPage</code>
 */
protected PropertySheetPage getPropertySheetPage() {
    if (undoablePropertySheetPage == null) {
        undoablePropertySheetPage = new PropertySheetPage() {

            @Override
            protected ISaveablePart getSaveablePart() {
                return null;
            }
        };
        undoablePropertySheetPage.setRootEntry(new UndoablePropertySheetEntry(getCommandStack()));
    }
    return undoablePropertySheetPage;
}
Also used : PropertySheetPage(org.eclipse.ui.views.properties.PropertySheetPage) IPropertySheetPage(org.eclipse.ui.views.properties.IPropertySheetPage) UndoablePropertySheetEntry(org.eclipse.gef.ui.properties.UndoablePropertySheetEntry) ISaveablePart(org.eclipse.ui.ISaveablePart)

Example 4 with ISaveablePart

use of org.eclipse.ui.ISaveablePart in project dbeaver by serge-rider.

the class DataSourceHandler method disconnectDataSource.

public static void disconnectDataSource(DBPDataSourceContainer dataSourceContainer, @Nullable final Runnable onFinish) {
    // Save users
    for (DBPDataSourceTask user : dataSourceContainer.getTasks()) {
        if (user instanceof ISaveablePart) {
            if (!SaveChangesHandler.validateAndSave(new VoidProgressMonitor(), (ISaveablePart) user)) {
                return;
            }
        }
    }
    if (!checkAndCloseActiveTransaction(dataSourceContainer)) {
        return;
    }
    if (dataSourceContainer instanceof DataSourceDescriptor && dataSourceContainer.isConnected()) {
        final DataSourceDescriptor dataSourceDescriptor = (DataSourceDescriptor) dataSourceContainer;
        if (!ArrayUtils.isEmpty(Job.getJobManager().find(dataSourceDescriptor))) {
            // Already connecting/disconnecting - just return
            return;
        }
        final DisconnectJob disconnectJob = new DisconnectJob(dataSourceDescriptor);
        disconnectJob.addJobChangeListener(new JobChangeAdapter() {

            @Override
            public void done(IJobChangeEvent event) {
                IStatus result = disconnectJob.getConnectStatus();
                if (onFinish != null) {
                    onFinish.run();
                } else if (!result.isOK()) {
                    DBWorkbench.getPlatformUI().showError(disconnectJob.getName(), null, result);
                }
                DataSourcePropertyTester.firePropertyChange(DataSourcePropertyTester.PROP_CONNECTED);
            }
        });
        disconnectJob.schedule();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DisconnectJob(org.jkiss.dbeaver.runtime.jobs.DisconnectJob) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) DBPDataSourceTask(org.jkiss.dbeaver.model.DBPDataSourceTask) ISaveablePart(org.eclipse.ui.ISaveablePart) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor)

Aggregations

ISaveablePart (org.eclipse.ui.ISaveablePart)4 IStatus (org.eclipse.core.runtime.IStatus)2 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)2 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)2 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)2 DataSourceDescriptor (org.jkiss.dbeaver.registry.DataSourceDescriptor)2 DisconnectJob (org.jkiss.dbeaver.runtime.jobs.DisconnectJob)2 UndoablePropertySheetEntry (org.eclipse.gef.ui.properties.UndoablePropertySheetEntry)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 IPropertySheetPage (org.eclipse.ui.views.properties.IPropertySheetPage)1 PropertySheetPage (org.eclipse.ui.views.properties.PropertySheetPage)1 DBPDataSourceTask (org.jkiss.dbeaver.model.DBPDataSourceTask)1