-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
.../src/main/java/de/sebthom/eclipse/commons/prefs/fieldeditor/HorizontalSeparatorField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* SPDX-FileCopyrightText: © Sebastian Thomschke and contributors. | ||
* SPDX-FileContributor: Sebastian Thomschke | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* SPDX-ArtifactOfProjectHomePage: https://github.com/sebthom/eclipse-commons | ||
*/ | ||
package de.sebthom.eclipse.commons.prefs.fieldeditor; | ||
|
||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.eclipse.jface.preference.FieldEditor; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.layout.GridData; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.swt.widgets.Label; | ||
|
||
/** | ||
* A pseudo field editor for displaying a horizontal separator. | ||
* | ||
* @author Sebastian Thomschke | ||
*/ | ||
public class HorizontalSeparatorField extends FieldEditor { | ||
|
||
private @Nullable Label separator; | ||
private @Nullable GridData separatorLayoutData; | ||
|
||
public HorizontalSeparatorField(final Composite parent) { | ||
super("unused", "", parent); | ||
} | ||
|
||
@Override | ||
protected void adjustForNumColumns(final int numColumns) { | ||
final var labelLayoutData = separatorLayoutData; | ||
if (labelLayoutData != null) { | ||
labelLayoutData.horizontalSpan = numColumns; | ||
} else { | ||
separatorLayoutData = new GridData(GridData.FILL, GridData.CENTER, false, false, numColumns, 1); | ||
} | ||
} | ||
|
||
@Override | ||
protected void doFillIntoGrid(final Composite parent, final int numColumns) { | ||
adjustForNumColumns(numColumns); | ||
getLabelControl(parent).setLayoutData(separatorLayoutData); | ||
} | ||
|
||
@Override | ||
protected void doLoad() { | ||
// ignored | ||
} | ||
|
||
@Override | ||
protected void doLoadDefault() { | ||
// ignored | ||
} | ||
|
||
@Override | ||
protected void doStore() { | ||
// ignored | ||
} | ||
|
||
@Override | ||
public Label getLabelControl(final Composite parent) { | ||
var separator = this.separator; | ||
if (separator == null || separator.isDisposed()) { | ||
separator = this.separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL); | ||
} else { | ||
checkParent(separator, parent); | ||
} | ||
return separator; | ||
} | ||
|
||
@Override | ||
public int getNumberOfControls() { | ||
return 1; | ||
} | ||
|
||
} |