Search in sources :

Example 1 with PartSite

use of org.eclipse.ui.internal.PartSite in project eclipse.platform.text by eclipse.

the class StatusEditorTest method doNotThrowOnActivationInStale.

/*
	 * https://bugs.eclipse.org/bugs/attachment.cgi?bugid=320672
	 *
	 * No exceptions are thrown when a status editor displaying an erroneous status is activated with a mouse click.
	 * @throws Exception
	 */
@Test
public void doNotThrowOnActivationInStale() throws Exception {
    IEditorPart editor1 = openNonExistentFile(page, new URI("file:/1.txt"));
    openNonExistentFile(page, new URI("file:/2.txt"));
    ILog log = Platform.getLog(Platform.getBundle("org.eclipse.e4.ui.workbench"));
    List<String> logEvents = new ArrayList<>();
    ILogListener listener = (status, plugin) -> logEvents.add(status.toString());
    log.addLogListener(listener);
    // Clicks are not equivalent to activation from API, so we need this
    // hack to imitate tab clicks.
    CTabFolder folder = (CTabFolder) (((PartSite) editor1.getSite()).getModel().getParent().getWidget());
    try {
        folder.setSelection(0);
        processEvents();
        folder.setSelection(1);
        processEvents();
    } finally {
        log.removeLogListener(listener);
    }
    if (!logEvents.isEmpty()) {
        Assert.assertEquals("Unexpected errors logged", "", logEvents.toString());
    }
}
Also used : WorkbenchException(org.eclipse.ui.WorkbenchException) ForwardingDocumentProvider(org.eclipse.ui.editors.text.ForwardingDocumentProvider) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) PartSite(org.eclipse.ui.internal.PartSite) ArrayList(java.util.ArrayList) IStatus(org.eclipse.core.runtime.IStatus) After(org.junit.After) URI(java.net.URI) TextEditor(org.eclipse.ui.editors.text.TextEditor) Method(java.lang.reflect.Method) EFS(org.eclipse.core.filesystem.EFS) IEditorPart(org.eclipse.ui.IEditorPart) Before(org.junit.Before) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) CTabFolder(org.eclipse.swt.custom.CTabFolder) ILog(org.eclipse.core.runtime.ILog) PlatformUI(org.eclipse.ui.PlatformUI) Status(org.eclipse.core.runtime.Status) Test(org.junit.Test) Display(org.eclipse.swt.widgets.Display) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) EditorsUI(org.eclipse.ui.editors.text.EditorsUI) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput) List(java.util.List) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) Platform(org.eclipse.core.runtime.Platform) Assert(org.junit.Assert) ILogListener(org.eclipse.core.runtime.ILogListener) CTabFolder(org.eclipse.swt.custom.CTabFolder) PartSite(org.eclipse.ui.internal.PartSite) ArrayList(java.util.ArrayList) ILog(org.eclipse.core.runtime.ILog) ILogListener(org.eclipse.core.runtime.ILogListener) IEditorPart(org.eclipse.ui.IEditorPart) URI(java.net.URI) Test(org.junit.Test)

Example 2 with PartSite

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

the class ObjectPropertiesEditor method createFoldersPanel.

private Composite createFoldersPanel(Composite parent, TabbedFolderInfo[] folders) {
    // Properties
    Composite foldersPlaceholder = UIUtils.createPlaceholder(parent, 1, 0);
    foldersPlaceholder.setLayoutData(new GridData(GridData.FILL_BOTH));
    boolean single = folders.length < 4;
    if (single) {
        for (TabbedFolderInfo fi : folders) {
            if (!fi.isEmbeddable()) {
                single = false;
            }
        }
    }
    folderComposite = new TabbedFolderComposite(foldersPlaceholder, SWT.LEFT | (single ? SWT.SINGLE : SWT.MULTI));
    folderComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    // Load properties
    {
        String objectId = "PropertiesEditor." + getDatabaseObject().getClass().getName();
        folderComposite.setFolders(objectId, folders);
    }
    // Collect section contributors
    GlobalContributorManager contributorManager = GlobalContributorManager.getInstance();
    for (TabbedFolderInfo folder : folders) {
        ITabbedFolder page = folder.getContents();
        if (page instanceof IDatabaseEditorContributorUser) {
            IEditorActionBarContributor contributor = ((IDatabaseEditorContributorUser) page).getContributor(contributorManager);
            if (contributor != null) {
                contributorManager.addContributor(contributor, this);
                pageContributors.put(page, contributor);
            }
        }
        if (page instanceof ISaveablePart) {
            nestedSaveable.add((ISaveablePart) page);
        }
    }
    folderComposite.switchFolder(curFolderId);
    folderComposite.addFolderListener(folderId1 -> {
        if (CommonUtils.equalObjects(curFolderId, folderId1)) {
            return;
        }
        IActionBars actionBars = getEditorSite().getActionBars();
        MultiPageEditorPart mainEditor = ((MultiPageEditorSite) getSite()).getMultiPageEditor();
        IWorkbenchPartSite mainEditorSite = mainEditor.getSite();
        if (mainEditorSite instanceof PartSite) {
            ((PartSite) mainEditorSite).deactivateActionBars(true);
        }
        ITabbedFolder activeFolder = folderComposite.getActiveFolder();
        if (activeFolder instanceof TabbedFolderPageEditor) {
            IEditorActionBarContributor activeFolderContributor = pageContributors.get(activeFolder);
            if (activeFolderContributor != null) {
                // FIXME: do not add extra contributions as they will be there forever (never cleaned up)
                // if (activeFolderContributor instanceof EditorActionBarContributor) {
                // ((EditorActionBarContributor) activeFolderContributor).contributeToStatusLine(
                // actionBars.getStatusLineManager());
                // }
                IEditorPart activeEditor = ((TabbedFolderPageEditor) activeFolder).getEditor();
                activeFolderContributor.setActiveEditor(activeEditor);
            }
        } else if (activeFolder instanceof TabbedFolderPageNode) {
            if (mainEditor instanceof EntityEditor) {
                // Overwrite external contributor actions with EntityEditor actions
                new EditorSearchActionsContributor().setActiveEditor(((EntityEditor) mainEditor).getActiveEditor());
            }
        }
        actionBars.updateActionBars();
        synchronized (folderListeners) {
            curFolderId = folderId1;
            for (ITabbedFolderListener listener : folderListeners) {
                listener.folderSelected(folderId1);
            }
        }
    });
    return foldersPlaceholder;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) PartSite(org.eclipse.ui.internal.PartSite) GridData(org.eclipse.swt.layout.GridData) MultiPageEditorSite(org.eclipse.ui.part.MultiPageEditorSite)

Aggregations

PartSite (org.eclipse.ui.internal.PartSite)2 Method (java.lang.reflect.Method)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 EFS (org.eclipse.core.filesystem.EFS)1 ILog (org.eclipse.core.runtime.ILog)1 ILogListener (org.eclipse.core.runtime.ILogListener)1 IStatus (org.eclipse.core.runtime.IStatus)1 Platform (org.eclipse.core.runtime.Platform)1 Status (org.eclipse.core.runtime.Status)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 GridData (org.eclipse.swt.layout.GridData)1 Composite (org.eclipse.swt.widgets.Composite)1 Display (org.eclipse.swt.widgets.Display)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 PlatformUI (org.eclipse.ui.PlatformUI)1 WorkbenchException (org.eclipse.ui.WorkbenchException)1