use of org.eclipse.swt.events.ControlListener in project netxms by netxms.
the class MainWindow method createContents.
/**
* @see org.eclipse.jface.window.Window#createContents(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createContents(Composite parent) {
Font font = ThemeEngine.getFont("TopMenu");
windowContent = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.verticalSpacing = 0;
layout.numColumns = verticalLayout ? 2 : 1;
windowContent.setLayout(layout);
Composite menuArea = new Composite(windowContent, SWT.NONE);
layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.numColumns = verticalLayout ? 1 : 2;
menuArea.setLayout(layout);
GridData gd = new GridData();
if (verticalLayout) {
gd.grabExcessVerticalSpace = true;
gd.verticalAlignment = SWT.FILL;
gd.verticalSpan = 2;
} else {
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
}
menuArea.setLayoutData(gd);
Label appLogo = new Label(menuArea, SWT.CENTER);
appLogo.setImage(ResourceManager.getImage("icons/app_logo.png"));
appLogo.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
mainMenu = new ToolBar(menuArea, SWT.FLAT | SWT.WRAP | SWT.RIGHT | (verticalLayout ? SWT.VERTICAL : SWT.HORIZONTAL));
mainMenu.setFont(font);
gd = new GridData();
if (verticalLayout) {
gd.grabExcessVerticalSpace = true;
gd.verticalAlignment = SWT.FILL;
} else {
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
}
mainMenu.setLayoutData(gd);
toolsMenu = new ToolBar(menuArea, SWT.FLAT | SWT.WRAP | SWT.RIGHT | (verticalLayout ? SWT.VERTICAL : SWT.HORIZONTAL));
toolsMenu.setFont(font);
ToolItem userMenu = new ToolItem(toolsMenu, SWT.PUSH);
userMenu.setImage(ResourceManager.getImage("icons/user-menu.png"));
NXCSession session = Registry.getSession();
if (verticalLayout)
userMenu.setToolTipText(session.getUserName() + "@" + session.getServerName());
else
userMenu.setText(session.getUserName() + "@" + session.getServerName());
userMenu.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Rectangle bounds = userMenu.getBounds();
showUserMenu(toolsMenu.toDisplay(verticalLayout ? new Point(bounds.x + bounds.width + 2, bounds.y) : new Point(bounds.x, bounds.y + bounds.height + 2)));
}
});
ToolItem appPreferencesMenu = new ToolItem(toolsMenu, SWT.PUSH);
appPreferencesMenu.setImage(ResourceManager.getImage("icons/preferences.png"));
appPreferencesMenu.setToolTipText("Console preferences");
appPreferencesMenu.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
showPreferences();
}
});
messageArea = new MessageArea(windowContent, SWT.NONE);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
messageArea.setLayoutData(gd);
perspectiveArea = new Composite(windowContent, SWT.NONE);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
perspectiveArea.setLayoutData(gd);
perspectiveArea.addControlListener(new ControlListener() {
@Override
public void controlResized(ControlEvent e) {
resizePerspectiveAreaContent();
}
@Override
public void controlMoved(ControlEvent e) {
}
});
setupPerspectiveSwitcher();
final Display display = parent.getDisplay();
display.addFilter(SWT.KeyDown, new Listener() {
@Override
public void handleEvent(Event e) {
if (// Only process keystrokes directed to this window
getShell() == display.getActiveShell())
processKeyDownEvent(e.stateMask, e.keyCode);
}
});
switchToPerspective("Pinboard");
switchToPerspective(PreferenceStore.getInstance().getAsString("MainWindow.CurrentPerspective"));
String motd = session.getMessageOfTheDay();
if ((motd != null) && !motd.isEmpty())
addMessage(MessageArea.INFORMATION, session.getMessageOfTheDay());
return windowContent;
}
use of org.eclipse.swt.events.ControlListener in project janrufmonitor by tbrandt77.
the class AbstractApplication method configureShell.
protected void configureShell(Shell shell) {
super.configureShell(shell);
shell.addControlListener(new ControlListener() {
public void controlMoved(ControlEvent e) {
internalSavePosition(e.display.getActiveShell());
storeConfiguration();
}
public void controlResized(ControlEvent e) {
internalSavePosition(e.display.getActiveShell());
storeConfiguration();
}
});
boolean isMaximized = (this.getConfiguration().getProperty(CFG_MAXIMIZED, "false").equalsIgnoreCase("true") ? true : false);
if (isMaximized) {
shell.setMaximized(true);
} else {
shell.setMaximized(false);
shell.setBounds(Integer.parseInt(this.getConfiguration().getProperty(CFG_POSITION_X, "0")), Integer.parseInt(this.getConfiguration().getProperty(CFG_POSITION_Y, "0")), Integer.parseInt(this.getConfiguration().getProperty(CFG_WIDTH, "800")), Integer.parseInt(this.getConfiguration().getProperty(CFG_HEIGHT, "600")));
}
shell.setText(this.getI18nManager().getString(this.getNamespace(), "title", "label", this.getLanguage()));
shell.setImage(this.getIcon());
}
use of org.eclipse.swt.events.ControlListener in project eclipse.platform.swt by eclipse-platform.
the class Test_org_eclipse_swt_widgets_Control method test_addControlListenerControlMovedAdapterLorg_eclipse_swt_events_ControlListener.
@Test
public void test_addControlListenerControlMovedAdapterLorg_eclipse_swt_events_ControlListener() {
ControlListener listener = ControlListener.controlMovedAdapter(e -> eventOccurred = true);
control.addControlListener(listener);
eventOccurred = false;
control.notifyListeners(SWT.Move, new Event());
assertTrue(eventOccurred);
eventOccurred = false;
control.notifyListeners(SWT.Resize, new Event());
assertFalse(eventOccurred);
control.removeControlListener(listener);
eventOccurred = false;
control.notifyListeners(SWT.Move, new Event());
assertFalse(eventOccurred);
control.notifyListeners(SWT.Resize, new Event());
assertFalse(eventOccurred);
}
use of org.eclipse.swt.events.ControlListener in project eclipse.platform.swt by eclipse-platform.
the class Bug97863_TableColumnDragging method main.
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setBounds(10, 10, 400, 400);
final Table tree = new Table(shell, SWT.NONE);
tree.setBounds(10, 10, 300, 300);
tree.setHeaderVisible(true);
ControlListener controlListener = new ControlListener() {
@Override
public void controlResized(ControlEvent e) {
System.out.println("column resized: " + e.widget);
}
@Override
public void controlMoved(ControlEvent e) {
System.out.println("column moved: " + e.widget);
}
};
TableColumn column = new TableColumn(tree, SWT.NONE);
column.setWidth(50);
column.setText("col 0");
column.setMoveable(true);
column.addControlListener(controlListener);
column = new TableColumn(tree, SWT.NONE);
column.setWidth(50);
column.setText("col 1");
column.setMoveable(true);
column.addControlListener(controlListener);
column = new TableColumn(tree, SWT.NONE);
column.setWidth(50);
column.setText("col 2");
column.setMoveable(true);
column.addControlListener(controlListener);
column = new TableColumn(tree, SWT.NONE);
column.setWidth(50);
column.setText("col 3");
column.setMoveable(true);
column.addControlListener(controlListener);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
use of org.eclipse.swt.events.ControlListener in project eclipse.pde by eclipse-pde.
the class RepositoryReferenceSection method createClient.
@Override
protected void createClient(Section section, FormToolkit toolkit) {
fModel = (ISiteModel) getPage().getModel();
fModel.addModelChangedListener(this);
section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
GridData sectionData = new GridData(GridData.FILL_BOTH);
sectionData.verticalSpan = 2;
section.setLayoutData(sectionData);
Composite container = createClientContainer(section, 2, toolkit);
createViewerPartControl(container, SWT.MULTI | SWT.FULL_SELECTION, 2, toolkit);
container.setLayoutData(new GridData(GridData.FILL_BOTH));
TablePart tablePart = getTablePart();
fRepositoryTable = tablePart.getTableViewer();
final Table table = fRepositoryTable.getTable();
final TableColumn locationColumn = new TableColumn(table, SWT.LEFT);
locationColumn.setText(PDEUIMessages.UpdatesSection_LocationColumn);
locationColumn.setWidth(240);
final TableColumn enabledColumn = new TableColumn(table, SWT.LEFT);
enabledColumn.setText(PDEUIMessages.UpdatesSection_EnabledColumn);
enabledColumn.setWidth(120);
GridData data = (GridData) tablePart.getControl().getLayoutData();
data.minimumWidth = 200;
tablePart.setButtonEnabled(0, isEditable());
tablePart.setButtonEnabled(1, isEditable());
table.setHeaderVisible(true);
toolkit.paintBordersFor(container);
table.addControlListener(new ControlListener() {
@Override
public void controlMoved(ControlEvent e) {
}
@Override
public void controlResized(ControlEvent e) {
int size = table.getSize().x;
locationColumn.setWidth(size / 6 * 5);
enabledColumn.setWidth(size / 6 * 1);
}
});
fRepositoryTable.setLabelProvider(new LabelProvider());
fRepositoryTable.setContentProvider(new ContentProvider());
fRepositoryTable.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
IRepositoryReference r1 = (IRepositoryReference) e1;
IRepositoryReference r2 = (IRepositoryReference) e2;
return super.compare(viewer, r1.getURL(), r2.getURL());
}
});
fRepositoryTable.setInput(getSite());
createEditors();
section.setClient(container);
section.setText(PDEUIMessages.RepositorySection_title);
section.setDescription(PDEUIMessages.RepositorySection_description);
}
Aggregations