use of org.eclipse.jface.viewers.ISelectionChangedListener in project xtext-eclipse by eclipse.
the class TraceEditor method createPageContainer.
@Override
protected Composite createPageContainer(final Composite parent) {
Composite tree = new Composite(parent, SWT.NONE);
final Sash sash = new Sash(parent, SWT.HORIZONTAL);
text = new StyledText(parent, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
text.setFont(JFaceResources.getTextFont());
final FormLayout form = new FormLayout();
parent.setLayout(form);
FormData treeData = new FormData();
treeData.left = new FormAttachment(0, 0);
treeData.right = new FormAttachment(100, 0);
treeData.top = new FormAttachment(0, 0);
treeData.bottom = new FormAttachment(sash, 0);
tree.setLayoutData(treeData);
final int limit = 20, percent = 50;
final FormData sashData = new FormData();
sashData.left = new FormAttachment(0, 0);
sashData.top = new FormAttachment(percent, 0);
sashData.right = new FormAttachment(100, 0);
sash.setLayoutData(sashData);
sash.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
Rectangle sashRect = sash.getBounds();
Rectangle parentRect = parent.getClientArea();
int bottom = parentRect.height - sashRect.height - limit;
e.y = Math.max(Math.min(e.y, bottom), limit);
if (e.y != sashRect.y) {
sashData.top = new FormAttachment(0, e.y);
parent.layout();
}
}
});
FormData textData = new FormData();
textData.left = new FormAttachment(0, 0);
textData.right = new FormAttachment(100, 0);
textData.top = new FormAttachment(sash, 0);
textData.bottom = new FormAttachment(100, 0);
text.setLayoutData(textData);
addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
if (selection instanceof IStructuredSelection) {
try {
Object x = ((IStructuredSelection) selection).getFirstElement();
if (x instanceof EObject)
updateText((EObject) x);
if (x instanceof Resource)
updateText(((Resource) x).getContents().get(0));
} catch (Exception e) {
text.setText(Throwables.getStackTraceAsString(e));
}
}
}
});
return tree;
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project archi by archimatetool.
the class ColoursFontsPreferencePage method createColoursTab.
private void createColoursTab() {
// Reset everything
resetColorsCache(false);
fImageRegistry = new ImageRegistry();
Composite client = new Composite(fTabfolder, SWT.NULL);
client.setLayout(new GridLayout(2, false));
TabItem item = new TabItem(fTabfolder, SWT.NONE);
item.setText(Messages.ColoursFontsPreferencePage_23);
item.setControl(client);
Label label = new Label(client, SWT.NULL);
label.setText(Messages.ColoursFontsPreferencePage_0);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
label.setLayoutData(gd);
// Tree
fTreeViewer = new TreeViewer(client);
gd = new GridData(GridData.FILL_BOTH);
// need this to set a smaller height
gd.heightHint = 80;
fTreeViewer.getTree().setLayoutData(gd);
// Tree Double-click listener
fTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
Object[] selected = ((IStructuredSelection) fTreeViewer.getSelection()).toArray();
if (isValidTreeSelection(selected)) {
RGB newRGB = openColorDialog(selected[0]);
if (newRGB != null) {
for (Object object : selected) {
setColor(object, newRGB);
}
}
}
}
});
// Tree Selection Changed Listener
fTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
Object[] selected = ((IStructuredSelection) event.getSelection()).toArray();
fEditFillColorButton.setEnabled(isValidTreeSelection(selected));
fResetFillColorButton.setEnabled(isValidTreeSelection(selected));
}
});
// Tree Content Provider
fTreeViewer.setContentProvider(new ITreeContentProvider() {
@Override
public void dispose() {
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public Object[] getElements(Object inputElement) {
if (inputElement instanceof String) {
return new Object[] { new TreeGrouping(Messages.ColoursFontsPreferencePage_32, ArchimateModelUtils.getStrategyClasses()), new TreeGrouping(Messages.ColoursFontsPreferencePage_7, ArchimateModelUtils.getBusinessClasses()), new TreeGrouping(Messages.ColoursFontsPreferencePage_8, ArchimateModelUtils.getApplicationClasses()), new TreeGrouping(Messages.ColoursFontsPreferencePage_9, ArchimateModelUtils.getTechnologyClasses()), new TreeGrouping(Messages.ColoursFontsPreferencePage_33, ArchimateModelUtils.getPhysicalClasses()), new TreeGrouping(Messages.ColoursFontsPreferencePage_10, ArchimateModelUtils.getMotivationClasses()), new TreeGrouping(Messages.ColoursFontsPreferencePage_11, ArchimateModelUtils.getImplementationMigrationClasses()), new TreeGrouping(Messages.ColoursFontsPreferencePage_17, ArchimateModelUtils.getOtherClasses()), new TreeGrouping(Messages.ColoursFontsPreferencePage_34, new Object[] { IArchimatePackage.eINSTANCE.getDiagramModelNote(), IArchimatePackage.eINSTANCE.getDiagramModelGroup() }), DEFAULT_ELEMENT_LINE_COLOR, DEFAULT_CONNECTION_LINE_COLOR };
}
return null;
}
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof TreeGrouping) {
return ((TreeGrouping) parentElement).children;
}
return null;
}
@Override
public Object getParent(Object element) {
return null;
}
@Override
public boolean hasChildren(Object element) {
return element instanceof TreeGrouping;
}
});
// Tree Label Provider
fTreeViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof EClass) {
return ArchiLabelProvider.INSTANCE.getDefaultName((EClass) element);
}
if (element instanceof TreeGrouping) {
return ((TreeGrouping) element).title;
}
if (element instanceof String) {
String s = (String) element;
if (s.equals(DEFAULT_ELEMENT_LINE_COLOR)) {
return Messages.ColoursFontsPreferencePage_12;
}
if (s.equals(DEFAULT_CONNECTION_LINE_COLOR)) {
return Messages.ColoursFontsPreferencePage_18;
}
}
return null;
}
@Override
public Image getImage(Object element) {
if (element instanceof TreeGrouping) {
return IArchiImages.ImageFactory.getImage(IArchiImages.ECLIPSE_IMAGE_FOLDER);
}
return getColorSwatch(element);
}
// Create a coloured image based on colour and add to the image registry
private Image getColorSwatch(Object object) {
String key = getColorKey(object);
Image image = fImageRegistry.get(key);
if (image == null) {
image = new Image(Display.getCurrent(), 16, 16);
GC gc = new GC(image);
SWTGraphics graphics = new SWTGraphics(gc);
graphics.setBackgroundColor(fColorsCache.get(object));
graphics.fillRectangle(0, 0, 15, 15);
graphics.drawRectangle(0, 0, 15, 15);
gc.dispose();
graphics.dispose();
fImageRegistry.put(key, image);
}
return image;
}
});
// fTreeViewer.setAutoExpandLevel(2);
// Set Content in Tree
// $NON-NLS-1$
fTreeViewer.setInput("");
// Buttons
Composite buttonClient = new Composite(client, SWT.NULL);
gd = new GridData(SWT.TOP, SWT.TOP, false, false);
buttonClient.setLayoutData(gd);
buttonClient.setLayout(new GridLayout());
// Edit...
fEditFillColorButton = new Button(buttonClient, SWT.PUSH);
fEditFillColorButton.setText(Messages.ColoursFontsPreferencePage_13);
fEditFillColorButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fEditFillColorButton.setEnabled(false);
fEditFillColorButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
Object[] selected = ((IStructuredSelection) fTreeViewer.getSelection()).toArray();
if (isValidTreeSelection(selected)) {
RGB newRGB = openColorDialog(selected[0]);
if (newRGB != null) {
for (Object object : selected) {
setColor(object, newRGB);
}
}
}
}
});
// Reset
fResetFillColorButton = new Button(buttonClient, SWT.PUSH);
fResetFillColorButton.setText(Messages.ColoursFontsPreferencePage_14);
fResetFillColorButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fResetFillColorButton.setEnabled(false);
fResetFillColorButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
Object[] selected = ((IStructuredSelection) fTreeViewer.getSelection()).toArray();
if (isValidTreeSelection(selected)) {
for (Object object : selected) {
resetColorToInbuiltDefault(object);
}
}
}
});
// Import Scheme
Button importButton = new Button(buttonClient, SWT.PUSH);
importButton.setText(Messages.ColoursFontsPreferencePage_2);
importButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
importButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
try {
importUserColors();
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
// Export Scheme
Button exportButton = new Button(buttonClient, SWT.PUSH);
exportButton.setText(Messages.ColoursFontsPreferencePage_3);
exportButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
exportButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
try {
exportUserColors();
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
Group elementColorGroup = new Group(client, SWT.NULL);
elementColorGroup.setLayout(new GridLayout(2, false));
elementColorGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
elementColorGroup.setText(Messages.ColoursFontsPreferencePage_20);
// Derive element line colours
fDeriveElementLineColorsButton = new Button(elementColorGroup, SWT.CHECK);
fDeriveElementLineColorsButton.setText(Messages.ColoursFontsPreferencePage_19);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
fDeriveElementLineColorsButton.setLayoutData(gd);
fDeriveElementLineColorsButton.setSelection(getPreferenceStore().getBoolean(DERIVE_ELEMENT_LINE_COLOR));
fDeriveElementLineColorsButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
fElementLineColorContrastSpinner.setEnabled(fDeriveElementLineColorsButton.getSelection());
fContrastFactorLabel.setEnabled(fDeriveElementLineColorsButton.getSelection());
}
});
fContrastFactorLabel = new Label(elementColorGroup, SWT.NULL);
fContrastFactorLabel.setText(Messages.ColoursFontsPreferencePage_21);
fElementLineColorContrastSpinner = new Spinner(elementColorGroup, SWT.BORDER);
fElementLineColorContrastSpinner.setMinimum(1);
fElementLineColorContrastSpinner.setMaximum(10);
fElementLineColorContrastSpinner.setSelection(getPreferenceStore().getInt(DERIVE_ELEMENT_LINE_COLOR_FACTOR));
label = new Label(elementColorGroup, SWT.NULL);
label.setText(Messages.ColoursFontsPreferencePage_22);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
// Persist user default colours
fPersistUserDefaultColors = new Button(client, SWT.CHECK);
fPersistUserDefaultColors.setText(Messages.ColoursFontsPreferencePage_1);
fPersistUserDefaultColors.setLayoutData(gd);
fPersistUserDefaultColors.setSelection(getPreferenceStore().getBoolean(SAVE_USER_DEFAULT_COLOR));
// Use colours in application
fShowUserDefaultFillColorsInApplication = new Button(client, SWT.CHECK);
fShowUserDefaultFillColorsInApplication.setText(Messages.ColoursFontsPreferencePage_6);
fShowUserDefaultFillColorsInApplication.setLayoutData(gd);
fShowUserDefaultFillColorsInApplication.setSelection(getPreferenceStore().getBoolean(SHOW_FILL_COLORS_IN_GUI));
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project archi by archimatetool.
the class GeneralPreferencePage method createContents.
@Override
protected Control createContents(Composite parent) {
// Help
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
Composite client = new Composite(parent, SWT.NULL);
client.setLayout(new GridLayout());
GridData gd;
Group fileGroup = new Group(client, SWT.NULL);
fileGroup.setText(Messages.GeneralPreferencePage_0);
fileGroup.setLayout(new GridLayout(2, false));
fileGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// Automatically open views when opening a model file
fOpenDiagramsOnLoadButton = new Button(fileGroup, SWT.CHECK);
fOpenDiagramsOnLoadButton.setText(Messages.GeneralPreferencePage_1);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
fOpenDiagramsOnLoadButton.setLayoutData(gd);
// Backup file on save
fBackupOnSaveButton = new Button(fileGroup, SWT.CHECK);
fBackupOnSaveButton.setText(Messages.GeneralPreferencePage_5);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
fBackupOnSaveButton.setLayoutData(gd);
// Size of recently opened file list
Label label = new Label(fileGroup, SWT.NULL);
label.setText(Messages.GeneralPreferencePage_2);
fMRUSizeSpinner = new Spinner(fileGroup, SWT.BORDER);
fMRUSizeSpinner.setMinimum(3);
fMRUSizeSpinner.setMaximum(15);
// Appearance
Group appearanceGroup = new Group(client, SWT.NULL);
appearanceGroup.setText(Messages.GeneralPreferencePage_3);
appearanceGroup.setLayout(new GridLayout(2, false));
appearanceGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// Themes
label = new Label(appearanceGroup, SWT.NULL);
label.setText(Messages.GeneralPreferencePage_4);
fThemeComboViewer = new ComboViewer(appearanceGroup, SWT.READ_ONLY);
gd = new GridData(GridData.FILL_HORIZONTAL);
fThemeComboViewer.getCombo().setLayoutData(gd);
fThemeComboViewer.setContentProvider(new IStructuredContentProvider() {
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
public void dispose() {
}
public Object[] getElements(Object inputElement) {
return (Object[]) inputElement;
}
});
fThemeComboViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
return ((ITheme) element).getLabel();
}
});
fThemeComboViewer.setComparator(new ViewerComparator());
// Show Status Line
fShowStatusLineButton = new Button(appearanceGroup, SWT.CHECK);
fShowStatusLineButton.setText(Messages.GeneralPreferencePage_9);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
fShowStatusLineButton.setLayoutData(gd);
label = new Label(appearanceGroup, SWT.NULL);
label.setText(Messages.GeneralPreferencePage_8);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
label.setLayoutData(gd);
// Model Tree
Group modelTreeGroup = new Group(client, SWT.NULL);
modelTreeGroup.setText(Messages.GeneralPreferencePage_10);
modelTreeGroup.setLayout(new GridLayout(2, false));
modelTreeGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fShowUnusedElementsInModelTreeButton = new Button(modelTreeGroup, SWT.CHECK);
fShowUnusedElementsInModelTreeButton.setText(Messages.GeneralPreferencePage_11);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
fShowUnusedElementsInModelTreeButton.setLayoutData(gd);
// Visualiser
Group visualiserGroup = new Group(client, SWT.NULL);
visualiserGroup.setText(Messages.GeneralPreferencePage_6);
visualiserGroup.setLayout(new GridLayout(2, false));
visualiserGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fAnimateVisualiserNodesButton = new Button(visualiserGroup, SWT.CHECK);
fAnimateVisualiserNodesButton.setText(Messages.GeneralPreferencePage_7);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
fAnimateVisualiserNodesButton.setLayoutData(gd);
fAnimateVisualiserNodesButton.setEnabled(AnimationUtil.supportsAnimation());
setValues();
fThemeComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
ITheme theme = (ITheme) ((IStructuredSelection) fThemeComboViewer.getSelection()).getFirstElement();
if (theme != null && theme != fThemeEngine.getActiveTheme()) {
setTheme(theme, false);
}
}
});
return client;
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project archi by archimatetool.
the class ExportAsImagePage method createFormatComboViewer.
/**
* Create tghe Format Combo Viewer
*/
private ComboViewer createFormatComboViewer(Composite parent) {
ComboViewer viewer = new ComboViewer(new Combo(parent, SWT.READ_ONLY | SWT.BORDER));
viewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public void dispose() {
}
@Override
public Object[] getElements(Object inputElement) {
return fImageProviders.toArray();
}
});
viewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
return ((ImageExportProviderInfo) element).getLabel();
}
});
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ImageExportProviderInfo provider = (ImageExportProviderInfo) ((IStructuredSelection) event.getSelection()).getFirstElement();
providerChanged(provider);
}
});
// $NON-NLS-1$
viewer.setInput("");
return viewer;
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project xtext-eclipse by eclipse.
the class NewProjectWizardTemplateSelectionPage method createControl.
@Override
public void createControl(Composite parent) {
Composite main = new Composite(parent, SWT.NONE);
main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
main.setLayout(new GridLayout(1, false));
Label availableTemplatesLabel = new Label(main, SWT.NONE);
availableTemplatesLabel.setText(Messages.NewProjectWizardTemplateSelectionPage_available_templates);
availableTemplatesLabel.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, true, false));
SashForm sash = new SashForm(main, SWT.HORIZONTAL);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.widthHint = 400;
sash.setLayoutData(data);
TableViewer templateTable = new TableViewer(sash, SWT.BORDER);
templateTable.setContentProvider(new ArrayContentProvider());
templateTable.setLabelProvider(labelProvider);
templateTable.setInput(loadTemplatesFromExtensionPoint());
FormText text = new FormText(sash, SWT.BORDER);
// $NON-NLS-1$
text.setText("", false, false);
text.setBackground(templateTable.getTable().getBackground());
templateTable.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object element = structuredSelection.getFirstElement();
if (element instanceof AbstractProjectTemplate) {
selectedTemplate = (AbstractProjectTemplate) element;
setPageComplete(true);
// $NON-NLS-1$ //$NON-NLS-2$
String content = "<form>" + selectedTemplate.getDescription() + "</form>";
try {
text.setText(content, true, true);
} catch (Exception e) {
text.setText(e.getMessage(), false, false);
}
} else {
selectedTemplate = null;
// $NON-NLS-1$
text.setText("", false, false);
setPageComplete(false);
}
} else {
selectedTemplate = null;
// $NON-NLS-1$
text.setText("", false, false);
setPageComplete(false);
}
}
});
templateTable.setSelection(new StructuredSelection(templateTable.getElementAt(0)));
setControl(main);
}
Aggregations