use of org.eclipse.jface.viewers.ListViewer in project jbosstools-openshift by jbosstools.
the class CreateComponentWizardPage method doCreateControls.
@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
GridLayoutFactory.fillDefaults().numColumns(3).margins(10, 10).applyTo(parent);
Label componentNameLabel = new Label(parent, SWT.NONE);
componentNameLabel.setText("Name:");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(componentNameLabel);
Text componentNameText = new Text(parent, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(componentNameText);
ISWTObservableValue<String> componentNameObservable = WidgetProperties.text(SWT.Modify).observe(componentNameText);
Binding componentNameBinding = ValueBindingBuilder.bind(componentNameObservable).validatingAfterGet(new MandatoryStringValidator("Please specify a name")).to(BeanProperties.value(ComponentModel.PROPERTY_COMPONENT_NAME).observe(model)).in(dbc);
ControlDecorationSupport.create(componentNameBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
IObservableValue<Object> projectObservable = BeanProperties.value(CreateComponentModel.PROPERTY_ECLIPSE_PROJECT).observe(model);
SelectProjectComponentBuilder builder = new SelectProjectComponentBuilder();
builder.setTextLabel("Use existing workspace project:").setRequired(true).setEclipseProjectObservable(projectObservable).setSelectionListener(SelectionListener.widgetSelectedAdapter(this::onBrowseProjects)).setButtonIndent(0).build(parent, dbc, 1);
CLabel information = new CLabel(parent, SWT.NONE);
GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(information);
ValueBindingBuilder.bind(WidgetProperties.text().observe(information)).notUpdatingParticipant().to(BeanProperties.value(CreateComponentModel.PROPERTY_ECLIPSE_PROJECT_HAS_DEVFILE).observe(model)).converting(IConverter.create(flag -> (boolean) flag ? "Project has a devfile, component type selection is not required" : "")).in(dbc);
ValueBindingBuilder.bind(WidgetProperties.image().observe(information)).notUpdatingParticipant().to(BeanProperties.value(CreateComponentModel.PROPERTY_ECLIPSE_PROJECT_HAS_DEVFILE).observe(model)).converting(IConverter.create(flag -> (boolean) flag ? INFORMATION_IMAGE : null)).in(dbc);
Label componentTypesLabel = new Label(parent, SWT.NONE);
componentTypesLabel.setText("Component type:");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).applyTo(componentTypesLabel);
org.eclipse.swt.widgets.List componentTypesList = new org.eclipse.swt.widgets.List(parent, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL);
GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.CENTER).grab(true, false).hint(SWT.DEFAULT, 150).applyTo(componentTypesList);
ListViewer componentTypesListViewer = new ListViewer(componentTypesList);
componentTypesListViewer.setContentProvider(ArrayContentProvider.getInstance());
componentTypesListViewer.setLabelProvider(new ComponentTypeColumLabelProvider());
componentTypesListViewer.setInput(model.getComponentTypes());
Binding componentTypesBinding = ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(componentTypesListViewer)).validatingAfterGet(new ComponentTypeValidator(ValidationStatus.cancel("You have to select a component type."))).to(BeanProperties.value(CreateComponentModel.PROPERTY_SELECTED_COMPONENT_TYPE, ComponentType.class).observe(model)).in(dbc);
ControlDecorationSupport.create(componentTypesBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
ValueBindingBuilder.bind(WidgetProperties.enabled().observe(componentTypesList)).to(BeanProperties.value(CreateComponentModel.PROPERTY_ECLIPSE_PROJECT_HAS_DEVFILE).observe(model)).converting(new InvertingBooleanConverter()).in(dbc);
Label componentStartersLabel = new Label(parent, SWT.NONE);
componentStartersLabel.setText("Project starter:");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(componentStartersLabel);
Combo componentStartersVersionsCombo = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(componentStartersVersionsCombo);
ComboViewer componentStartersComboViewer = new ComboViewer(componentStartersVersionsCombo);
componentStartersComboViewer.setContentProvider(new ObservableListContentProvider<>());
componentStartersComboViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof Starter) {
return ((Starter) element).getName();
}
return "";
}
});
componentStartersComboViewer.setInput(BeanProperties.list(CreateComponentModel.PROPERTY_SELECTED_COMPONENT_STARTERS).observe(model));
Binding componentStartersBinding = ValueBindingBuilder.bind(ViewerProperties.singleSelection().observe(componentStartersComboViewer)).to(BeanProperties.value(CreateComponentModel.PROPERTY_SELECTED_COMPONENT_STARTER).observe(model)).in(dbc);
IObservableValue<List> selectedStartersObservable = BeanProperties.value(CreateComponentModel.PROPERTY_SELECTED_COMPONENT_STARTERS, List.class).observe(model);
IObservableValue<Boolean> emptyProjectObservable = BeanProperties.value(CreateComponentModel.PROPERTY_ECLIPSE_PROJECT_EMPTY, Boolean.class).observe(model);
IObservableValue<Boolean> computedObservable = ComputedValue.create(() -> {
return !selectedStartersObservable.getValue().isEmpty() && emptyProjectObservable.getValue();
});
ValueBindingBuilder.bind(WidgetProperties.enabled().observe(componentStartersVersionsCombo)).to(computedObservable).in(dbc);
ValueBindingBuilder.bind(WidgetProperties.text().observe(information)).notUpdatingParticipant().to(computedObservable).converting(IConverter.create(flag -> (boolean) flag ? "Your project is empty, you can initialize it from starters (templates)" : "")).in(dbc);
ValueBindingBuilder.bind(WidgetProperties.image().observe(information)).notUpdatingParticipant().to(computedObservable).converting(IConverter.create(flag -> (boolean) flag ? INFORMATION_IMAGE : null)).in(dbc);
Label applicationLabel = new Label(parent, SWT.NONE);
applicationLabel.setText("Application:");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(applicationLabel);
Text applicationNameText = new Text(parent, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(applicationNameText);
ISWTObservableValue<String> applicationNameObservable = WidgetProperties.text(SWT.Modify).observe(applicationNameText);
Binding applicationNameBinding = ValueBindingBuilder.bind(applicationNameObservable).validatingAfterGet(new MandatoryStringValidator("Please specify an application")).to(BeanProperties.value(CreateComponentModel.PROPERTY_APPLICATION_NAME).observe(model)).in(dbc);
ControlDecorationSupport.create(applicationNameBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
if (!model.isDefaultApplication()) {
applicationNameText.setEnabled(false);
}
Label pushAfterCreateLabel = new Label(parent, SWT.NONE);
pushAfterCreateLabel.setText("Push after create:");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(pushAfterCreateLabel);
Button pushAfterCreateButton = new Button(parent, SWT.CHECK);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(pushAfterCreateButton);
ISWTObservableValue<Boolean> pushAfterCreateObservable = WidgetProperties.buttonSelection().observe(pushAfterCreateButton);
Binding pushAfterCreateBinding = ValueBindingBuilder.bind(pushAfterCreateObservable).to(BeanProperties.value(CreateComponentModel.PROPERTY_PUSH_AFTER_CREATE).observe(model)).in(dbc);
ControlDecorationSupport.create(pushAfterCreateBinding, SWT.LEFT | SWT.TOP);
}
use of org.eclipse.jface.viewers.ListViewer in project translationstudio8 by heartsome.
the class ColumnCategoriesDialog method populateDialogArea.
@Override
public void populateDialogArea(Composite parent) {
GridDataFactory.fillDefaults().grab(true, true).applyTo(parent);
parent.setLayout(new GridLayout(4, false));
// Labels
createLabels(parent, "Available columns", "Selected columns");
GridData gridData = GridDataFactory.fillDefaults().grab(true, true).create();
// Left tree - column categories
treeViewer = new TreeViewer(parent);
populateAvailableTree();
treeViewer.getControl().setLayoutData(gridData);
// Add/remove buttons
Composite buttonComposite = new Composite(parent, SWT.NONE);
buttonComposite.setLayout(new GridLayout(1, true));
createAddButton(buttonComposite);
createRemoveButton(buttonComposite);
addListenersToTreeViewer();
// Right list - selected columns
listViewer = new ListViewer(parent, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
populateSelectedList();
addListenersToListViewer();
// Up/down buttons
Composite upDownbuttonComposite = new Composite(parent, SWT.NONE);
upDownbuttonComposite.setLayout(new GridLayout(1, true));
createUpButton(upDownbuttonComposite);
createDownButton(upDownbuttonComposite);
}
use of org.eclipse.jface.viewers.ListViewer in project translationstudio8 by heartsome.
the class ExportTmxDialog method createDialogArea.
/**
* Create contents of the dialog.
* @param parent
*/
@Override
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
container.setLayout(new GridLayout(1, false));
Group dbListGroup = new Group(container, SWT.NONE);
GridLayout glDbListGroup = new GridLayout(2, false);
glDbListGroup.horizontalSpacing = 0;
glDbListGroup.marginHeight = 0;
glDbListGroup.marginWidth = 0;
dbListGroup.setLayout(glDbListGroup);
dbListGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
dbListGroup.setText(Messages.getString("dialog.ExportTmxDialog.dbListGroup"));
Composite leftComposite = new Composite(dbListGroup, SWT.NONE);
GridLayout glLeftComposite = new GridLayout(1, false);
glLeftComposite.verticalSpacing = 0;
glLeftComposite.marginHeight = 0;
leftComposite.setLayout(glLeftComposite);
leftComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
// 列表和语言设置
Composite dbListComposite = new Composite(leftComposite, SWT.NONE);
GridLayout glTopLeftComposite = new GridLayout(1, false);
glTopLeftComposite.marginHeight = 0;
glTopLeftComposite.marginWidth = 0;
dbListComposite.setLayout(glTopLeftComposite);
dbListComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
dbListViewer = new TableViewer(dbListComposite, SWT.BORDER | SWT.FULL_SELECTION);
Table table = dbListViewer.getTable();
GridData gd_table = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gd_table.heightHint = 100;
table.setLayoutData(gd_table);
table.setHeaderVisible(true);
table.setLinesVisible(true);
dbListViewer.setContentProvider(new ArrayContentProvider());
dbListViewer.setInput(dbList);
createColumn(dbListViewer);
dbListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
currentDatabase = (ExportDatabaseBean) selection.getFirstElement();
loadData();
}
});
Composite langSetComposite = new Composite(leftComposite, SWT.NONE);
GridLayout gl_langSetComposite = new GridLayout(2, false);
gl_langSetComposite.marginWidth = 0;
langSetComposite.setLayout(gl_langSetComposite);
langSetComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
Label langSelLabel = new Label(langSetComposite, SWT.NONE);
langSelLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
langSelLabel.setText(Messages.getString("dialog.ExportTmxDialog.langSelLabel"));
hasSelLangListViewer = new ListViewer(langSetComposite, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
org.eclipse.swt.widgets.List list = hasSelLangListViewer.getList();
GridData glLangList = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
glLangList.heightHint = 76;
list.setLayoutData(glLangList);
hasSelLangListViewer.setContentProvider(new ArrayContentProvider());
hasSelLangListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@SuppressWarnings("unchecked")
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection sel = (IStructuredSelection) event.getSelection();
if (sel.isEmpty()) {
return;
}
if (currentDatabase != null) {
currentDatabase.getHasSelectedLangs().clear();
currentDatabase.getHasSelectedLangs().addAll(sel.toList());
List<String> canSelSrcLangs = new ArrayList<String>();
canSelSrcLangs.add("*all*");
canSelSrcLangs.addAll(sel.toList());
currentDatabase.setCanSelSrcLangs(canSelSrcLangs);
srcLangcomboViewer.setInput(canSelSrcLangs);
if (canSelSrcLangs.contains(currentDatabase.getSrcLang())) {
String srcLang = currentDatabase.getSrcLang();
if (srcLang != null && !srcLang.equals("")) {
for (int i = 0; i < canSelSrcLangs.size(); i++) {
if (canSelSrcLangs.get(i).equals(srcLang)) {
srcLangcomboViewer.getCombo().select(i);
break;
}
}
}
} else {
srcLangcomboViewer.getCombo().select(0);
}
}
}
});
Label srcLangSelLabel = new Label(langSetComposite, SWT.NONE);
srcLangSelLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
srcLangSelLabel.setBounds(0, 0, 79, 19);
srcLangSelLabel.setText(Messages.getString("dialog.ExportTmxDialog.srcLangSelLabel"));
srcLangcomboViewer = new ComboViewer(langSetComposite, SWT.NONE | SWT.READ_ONLY);
Combo combo = srcLangcomboViewer.getCombo();
GridData gd_combo = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
gd_combo.widthHint = 197;
combo.setLayoutData(gd_combo);
srcLangcomboViewer.setContentProvider(new ArrayContentProvider());
srcLangcomboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection sel = (IStructuredSelection) event.getSelection();
if (sel.isEmpty()) {
return;
}
if (currentDatabase != null) {
currentDatabase.setSrcLang((String) sel.getFirstElement());
}
}
});
// 操作库列的按钮区域
Composite rightComposite = new Composite(dbListGroup, SWT.NONE);
GridLayout gl_rightComposite = new GridLayout(1, false);
gl_rightComposite.marginRight = 5;
gl_rightComposite.marginHeight = 0;
gl_rightComposite.marginWidth = 0;
rightComposite.setLayout(gl_rightComposite);
rightComposite.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
HSDropDownButton addDbBtn = new HSDropDownButton(rightComposite, SWT.None);
addDbBtn.setBounds(0, 0, 104, 31);
addDbBtn.setText(Messages.getString("dialog.ExportTmxDialog.AddDbBtn"));
Menu menu = addDbBtn.getMenu();
MenuItem fileItem = new MenuItem(menu, SWT.PUSH);
fileItem.setText(Messages.getString("tm.dialog.addTm.DropDownButton.AddFileTm"));
fileItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
FileDialog fileDialg = new FileDialog(getShell());
fileDialg.setFilterExtensions(new String[] { "*.hstm", "*.*" });
String result = fileDialg.open();
if (result == null) {
return;
}
File f = new File(result);
if (!f.exists()) {
return;
}
Map<DatabaseModelBean, String> r = null;
try {
r = Utils.convertFile2TmModel(f, true);
} catch (Exception e1) {
MessageDialog.openError(getShell(), Messages.getString("tm.dialog.addFileTm.errorTitle"), e1.getMessage());
}
if (r == null) {
return;
}
Iterator<DatabaseModelBean> it = r.keySet().iterator();
if (it.hasNext()) {
DatabaseModelBean selectedVal = it.next();
ExportDatabaseBean bean = new ExportDatabaseBean(selectedVal.toDbMetaData(), r.get(selectedVal));
if (!dbList.contains(bean)) {
// 实现: 重写equals方法
dbList.add(bean);
bean.setIndex(dbList.size() + "");
}
dbListViewer.getTable().removeAll();
dbListViewer.setInput(dbList);
if (dbList.size() != 0) {
deleteDbBtn.setEnabled(true);
browserBtn.setEnabled(true);
selectCurrentDb(currentDatabase);
} else {
deleteDbBtn.setEnabled(false);
browserBtn.setEnabled(false);
}
}
}
});
MenuItem serverItem = new MenuItem(menu, SWT.PUSH);
serverItem.setText(Messages.getString("tm.dialog.addTm.DropDownButton.AddServerTm"));
serverItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
TmDbManagerDialog dialog = new TmDbManagerDialog(getShell());
dialog.setDialogUseFor(TmDbManagerDialog.TYPE_DBSELECTED);
if (dialog.open() == Window.OK) {
Map<DatabaseModelBean, String> selDb = dialog.getHasSelectedDatabase();
Iterator<Entry<DatabaseModelBean, String>> entryIt = selDb.entrySet().iterator();
while (entryIt.hasNext()) {
Entry<DatabaseModelBean, String> entry = entryIt.next();
ExportDatabaseBean bean = new ExportDatabaseBean(entry.getKey().toDbMetaData(), entry.getValue());
if (!dbList.contains(bean)) {
// 实现: 重写equals方法
dbList.add(bean);
bean.setIndex(dbList.size() + "");
}
}
dbListViewer.getTable().removeAll();
dbListViewer.setInput(dbList);
}
if (dbList.size() != 0) {
deleteDbBtn.setEnabled(true);
browserBtn.setEnabled(true);
selectCurrentDb(currentDatabase);
} else {
deleteDbBtn.setEnabled(false);
browserBtn.setEnabled(false);
}
}
});
deleteDbBtn = new Button(rightComposite, SWT.NONE);
deleteDbBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
deleteDbBtn.setBounds(0, 0, 104, 31);
deleteDbBtn.setText(Messages.getString("dialog.ExportTmxDialog.deleteDbBtn"));
deleteDbBtn.setEnabled(false);
deleteDbBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
IStructuredSelection sel = (IStructuredSelection) dbListViewer.getSelection();
if (sel.isEmpty()) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg1"));
return;
}
dbList.removeAll(sel.toList());
dbListViewer.remove(sel.toArray());
if (dbList.size() != 0) {
deleteDbBtn.setEnabled(true);
browserBtn.setEnabled(true);
selectCurrentDb(currentDatabase);
} else {
currentDatabase = null;
deleteDbBtn.setEnabled(false);
browserBtn.setEnabled(false);
}
}
});
// 过虑规则
Composite filterSetComposite = new Composite(container, SWT.NONE);
GridLayout glFilterSetComposite = new GridLayout(4, false);
glFilterSetComposite.marginWidth = 0;
glFilterSetComposite.marginHeight = 0;
filterSetComposite.setLayout(glFilterSetComposite);
filterSetComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
hasfilterCbtn = new Button(filterSetComposite, SWT.CHECK);
hasfilterCbtn.setText(Messages.getString("dialog.ExportTmxDialog.hasfilterCbtn"));
hasfilterCbtn.setSelection(false);
hasfilterCbtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
// TODO 实现选择改变
filterComboViewer.getCombo().setEnabled(hasfilterCbtn.getSelection());
filterSetBtn.setEnabled(hasfilterCbtn.getSelection());
deleteFilterBtn.setEnabled(hasfilterCbtn.getSelection());
}
});
filterComboViewer = new ComboViewer(filterSetComposite, SWT.NONE);
Combo filterCombo = filterComboViewer.getCombo();
filterCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
filterCombo.setEnabled(hasfilterCbtn.getSelection());
filterComboViewer.setContentProvider(new ArrayContentProvider());
filterComboViewer.setLabelProvider(new FilterLabelProvider());
filterComboViewer.setInput(filterList);
// 有一个空的过滤器
filterCombo.select(0);
filterSetBtn = new Button(filterSetComposite, SWT.NONE);
filterSetBtn.setText(Messages.getString("dialog.ExportTmxDialog.filterSetBtn"));
filterSetBtn.setEnabled(hasfilterCbtn.getSelection());
filterSetBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
IStructuredSelection sel = (IStructuredSelection) filterComboViewer.getSelection();
ExportFilterBean bean = (ExportFilterBean) sel.getFirstElement();
if (bean.equals(filterList.get(0))) {
// 0位置的始终存在 Empty
// 新建
filterSetting(null);
} else {
// 编辑
filterSetting(bean);
}
}
});
deleteFilterBtn = new Button(filterSetComposite, SWT.NONE);
deleteFilterBtn.setText(Messages.getString("dialog.ExportTmxDialog.deleteFilterBtn"));
deleteFilterBtn.setEnabled(hasfilterCbtn.getSelection());
deleteFilterBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
IStructuredSelection sel = (IStructuredSelection) filterComboViewer.getSelection();
ExportFilterBean bean = (ExportFilterBean) sel.getFirstElement();
if (bean.equals(filterList.get(0))) {
// 总是存在一个空的filter,显示为"无"
return;
}
if (MessageDialog.openConfirm(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg2"))) {
filterStore.deleteFilterRuleByName(bean.getFilterName(), "TMX");
int i = filterList.indexOf(bean);
filterList.remove(i);
filterComboViewer.setInput(filterList);
filterComboViewer.getCombo().select(0);
}
}
});
isTopLevelTmxCbtn = new Button(container, SWT.CHECK);
isTopLevelTmxCbtn.setText(Messages.getString("dialog.ExportTmxDialog.isTopLevelTmxCbtn"));
isTopLevelTmxCbtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
boolean temp = isTopLevelTmxCbtn.getSelection();
if (temp) {
isTagCbtn.setSelection(false);
isTagCbtn.setEnabled(false);
} else {
isTagCbtn.setEnabled(true);
}
}
});
isTagCbtn = new Button(container, SWT.CHECK);
isTagCbtn.setText(Messages.getString("dialog.ExportTmxDialog.isTagCbtn"));
isTagCbtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
boolean temp = isTagCbtn.getSelection();
if (temp) {
isTopLevelTmxCbtn.setSelection(false);
isTopLevelTmxCbtn.setEnabled(false);
} else {
isTopLevelTmxCbtn.setEnabled(true);
}
}
});
isTopLevelTmxCbtn.setSelection(true);
isTagCbtn.setEnabled(false);
Composite encodingComposite = new Composite(container, SWT.NONE);
GridLayout glEncodingComposite = new GridLayout(2, false);
glEncodingComposite.marginWidth = 0;
glEncodingComposite.marginHeight = 0;
encodingComposite.setLayout(glEncodingComposite);
encodingComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
hasChangedCodingCbtn = new Button(encodingComposite, SWT.CHECK);
hasChangedCodingCbtn.setText(Messages.getString("dialog.ExportTmxDialog.hasChangedCodingCbtn"));
hasChangedCodingCbtn.setSelection(false);
hasChangedCodingCbtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
encodingComboViewer.getCombo().setEnabled(hasChangedCodingCbtn.getSelection());
}
});
encodingComboViewer = new ComboViewer(encodingComposite, SWT.NONE | SWT.READ_ONLY);
Combo encodingCombo = encodingComboViewer.getCombo();
GridData gdEncodingCombo = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gdEncodingCombo.widthHint = 279;
encodingCombo.setLayoutData(gdEncodingCombo);
encodingCombo.setEnabled(hasChangedCodingCbtn.getSelection());
encodingComboViewer.setContentProvider(new ArrayContentProvider());
encodingComboViewer.setInput(pageCodes);
Composite tmxFileSetComposite = new Composite(container, SWT.NONE);
GridLayout glTmxFileSetComposite = new GridLayout(3, false);
glTmxFileSetComposite.marginWidth = 0;
glTmxFileSetComposite.marginHeight = 0;
tmxFileSetComposite.setLayout(glTmxFileSetComposite);
tmxFileSetComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label tmxFileLabel = new Label(tmxFileSetComposite, SWT.NONE);
tmxFileLabel.setText(Messages.getString("dialog.ExportTmxDialog.tmxFileLabel"));
tmxFileText = new Text(tmxFileSetComposite, SWT.BORDER);
tmxFileText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
tmxFileText.setEnabled(false);
browserBtn = new Button(tmxFileSetComposite, SWT.NONE);
browserBtn.setText(Messages.getString("dialog.ExportTmxDialog.browserBtn"));
browserBtn.setEnabled(false);
browserBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (dbList.size() > 1) {
DirectoryDialog dlg = new DirectoryDialog(getParentShell());
String filePath = dlg.open();
if (filePath != null) {
tmxFileText.setText(filePath);
}
} else {
FileDialog dlg = new FileDialog(getShell(), SWT.SAVE);
String[] filterExt = { "*.tmx" };
dlg.setFilterExtensions(filterExt);
String filePath = dlg.open();
if (filePath != null) {
tmxFileText.setText(filePath);
}
}
}
});
return container;
}
use of org.eclipse.jface.viewers.ListViewer in project translationstudio8 by heartsome.
the class ExportTbxDialog method createDialogArea.
/**
* Create contents of the dialog.
* @param parent
*/
@Override
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
container.setLayout(new GridLayout(1, false));
Group dbListGroup = new Group(container, SWT.NONE);
GridLayout glDbListGroup = new GridLayout(2, false);
glDbListGroup.horizontalSpacing = 0;
glDbListGroup.marginHeight = 0;
glDbListGroup.marginWidth = 0;
dbListGroup.setLayout(glDbListGroup);
dbListGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
dbListGroup.setText(Messages.getString("dialog.ExportTbxDialog.dbListGroup"));
Composite leftComposite = new Composite(dbListGroup, SWT.NONE);
GridLayout glLeftComposite = new GridLayout(1, false);
glLeftComposite.verticalSpacing = 0;
glLeftComposite.marginHeight = 0;
leftComposite.setLayout(glLeftComposite);
leftComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
// 列表和语言设置
Composite dbListComposite = new Composite(leftComposite, SWT.NONE);
GridLayout glTopLeftComposite = new GridLayout(1, false);
glTopLeftComposite.marginHeight = 0;
glTopLeftComposite.marginWidth = 0;
dbListComposite.setLayout(glTopLeftComposite);
dbListComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
dbListViewer = new TableViewer(dbListComposite, SWT.BORDER | SWT.FULL_SELECTION);
Table table = dbListViewer.getTable();
GridData gd_table = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gd_table.heightHint = 100;
table.setLayoutData(gd_table);
table.setHeaderVisible(true);
table.setLinesVisible(true);
dbListViewer.setContentProvider(new ArrayContentProvider());
dbListViewer.setInput(dbList);
createColumn(dbListViewer);
dbListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
currentDatabase = (ExportDatabaseBean) selection.getFirstElement();
loadData();
}
});
Composite langSetComposite = new Composite(leftComposite, SWT.NONE);
GridLayout gl_langSetComposite = new GridLayout(2, false);
gl_langSetComposite.marginWidth = 0;
langSetComposite.setLayout(gl_langSetComposite);
langSetComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
Label langSelLabel = new Label(langSetComposite, SWT.NONE);
langSelLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
langSelLabel.setText(Messages.getString("dialog.ExportTbxDialog.langSelLabel"));
hasSelLangListViewer = new ListViewer(langSetComposite, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
org.eclipse.swt.widgets.List list = hasSelLangListViewer.getList();
GridData glLangList = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
glLangList.heightHint = 76;
list.setLayoutData(glLangList);
hasSelLangListViewer.setContentProvider(new ArrayContentProvider());
hasSelLangListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@SuppressWarnings("unchecked")
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection sel = (IStructuredSelection) event.getSelection();
if (sel.isEmpty()) {
return;
}
if (currentDatabase != null) {
currentDatabase.getHasSelectedLangs().clear();
currentDatabase.getHasSelectedLangs().addAll(sel.toList());
List<String> canSelSrcLangs = new ArrayList<String>();
canSelSrcLangs.addAll(sel.toList());
currentDatabase.setCanSelSrcLangs(canSelSrcLangs);
srcLangcomboViewer.setInput(canSelSrcLangs);
if (canSelSrcLangs.contains(currentDatabase.getSrcLang())) {
String srcLang = currentDatabase.getSrcLang();
if (srcLang != null && !srcLang.equals("")) {
for (int i = 0; i < canSelSrcLangs.size(); i++) {
if (canSelSrcLangs.get(i).equals(srcLang)) {
srcLangcomboViewer.getCombo().select(i);
break;
}
}
}
} else {
srcLangcomboViewer.getCombo().select(0);
}
}
}
});
Label srcLangSelLabel = new Label(langSetComposite, SWT.NONE);
srcLangSelLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
srcLangSelLabel.setBounds(0, 0, 79, 19);
srcLangSelLabel.setText(Messages.getString("dialog.ExportTbxDialog.srcLangSelLabel"));
srcLangcomboViewer = new ComboViewer(langSetComposite, SWT.NONE | SWT.READ_ONLY);
Combo combo = srcLangcomboViewer.getCombo();
GridData gd_combo = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
gd_combo.widthHint = 197;
combo.setLayoutData(gd_combo);
srcLangcomboViewer.setContentProvider(new ArrayContentProvider());
srcLangcomboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection sel = (IStructuredSelection) event.getSelection();
if (sel.isEmpty()) {
return;
}
if (currentDatabase != null) {
currentDatabase.setSrcLang((String) sel.getFirstElement());
}
}
});
// 操作库列的按钮区域
Composite rightComposite = new Composite(dbListGroup, SWT.NONE);
GridLayout gl_rightComposite = new GridLayout(1, false);
gl_rightComposite.marginRight = 5;
gl_rightComposite.marginHeight = 0;
gl_rightComposite.marginWidth = 0;
rightComposite.setLayout(gl_rightComposite);
rightComposite.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
HSDropDownButton addBtn = new HSDropDownButton(rightComposite, SWT.NONE);
addBtn.setText(Messages.getString("dialog.ExportTbxDialog.AddDbBtn"));
Menu addMenu = addBtn.getMenu();
MenuItem item = new MenuItem(addMenu, SWT.PUSH);
item.setText(Messages.getString("tb.dialog.addTb.DropDownButton.AddFileTb"));
item.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
FileDialog fileDialg = new FileDialog(getShell());
fileDialg.setFilterExtensions(new String[] { "*.hstb", "*.*" });
String result = fileDialg.open();
if (result == null) {
return;
}
File f = new File(result);
if (!f.exists()) {
return;
}
Map<DatabaseModelBean, String> r = null;
try {
r = Utils.convertFile2TbModel(f, true);
} catch (Exception e1) {
MessageDialog.openError(getShell(), Messages.getString("tb.dialog.addFileTb.errorTitle"), e1.getMessage());
}
if (r == null) {
return;
}
Iterator<DatabaseModelBean> it = r.keySet().iterator();
if (it.hasNext()) {
DatabaseModelBean selectedVal = it.next();
ExportDatabaseBean bean = new ExportDatabaseBean(selectedVal.toDbMetaData(), r.get(selectedVal));
if (!dbList.contains(bean)) {
// 实现: 重写equals方法
dbList.add(bean);
bean.setIndex(dbList.size() + "");
}
dbListViewer.getTable().removeAll();
dbListViewer.setInput(dbList);
if (dbList.size() != 0) {
deleteDbBtn.setEnabled(true);
browserBtn.setEnabled(true);
selectCurrentDb(currentDatabase);
} else {
deleteDbBtn.setEnabled(false);
browserBtn.setEnabled(false);
}
}
}
});
MenuItem serverItem = new MenuItem(addMenu, SWT.PUSH);
serverItem.setText(Messages.getString("tb.dialog.addTb.DropDownButton.AddServerTb"));
serverItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
TermDbManagerDialog dialog = new TermDbManagerDialog(getShell());
dialog.setDialogUseFor(TermDbManagerDialog.TYPE_DBSELECTED);
if (dialog.open() == Window.OK) {
Map<DatabaseModelBean, String> selDb = dialog.getHasSelectedDatabase();
Iterator<Entry<DatabaseModelBean, String>> entryIt = selDb.entrySet().iterator();
while (entryIt.hasNext()) {
Entry<DatabaseModelBean, String> entry = entryIt.next();
ExportDatabaseBean bean = new ExportDatabaseBean(entry.getKey().toDbMetaData(), entry.getValue());
if (!dbList.contains(bean)) {
// 实现: 重写equals方法
dbList.add(bean);
bean.setIndex(dbList.size() + "");
}
}
dbListViewer.getTable().removeAll();
dbListViewer.setInput(dbList);
}
if (dbList.size() != 0) {
deleteDbBtn.setEnabled(true);
browserBtn.setEnabled(true);
selectCurrentDb(currentDatabase);
} else {
deleteDbBtn.setEnabled(false);
browserBtn.setEnabled(false);
}
}
});
deleteDbBtn = new Button(rightComposite, SWT.NONE);
deleteDbBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
deleteDbBtn.setBounds(0, 0, 104, 31);
deleteDbBtn.setText(Messages.getString("dialog.ExportTbxDialog.deleteDbBtn"));
deleteDbBtn.setEnabled(false);
deleteDbBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
IStructuredSelection sel = (IStructuredSelection) dbListViewer.getSelection();
if (sel.isEmpty()) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), Messages.getString("dialog.ExportTbxDialog.msg1"));
return;
}
dbList.removeAll(sel.toList());
dbListViewer.remove(sel.toArray());
if (dbList.size() != 0) {
deleteDbBtn.setEnabled(true);
browserBtn.setEnabled(true);
selectCurrentDb(currentDatabase);
} else {
currentDatabase = null;
deleteDbBtn.setEnabled(false);
browserBtn.setEnabled(false);
}
}
});
Composite tbxTemplateComp = new Composite(container, SWT.NONE);
GridLayout glTbxTemplateComp = new GridLayout(1, false);
glTbxTemplateComp.marginWidth = 0;
glTbxTemplateComp.marginHeight = 0;
tbxTemplateComp.setLayout(glTbxTemplateComp);
Composite encodingComposite = new Composite(container, SWT.NONE);
GridLayout glEncodingComposite = new GridLayout(2, false);
glEncodingComposite.marginWidth = 0;
glEncodingComposite.marginHeight = 0;
encodingComposite.setLayout(glEncodingComposite);
encodingComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
hasChangedCodingCbtn = new Button(encodingComposite, SWT.CHECK);
hasChangedCodingCbtn.setText(Messages.getString("dialog.ExportTbxDialog.hasChangedCodingCbtn"));
hasChangedCodingCbtn.setSelection(false);
hasChangedCodingCbtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
encodingComboViewer.getCombo().setEnabled(hasChangedCodingCbtn.getSelection());
}
});
encodingComboViewer = new ComboViewer(encodingComposite, SWT.NONE | SWT.READ_ONLY);
Combo encodingCombo = encodingComboViewer.getCombo();
GridData gdEncodingCombo = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gdEncodingCombo.widthHint = 279;
encodingCombo.setLayoutData(gdEncodingCombo);
encodingCombo.setEnabled(hasChangedCodingCbtn.getSelection());
encodingComboViewer.setContentProvider(new ArrayContentProvider());
encodingComboViewer.setInput(pageCodes);
Composite filterComposite = new Composite(container, SWT.NONE);
filterComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
GridLayout glFilterComposite = new GridLayout(4, false);
glFilterComposite.marginWidth = 0;
glFilterComposite.marginHeight = 0;
filterComposite.setLayout(glFilterComposite);
hasFilterChangedBtn = new Button(filterComposite, SWT.CHECK);
hasFilterChangedBtn.setText(Messages.getString("dialog.ExportTbxDialog.button"));
hasFilterChangedBtn.setSelection(false);
hasFilterChangedBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
filterComboViewer.getCombo().setEnabled(hasFilterChangedBtn.getSelection());
filterSettingBtn.setEnabled(hasFilterChangedBtn.getSelection());
filterDeleteBtn.setEnabled(hasFilterChangedBtn.getSelection());
}
});
filterComboViewer = new ComboViewer(filterComposite, SWT.NONE);
Combo filterCombo = filterComboViewer.getCombo();
filterCombo.setEnabled(false);
filterCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
filterComboViewer.setContentProvider(new ArrayContentProvider());
filterComboViewer.setLabelProvider(new FilterLabelProvider());
filterComboViewer.setInput(filterList);
// 有一个空的过滤器
filterCombo.select(0);
filterSettingBtn = new Button(filterComposite, SWT.NONE);
filterSettingBtn.setText(Messages.getString("dialog.ExportTbxDialog.filterSettingBtn"));
filterSettingBtn.setEnabled(false);
filterSettingBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
IStructuredSelection sel = (IStructuredSelection) filterComboViewer.getSelection();
ExportFilterBean bean = (ExportFilterBean) sel.getFirstElement();
if (bean.equals(filterList.get(0))) {
// 0位置的始终存在 Empty
// 新建
filterSetting(null);
} else {
// 编辑
filterSetting(bean);
}
}
});
filterDeleteBtn = new Button(filterComposite, SWT.NONE);
filterDeleteBtn.setText(Messages.getString("dialog.ExportTbxDialog.filterDeleteBtn"));
filterDeleteBtn.setEnabled(false);
filterDeleteBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
IStructuredSelection sel = (IStructuredSelection) filterComboViewer.getSelection();
ExportFilterBean bean = (ExportFilterBean) sel.getFirstElement();
if (bean.equals(filterList.get(0))) {
// 总是存在一个空的filter,显示为"无"
return;
}
if (MessageDialog.openConfirm(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), Messages.getString("dialog.ExportTbxDialog.msg2"))) {
filterStore.deleteFilterRuleByName(bean.getFilterName(), "TBX");
int i = filterList.indexOf(bean);
filterList.remove(i);
filterComboViewer.setInput(filterList);
filterComboViewer.getCombo().select(0);
}
}
});
Composite tbxFileSetComposite = new Composite(container, SWT.NONE);
GridLayout glTbxFileSetComposite = new GridLayout(3, false);
glTbxFileSetComposite.marginWidth = 0;
glTbxFileSetComposite.marginHeight = 0;
tbxFileSetComposite.setLayout(glTbxFileSetComposite);
tbxFileSetComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label tbxFileLabel = new Label(tbxFileSetComposite, SWT.NONE);
tbxFileLabel.setText(Messages.getString("dialog.ExportTbxDialog.tbxFileLabel"));
tbxFileText = new Text(tbxFileSetComposite, SWT.BORDER);
tbxFileText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
tbxFileText.setEnabled(false);
browserBtn = new Button(tbxFileSetComposite, SWT.NONE);
browserBtn.setText(Messages.getString("dialog.ExportTbxDialog.browserBtn"));
browserBtn.setEnabled(false);
browserBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (dbList.size() > 1) {
DirectoryDialog dlg = new DirectoryDialog(getParentShell());
String filePath = dlg.open();
if (filePath != null) {
tbxFileText.setText(filePath);
}
} else {
FileDialog dlg = new FileDialog(getShell(), SWT.SAVE);
String[] filterExt = { "*.tbx" };
dlg.setFilterExtensions(filterExt);
String filePath = dlg.open();
if (filePath != null) {
tbxFileText.setText(filePath);
}
}
}
});
return container;
}
use of org.eclipse.jface.viewers.ListViewer in project ACS by ACS-Community.
the class LostSourcesPart method createPartControl.
public void createPartControl(Composite parent) {
listViewer = new ListViewer(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
listViewer.setContentProvider(LostSourcesContainer.getInstance());
listViewer.setSorter(new ViewerSorter());
listViewer.setInput(null);
}
Aggregations