use of org.eclipse.jface.viewers.SelectionChangedEvent in project eclipse.platform.text by eclipse.
the class TemplatePreferencePage method createContents.
@Override
protected Control createContents(Composite ancestor) {
Composite parent = new Composite(ancestor, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginHeight = 0;
layout.marginWidth = 0;
parent.setLayout(layout);
Composite innerParent = new Composite(parent, SWT.NONE);
GridLayout innerLayout = new GridLayout();
innerLayout.numColumns = 2;
innerLayout.marginHeight = 0;
innerLayout.marginWidth = 0;
innerParent.setLayout(innerLayout);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 2;
innerParent.setLayoutData(gd);
Composite tableComposite = new Composite(innerParent, SWT.NONE);
GridData data = new GridData(GridData.FILL_BOTH);
data.widthHint = 360;
data.heightHint = convertHeightInCharsToPixels(10);
tableComposite.setLayoutData(data);
ColumnLayout columnLayout = new ColumnLayout();
tableComposite.setLayout(columnLayout);
Table table = new Table(tableComposite, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
table.setHeaderVisible(true);
table.setLinesVisible(true);
GC gc = new GC(getShell());
gc.setFont(JFaceResources.getDialogFont());
TemplateViewerComparator viewerComparator = new TemplateViewerComparator();
TableColumn column1 = new TableColumn(table, SWT.NONE);
column1.setText(TemplatesMessages.TemplatePreferencePage_column_name);
int minWidth = computeMinimumColumnWidth(gc, TemplatesMessages.TemplatePreferencePage_column_name);
columnLayout.addColumnData(new ColumnWeightData(2, minWidth, true));
column1.addSelectionListener(new TemplateColumnSelectionAdapter(column1, 0, viewerComparator));
TableColumn column2 = new TableColumn(table, SWT.NONE);
column2.setText(TemplatesMessages.TemplatePreferencePage_column_context);
minWidth = computeMinimumContextColumnWidth(gc);
columnLayout.addColumnData(new ColumnWeightData(1, minWidth, true));
column2.addSelectionListener(new TemplateColumnSelectionAdapter(column2, 1, viewerComparator));
TableColumn column3 = new TableColumn(table, SWT.NONE);
column3.setText(TemplatesMessages.TemplatePreferencePage_column_description);
minWidth = computeMinimumColumnWidth(gc, TemplatesMessages.TemplatePreferencePage_column_description);
columnLayout.addColumnData(new ColumnWeightData(3, minWidth, true));
column3.addSelectionListener(new TemplateColumnSelectionAdapter(column3, 2, viewerComparator));
TableColumn column4 = new TableColumn(table, SWT.NONE);
column4.setAlignment(SWT.CENTER);
column4.setText(TemplatesMessages.TemplatePreferencePage_column_autoinsert);
minWidth = computeMinimumColumnWidth(gc, TemplatesMessages.TemplatePreferencePage_column_autoinsert);
minWidth = Math.max(minWidth, computeMinimumColumnWidth(gc, TemplatesMessages.TemplatePreferencePage_on));
columnLayout.addColumnData(new ColumnPixelData(minWidth, false, false));
column4.addSelectionListener(new TemplateColumnSelectionAdapter(column4, 3, viewerComparator));
gc.dispose();
fTableViewer = new CheckboxTableViewer(table);
fTableViewer.setLabelProvider(new TemplateLabelProvider());
fTableViewer.setContentProvider(new TemplateContentProvider());
fTableViewer.setComparator(viewerComparator);
// Specify default sorting
table.setSortColumn(column1);
table.setSortDirection(viewerComparator.getDirection());
fTableViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent e) {
edit();
}
});
fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent e) {
selectionChanged1();
}
});
fTableViewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
TemplatePersistenceData d = (TemplatePersistenceData) event.getElement();
d.setEnabled(event.getChecked());
}
});
BidiUtils.applyTextDirection(fTableViewer.getControl(), BidiUtils.BTD_DEFAULT);
Composite buttons = new Composite(innerParent, SWT.NONE);
buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
buttons.setLayout(layout);
fAddButton = new Button(buttons, SWT.PUSH);
fAddButton.setText(TemplatesMessages.TemplatePreferencePage_new);
fAddButton.setLayoutData(getButtonGridData(fAddButton));
fAddButton.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
add();
}
});
fEditButton = new Button(buttons, SWT.PUSH);
fEditButton.setText(TemplatesMessages.TemplatePreferencePage_edit);
fEditButton.setLayoutData(getButtonGridData(fEditButton));
fEditButton.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
edit();
}
});
fRemoveButton = new Button(buttons, SWT.PUSH);
fRemoveButton.setText(TemplatesMessages.TemplatePreferencePage_remove);
fRemoveButton.setLayoutData(getButtonGridData(fRemoveButton));
fRemoveButton.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
remove();
}
});
createSeparator(buttons);
fRestoreButton = new Button(buttons, SWT.PUSH);
fRestoreButton.setText(TemplatesMessages.TemplatePreferencePage_restore);
fRestoreButton.setLayoutData(getButtonGridData(fRestoreButton));
fRestoreButton.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
restoreDeleted();
}
});
fRevertButton = new Button(buttons, SWT.PUSH);
fRevertButton.setText(TemplatesMessages.TemplatePreferencePage_revert);
fRevertButton.setLayoutData(getButtonGridData(fRevertButton));
fRevertButton.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
revert();
}
});
createSeparator(buttons);
fImportButton = new Button(buttons, SWT.PUSH);
fImportButton.setText(TemplatesMessages.TemplatePreferencePage_import);
fImportButton.setLayoutData(getButtonGridData(fImportButton));
fImportButton.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
import_();
}
});
fExportButton = new Button(buttons, SWT.PUSH);
fExportButton.setText(TemplatesMessages.TemplatePreferencePage_export);
fExportButton.setLayoutData(getButtonGridData(fExportButton));
fExportButton.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
export();
}
});
fPatternViewer = doCreateViewer(parent);
if (isShowFormatterSetting()) {
fFormatButton = new Button(parent, SWT.CHECK);
fFormatButton.setText(TemplatesMessages.TemplatePreferencePage_use_code_formatter);
GridData gd1 = new GridData();
gd1.horizontalSpan = 2;
fFormatButton.setLayoutData(gd1);
fFormatButton.setSelection(getPreferenceStore().getBoolean(getFormatterPreferenceKey()));
}
fTableViewer.setInput(fTemplateStore);
fTableViewer.setAllChecked(false);
fTableViewer.setCheckedElements(getEnabledTemplates());
updateButtons();
Dialog.applyDialogFont(parent);
innerParent.layout();
return parent;
}
use of org.eclipse.jface.viewers.SelectionChangedEvent in project eclipse.platform.text by eclipse.
the class SpellingConfigurationBlock method createProviderViewer.
private ComboViewer createProviderViewer() {
/* list viewer */
final ComboViewer viewer = new ComboViewer(fProviderCombo);
viewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void dispose() {
}
@Override
public void inputChanged(Viewer v, Object oldInput, Object newInput) {
}
@Override
public Object[] getElements(Object inputElement) {
return fProviderDescriptors.values().toArray();
}
});
viewer.setLabelProvider(new LabelProvider() {
@Override
public Image getImage(Object element) {
return null;
}
@Override
public String getText(Object element) {
return ((SpellingEngineDescriptor) element).getLabel();
}
});
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection sel = (IStructuredSelection) event.getSelection();
if (sel.isEmpty())
return;
if (fCurrentBlock != null && fStatusMonitor.getStatus() != null && fStatusMonitor.getStatus().matches(IStatus.ERROR))
if (isPerformRevert()) {
ISafeRunnable runnable = new ISafeRunnable() {
@Override
public void run() throws Exception {
fCurrentBlock.performRevert();
}
@Override
public void handleException(Throwable x) {
}
};
SafeRunner.run(runnable);
} else {
revertSelection();
return;
}
fStore.setValue(SpellingService.PREFERENCE_SPELLING_ENGINE, ((SpellingEngineDescriptor) sel.getFirstElement()).getId());
updateListDependencies();
}
private boolean isPerformRevert() {
Shell shell = viewer.getControl().getShell();
MessageDialog dialog = new MessageDialog(shell, TextEditorMessages.SpellingConfigurationBlock_error_title, null, TextEditorMessages.SpellingConfigurationBlock_error_message, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1);
return dialog.open() == 0;
}
private void revertSelection() {
try {
viewer.removeSelectionChangedListener(this);
SpellingEngineDescriptor desc = EditorsUI.getSpellingService().getActiveSpellingEngineDescriptor(fStore);
if (desc != null)
viewer.setSelection(new StructuredSelection(desc), true);
} finally {
viewer.addSelectionChangedListener(this);
}
}
});
viewer.setInput(fProviderDescriptors);
viewer.refresh();
return viewer;
}
use of org.eclipse.jface.viewers.SelectionChangedEvent in project eclipse.platform.text by eclipse.
the class RevisionSelectionProvider method fireSelectionEvent.
private void fireSelectionEvent() {
fIgnoreEvents = true;
try {
ISelection selection = getSelection();
SelectionChangedEvent event = new SelectionChangedEvent(this, selection);
for (ISelectionChangedListener listener : fListeners) {
listener.selectionChanged(event);
}
} finally {
fIgnoreEvents = false;
}
}
use of org.eclipse.jface.viewers.SelectionChangedEvent in project eclipse.platform.text by eclipse.
the class TextViewer method fireSelectionChanged.
/**
* Sends out a text selection changed event to all registered listeners.
*
* @param offset the offset of the newly selected range in the visible document
* @param length the length of the newly selected range in the visible document
* @since 3.0
*/
protected void fireSelectionChanged(int offset, int length) {
if (redraws()) {
if (length < 0) {
length = -length;
offset = offset + length;
}
IRegion r = widgetRange2ModelRange(new Region(offset, length));
if ((r != null && !r.equals(fLastSentSelectionChange)) || r == null) {
fLastSentSelectionChange = r;
ISelection selection = r != null ? new TextSelection(getDocument(), r.getOffset(), r.getLength()) : TextSelection.emptySelection();
SelectionChangedEvent event = new SelectionChangedEvent(this, selection);
fireSelectionChanged(event);
}
}
}
use of org.eclipse.jface.viewers.SelectionChangedEvent in project eclipse.platform.text by eclipse.
the class TextViewer method firePostSelectionChanged.
/**
* Sends out a text selection changed event to all registered post selection changed listeners.
*
* @param offset the offset of the newly selected range in the visible document
* @param length the length of the newly selected range in the visible document
* @since 3.0
*/
protected void firePostSelectionChanged(int offset, int length) {
if (redraws()) {
IRegion r = widgetRange2ModelRange(new Region(offset, length));
ISelection selection = r != null ? new TextSelection(getDocument(), r.getOffset(), r.getLength()) : TextSelection.emptySelection();
SelectionChangedEvent event = new SelectionChangedEvent(this, selection);
firePostSelectionChanged(event);
}
}
Aggregations