Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centralize functionality for creating and identifying editor stacks #1806

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.e4.ui.internal.css.swt.ICTabRendering;
import org.eclipse.e4.ui.internal.workbench.PartStackUtil;
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
import org.eclipse.e4.ui.model.application.ui.MContext;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabFolderRenderer;
Expand Down Expand Up @@ -1329,15 +1326,7 @@ private void hideIconsForViewTabsPreferenceChanged() {

private boolean isPartOfEditorStack() {
MUIElement element = (MUIElement) parent.getData(AbstractPartRenderer.OWNING_ME);
EObject root = EcoreUtil.getRootContainer((EObject) element, true);
if (root instanceof MContext context) {
EModelService eModelService = context.getContext().get(EModelService.class);
if (eModelService != null) {
int location = eModelService.getElementLocation(element);
return (location & EModelService.IN_SHARED_AREA) != 0;
}
}
return false;
return PartStackUtil.isEditorStack(element);
}

private boolean getSwtRendererPreference(String prefName, boolean defaultValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.eclipse.e4.ui.di.UIEventTopic;
import org.eclipse.e4.ui.di.UISynchronize;
import org.eclipse.e4.ui.internal.workbench.OpaqueElementUtil;
import org.eclipse.e4.ui.internal.workbench.PartStackUtil;
import org.eclipse.e4.ui.internal.workbench.renderers.swt.BasicPartList;
import org.eclipse.e4.ui.internal.workbench.renderers.swt.SWTRenderersMessages;
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
Expand Down Expand Up @@ -128,8 +129,6 @@ public class StackRenderer extends LazyStackRenderer {
private static final String ONBOARDING_IMAGE = "EditorStack.OnboardingImage"; //$NON-NLS-1$
private static final String ONBOARDING_TEXT = "EditorStack.OnboardingText"; //$NON-NLS-1$

private static final String EDITOR_STACK_ID = "EditorStack"; //$NON-NLS-1$

/**
* Id of a a control.
*/
Expand Down Expand Up @@ -703,7 +702,7 @@ public Object createWidget(MUIElement element, Object parent) {
int location = modelService.getElementLocation(element);
boolean isInSharedArea = (location & EModelService.IN_SHARED_AREA) != 0;
if (isInSharedArea) {
pStack.getTags().add(EDITOR_STACK_ID);
PartStackUtil.makeEditorStack(pStack);
}

Composite parentComposite = (Composite) parent;
Expand All @@ -717,7 +716,7 @@ public Object createWidget(MUIElement element, Object parent) {
int styleOverride = getStyleOverride(pStack);
int style = styleOverride == -1 ? SWT.BORDER : styleOverride;
CTabFolder tabFolder = new CTabFolder(parentComposite, style);
if (pStack.getTags().contains("EditorStack")) { //$NON-NLS-1$
if (PartStackUtil.isEditorStack(element)) {
createOnboardingControls(tabFolder);
initializeOnboardingInformationInEditorStack(tabFolder);
}
Expand Down Expand Up @@ -1926,7 +1925,8 @@ private Stream<CTabFolder> getEditorTabFolders(MPerspective perspective) {
Predicate<Object> tabFolders = CTabFolder.class::isInstance;
Function<Object, CTabFolder> toTabFolder = CTabFolder.class::cast;

List<MPartStack> elements = modelService.findElements(perspective, null, MPartStack.class, List.of(EDITOR_STACK_ID));
List<MPartStack> elements = modelService.findElements(perspective, null, MPartStack.class,
List.of(PartStackUtil.EDITOR_STACK_TAG));
return elements.stream().map(MUIElement::getWidget).filter(tabFolders).map(toTabFolder);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ private PartStackUtil() {
* @param partStack the part stack to make the primary data stack
*/
public static void initializeAsPrimaryDataStack(MPartStack partStack) {
makeEditorStack(partStack);
partStack.getTags().add(PRIMARY_DATA_STACK_ID);
if (!partStack.getTags().contains(EDITOR_STACK_TAG)) {
partStack.getTags().add(EDITOR_STACK_TAG);
}
partStack.setElementId(PRIMARY_DATA_STACK_ID);
}

Expand All @@ -42,4 +40,26 @@ public static void initializeAsPrimaryDataStack(MPartStack partStack) {
public static boolean isPrimaryDataStack(MApplicationElement element) {
return element instanceof MPartStack && PRIMARY_DATA_STACK_ID.equals(element.getElementId());
}

/**
* @param element the element to check for being an editor stack
* @return whether the given element is marked as an editor stack
*/
public static boolean isEditorStack(MApplicationElement element) {
return element instanceof MPartStack && element.getTags().contains(EDITOR_STACK_TAG);
}

/**
* Marks the given part stack as an editor stack. In consequence calling
* {{@link #isEditorStack(MApplicationElement)} for the element will return
* {@code true}.
*
* @param partStack the part stack to mark as an editor stack
*/
public static void makeEditorStack(MPartStack partStack) {
if (!partStack.getTags().contains(EDITOR_STACK_TAG)) {
partStack.getTags().add(EDITOR_STACK_TAG);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public class ModeledPageLayout implements IPageLayout {
public static final String PERSP_SHORTCUT_TAG = "persp.perspSC:"; //$NON-NLS-1$
public static final String SHOW_IN_PART_TAG = "persp.showIn:"; //$NON-NLS-1$
public static final String SHOW_VIEW_TAG = "persp.viewSC:"; //$NON-NLS-1$
public static final String EDITOR_STACK_TAG = "EditorStack"; //$NON-NLS-1$
public static final String HIDDEN_MENU_PREFIX = "persp.hideMenuSC:"; //$NON-NLS-1$
public static final String HIDDEN_TOOLBAR_PREFIX = "persp.hideToolbarSC:"; //$NON-NLS-1$
public static final String HIDDEN_ACTIONSET_PREFIX = "persp.hideActionSetSC:"; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.HashMap;
import java.util.List;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.internal.workbench.PartStackUtil;
import org.eclipse.e4.ui.internal.workbench.swt.CSSConstants;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.descriptor.basic.MPartDescriptor;
Expand Down Expand Up @@ -411,7 +412,7 @@ public void testBug573518_SharedPartToolbarShown2() {

@Test
public void testOnboardingRenderedWithCorrectSizeForEditorStack() {
partStack.getTags().add("EditorStack");
PartStackUtil.makeEditorStack(partStack);

contextRule.createAndRunWorkbench(window);

Expand Down Expand Up @@ -445,7 +446,7 @@ public void testOnboardingNotRenderedForNonEditorStack() {
@Test
public void testOnboardingIsFilled() {
MPerspective perspective = createPerspective();
partStack.getTags().add("EditorStack");
PartStackUtil.makeEditorStack(partStack);

contextRule.createAndRunWorkbench(window);
switchToPerspective(perspective);
Expand Down Expand Up @@ -500,13 +501,13 @@ private void assertFilledOnboardingInformation(CTabFolder tabFolder) {
@Test
public void testOnboardingIsFilledForEveryEditorStack() {
MPerspective perspective = createPerspective();
partStack.getTags().add("EditorStack");
PartStackUtil.makeEditorStack(partStack);

contextRule.createAndRunWorkbench(window);

// Create second editor stack
MPartStack secondPartStack = ems.createModelElement(MPartStack.class);
secondPartStack.getTags().add("EditorStack");
PartStackUtil.makeEditorStack(secondPartStack);
MPlaceholder placeholder = ems.createModelElement(MPlaceholder.class);
placeholder.setRef(secondPartStack);
perspective.getChildren().add(placeholder);
Expand All @@ -520,7 +521,7 @@ public void testOnboardingIsFilledForEveryEditorStack() {

@Test
public void testOnboardingIsHiddenWhenEditorOpened() {
partStack.getTags().add("EditorStack");
PartStackUtil.makeEditorStack(partStack);

contextRule.createAndRunWorkbench(window);

Expand Down
Loading