blob: ecfac318824604fea90c2f695c67aec9d8be5cd3 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2012, 2021 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.internal.r.ui.datafilterview;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.forms.FormColors;
import org.eclipse.ui.forms.events.ExpansionAdapter;
import org.eclipse.ui.forms.events.ExpansionEvent;
import org.eclipse.ui.forms.events.IExpansionListener;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.SharedScrolledComposite;
public class ScrolledPageComposite extends SharedScrolledComposite {
private static FormToolkit gDialogsFormToolkit;
private static FormToolkit getViewFormToolkit() {
if (gDialogsFormToolkit == null) {
final FormColors colors= new FormColors(Display.getCurrent());
gDialogsFormToolkit= new FormToolkit(colors);
}
return gDialogsFormToolkit;
}
private final FormToolkit toolkit;
private IExpansionListener expansionListener;
private int delayReflowCounter;
public ScrolledPageComposite(final Composite parent) {
this(parent, SWT.H_SCROLL | SWT.V_SCROLL);
}
public ScrolledPageComposite(final Composite parent, final int style) {
super(parent, style);
if ((style & SWT.H_SCROLL) == 0) {
setExpandHorizontal(true);
}
setFont(parent.getFont());
this.toolkit= getViewFormToolkit();
setExpandHorizontal(true);
setExpandVertical(true);
final Composite body= new Composite(this, SWT.NONE);
setContent(body);
setFont(parent.getFont());
setBackground(this.toolkit.getColors().getBackground());
}
@Override
public Composite getContent() {
return (Composite) super.getContent();
}
@Override
public void setDelayedReflow(final boolean delayedReflow) {
if (delayedReflow) {
this.delayReflowCounter++;
}
else {
this.delayReflowCounter--;
}
super.setDelayedReflow(this.delayReflowCounter > 0);
}
public void adaptChild(final Control childControl) {
if (childControl instanceof ExpandableRowComposite) {
this.toolkit.adapt(childControl, true, false);
if (this.expansionListener == null) {
this.expansionListener= new ExpansionAdapter() {
@Override
public void expansionStateChanged(final ExpansionEvent e) {
expandedStateChanged();
}
};
}
((ExpandableRowComposite) childControl).addExpansionListener(this.expansionListener);
}
else if (childControl instanceof Composite) {
this.toolkit.adapt(childControl, false, false);
final Control[] children= ((Composite) childControl).getChildren();
for (int i= 0; i < children.length; i++) {
this.toolkit.adapt(children[i], true, false);
}
}
else {
this.toolkit.adapt(childControl, true, false);
}
}
protected void expandedStateChanged() {
reflow(true);
}
}