From ea4f4824e668159dd8494d0580345788781b76e7 Mon Sep 17 00:00:00 2001 From: Martin Lippert Date: Wed, 22 Jun 2022 11:29:11 +0200 Subject: [PATCH] have a duplicate of the new FillLayoutFactory around for as long as we support Eclipse 2021-12 and 2022-03 release --- .../boot/ls/commands/FillLayoutFactory.java | 182 ++++++++++++++++++ .../boot/ls/commands/SelectRecipesDialog.java | 1 - 2 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/commands/FillLayoutFactory.java diff --git a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/commands/FillLayoutFactory.java b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/commands/FillLayoutFactory.java new file mode 100644 index 000000000..223884231 --- /dev/null +++ b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/commands/FillLayoutFactory.java @@ -0,0 +1,182 @@ +/******************************************************************************* + * Copyright (c) 2020 vogella GmbH and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Lars Vogel - initial API and implementation + *******************************************************************************/ +package org.springframework.tooling.boot.ls.commands; + +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; + +// +// THIS IS A COPY OF THE NEW FILLLAYOUTFACTORY CLASS THAT DOESN'T EXIST YET +// IN ECLIPSE 2022-03 RELEASE. +// +// This copy serves as a fill-in for as long as we support 2022-03. +// + + +/** + * FillLayoutFactory creates and initializes {@link FillLayout fill layouts}. It + * is used as a shorthand for writing "new FillLayout()" and + * initializing some fields. In this case the main benefit is a more concise + * syntax and the ability to create more than one identical {@link FillLayout} + * from the same factory. Changing a property of the factory will affect future + * layouts created by the factory, but has no effect on layouts that have + * already been created. + * + * @since 3.26 + */ +public final class FillLayoutFactory { + + /** + * Template layout. The factory will create copies of this layout. + */ + private FillLayout layout; + + /** + * Creates a factory that creates copies of the given layout. + * + * @return a new FillLayoutFactory instance with a new FillLayout + */ + public static FillLayoutFactory fillDefaults() { + return new FillLayoutFactory(copyLayout(new FillLayout())); + } + + /** + * Creates a new FillLayoutFactory that will create copies of the given layout. + * + * @param l layout to copy + */ + private FillLayoutFactory(FillLayout l) { + this.layout = l; + } + + /** + * Creates a factory that creates copies of the given layout. + * + * @param l layout to copy + * @return a new FillLayoutFactory instance that creates copies of the given + * layout + */ + public static FillLayoutFactory createFrom(FillLayout l) { + return new FillLayoutFactory(copyLayout(l)); + } + + + /** + * Creates a copy of the receiver. + * + * @return a copy of the receiver + */ + public FillLayoutFactory copy() { + return new FillLayoutFactory(create()); + } + + + /** + * Sets the margins for layouts created with this factory. The margins + * are the distance between the outer cells and the edge of the layout. + * + * @param margins margin size (pixels) + * @return this + */ + public FillLayoutFactory margins(Point margins) { + layout.marginWidth = margins.x; + layout.marginHeight = margins.y; + return this; + } + + /** + * Sets the margins for layouts created with this factory. The margins are the + * distance between the outer cells and the edge of the layout. + * + * @param width margin width (pixels) + * @param height margin height (pixels) + * @return this + */ + public FillLayoutFactory margins(int width, int height) { + layout.marginWidth = width; + layout.marginHeight = height; + return this; + } + + /** + * Sets the margins for layouts created with this factory. The margins specify + * the number of pixels of width and height of the layout. Note that these + * margins will be added to the ones specified by {@link #margins(int, int)}. + * + * @param width width margin size (pixels) + * @param height height margin size (pixels) + * @return this + * + * @since 3.3 + */ + public FillLayoutFactory extendedMargins(int width, int height) { + layout.marginWidth = layout.marginWidth + width; + layout.marginHeight = layout.marginHeight + height; + return this; + } + + + /** + * Creates a new {@code FillLayout}, and initializes it with values from the + * factory. + * + * @return a new initialized {@code FillLayout}. + * @see #applyTo + */ + public FillLayout create() { + return copyLayout(layout); + } + + /** + * Creates a new {@code FillLayout} and attaches it to the given composite. Does + * not create the layout data of any of the controls in the composite. + * + * @param c composite whose layout will be set + * @see #create + * @see FillLayoutFactory + */ + public void applyTo(Composite c) { + c.setLayout(copyLayout(layout)); + } + + /** + * Copies the given {@code FillLayout} instance + * + * @param l layout to copy + * @return a new FillLayout + */ + public static FillLayout copyLayout(FillLayout l) { + FillLayout result = new FillLayout(); + result.marginHeight = l.marginHeight; + result.marginWidth = l.marginWidth; + result.spacing = l.spacing; + + return result; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("FillLayout()\n"); //$NON-NLS-1$ + if (layout.marginWidth != 0 || layout.marginHeight != 0) { + builder.append(" .margins("); //$NON-NLS-1$ + builder.append(layout.marginWidth); + builder.append(", "); //$NON-NLS-1$ + builder.append(layout.marginHeight); + builder.append(")\n"); //$NON-NLS-1$ + } + return builder.toString(); + } +} diff --git a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/commands/SelectRecipesDialog.java b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/commands/SelectRecipesDialog.java index 8ae43dc35..8b5a300a1 100644 --- a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/commands/SelectRecipesDialog.java +++ b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/commands/SelectRecipesDialog.java @@ -18,7 +18,6 @@ import org.eclipse.jdt.ui.PreferenceConstants; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.StatusDialog; import org.eclipse.jface.internal.text.html.HTMLPrinter; -import org.eclipse.jface.layout.FillLayoutFactory; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.resource.ColorRegistry; import org.eclipse.jface.resource.JFaceResources;