use of org.eclipse.jface.viewers.IStructuredSelection in project translationstudio8 by heartsome.
the class NewProjectWizardLanguagePage method createControl.
/**
* Create contents of the wizard.
* @param parent
*/
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
container.setLayout(new GridLayout(1, false));
// source language control
Group sourceLanguageGrp = new Group(container, SWT.NONE);
sourceLanguageGrp.setLayout(new GridLayout(1, false));
sourceLanguageGrp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
sourceLanguageGrp.setText(Messages.getString("wizard.NewProjectWizardLanguagePage.sourceLanguageGrp"));
srcLangComboViewer = new TableComboViewer(sourceLanguageGrp, SWT.READ_ONLY | SWT.BORDER);
TableCombo tableCombo = srcLangComboViewer.getTableCombo();
// set options.
tableCombo.setShowTableLines(false);
tableCombo.setShowTableHeader(false);
tableCombo.setDisplayColumnIndex(-1);
tableCombo.setShowImageWithinSelection(true);
tableCombo.setShowColorWithinSelection(false);
tableCombo.setShowFontWithinSelection(false);
tableCombo.setVisibleItemCount(20);
srcLangComboViewer.getTableCombo().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
srcLangComboViewer.setLabelProvider(new LanguageLabelProvider());
srcLangComboViewer.setContentProvider(new ArrayContentProvider());
srcLangComboViewer.setInput(languages);
srcLangComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
srcLanguage = (Language) selection.getFirstElement();
validator.update();
}
});
// initialization remember value
String rmSrcLangCode = ps.getString(IPreferenceConstants.NEW_PROJECT_SRC_LANG);
if (rmSrcLangCode != null && !rmSrcLangCode.equals("")) {
for (Language srcLang : languages) {
if (srcLang.getCode().equals(rmSrcLangCode)) {
srcLangComboViewer.setSelection(new StructuredSelection(srcLang));
break;
}
}
}
// end source language
// target language control
Group targetLanguageGrp = new Group(container, SWT.NONE);
targetLanguageGrp.setLayout(new GridLayout(3, false));
targetLanguageGrp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
targetLanguageGrp.setText(Messages.getString("wizard.NewProjectWizardLanguagePage.targetLanguageGrp"));
targetLangControl.createControl(targetLanguageGrp);
// end Target language
setControl(container);
validator.update();
}
use of org.eclipse.jface.viewers.IStructuredSelection in project translationstudio8 by heartsome.
the class NewProjectWizardSourceFilePage method createControl.
/**
* Create contents of the wizard.
* @param parent
*/
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
container.setLayout(new GridLayout(1, false));
setControl(container);
fileListViewer = new ListViewer(container, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
fileListViewer.getList().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
fileListViewer.setContentProvider(new ArrayContentProvider());
fileListViewer.setInput(srcFileList);
if (this.converterCaller != null) {
final Button btnConvert = new Button(container, SWT.CHECK);
btnConvert.setText(Messages.getString("wizard.NewProjectWizardSourceFilePage.btnConvert"));
btnConvert.setSelection(true);
isOpenConverter = true;
btnConvert.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
isOpenConverter = btnConvert.getSelection();
}
});
}
Composite composite = new Composite(container, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
composite.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false, 1, 1));
Button addBtn = new Button(composite, SWT.NONE);
addBtn.setText(Messages.getString("wizard.NewProjectWizardSourceFilePage.addBtn"));
addBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
FileDialog dlg = new FileDialog(getShell(), SWT.MULTI);
// CONVERTEREXTENTION
String[] supExtentions = new String[] { "*.mif;*.idml;*.inx;*.xlf;*.rtf;*.po;*.properties;*.js;*.mqxlz;*.doc;*.xls;*.ppt;" + "*.docx;*.xlsx;*.pptx;*.odt;*.ods;*.odp;*.odg;*.rtf;*.sdlxliff;*.ttx;*.htm;*.html;*.txt;*.resx;*.rc;*.xml;*.txml", "*.*" };
dlg.setFilterExtensions(supExtentions);
if (dlg.open() != null) {
String[] files = dlg.getFileNames();
for (int i = 0; i < files.length; i++) {
StringBuffer buf = new StringBuffer(dlg.getFilterPath());
buf.append(File.separator);
buf.append(files[i]);
String file = buf.toString();
if (!srcFileList.contains(file)) {
srcFileList.add(file);
}
}
fileListViewer.refresh();
}
}
});
Button deleteBtn = new Button(composite, SWT.NONE);
deleteBtn.setText(Messages.getString("wizard.NewProjectWizardSourceFilePage.deleteBtn"));
deleteBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
IStructuredSelection selections = (IStructuredSelection) fileListViewer.getSelection();
Iterator<?> it = selections.iterator();
while (it.hasNext()) {
String file = (String) it.next();
srcFileList.remove(file);
}
fileListViewer.refresh();
}
});
}
use of org.eclipse.jface.viewers.IStructuredSelection in project translationstudio8 by heartsome.
the class MultiSelectionPropertyTester method test.
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
IProject curProject = null;
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
if (page.getActivePartReference() == null) {
return false;
}
String partId = page.getActivePartReference().getId();
if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {
// 导航视图处于激活状态
IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
ArrayList<IFile> selectedIFileList = new ArrayList<IFile>();
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
List<?> lstObj = ((IStructuredSelection) selection).toList();
for (Object obj : lstObj) {
if (obj instanceof IFile) {
IFile file = (IFile) obj;
// Linux 下的文本文件无扩展名,因此要先判断扩展名是否为空
if (file.getFileExtension() == null || !CommonFunction.validXlfExtension(file.getFileExtension())) {
return false;
} else {
String xlfFolderPath = file.getProject().getFullPath().append(Constant.FOLDER_XLIFF).toOSString();
if (!file.getFullPath().toOSString().startsWith(xlfFolderPath)) {
return false;
}
if (curProject == null) {
curProject = file.getProject();
} else {
if (curProject != file.getProject()) {
return false;
}
}
selectedIFileList.add(file);
}
} else if (obj instanceof IFolder) {
IFolder folder = (IFolder) obj;
String xlfFolderPath = folder.getProject().getFullPath().append(Constant.FOLDER_XLIFF).toOSString();
if (!folder.getFullPath().toOSString().startsWith(xlfFolderPath)) {
return false;
}
try {
ResourceUtils.getXliffs(folder, selectedIFileList);
} catch (CoreException e) {
logger.error(Messages.getString("propertyTester.MultiSelectionPropertyTester.logger1"), folder.getFullPath().toOSString(), e);
}
if (curProject == null) {
curProject = folder.getProject();
} else {
if (curProject != folder.getProject()) {
return false;
}
}
}
}
CommonFunction.removeRepeateSelect(selectedIFileList);
if (selectedIFileList.size() < 2) {
return false;
}
} else {
return false;
}
}
} else {
return false;
}
} else {
return false;
}
return true;
}
use of org.eclipse.jface.viewers.IStructuredSelection in project translationstudio8 by heartsome.
the class XmlConvertManagerDialog method initListener.
/**
* 给增删改三个按钮添加点击事件 ;
*/
protected void initListener() {
addBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
AddOrEditElementOfXmlConvertDialog dialog = new AddOrEditElementOfXmlConvertDialog(getShell(), true, elementsList);
int result = dialog.open();
if (result == IDialogConstants.OK_ID) {
refreshTable(dialog.getCurrentElement());
}
}
});
editBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
editElement();
}
});
deleteBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ISelection selection = tableViewer.getSelection();
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
if (MessageDialog.openConfirm(getShell(), Messages.getString("dialogs.XmlConvertManagerDialog.msgTitle1"), Messages.getString("dialogs.XmlConvertManagerDialog.msg1"))) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
@SuppressWarnings("unchecked") Iterator<ElementBean> iter = structuredSelection.iterator();
ElementBean bean = new ElementBean();
while (iter.hasNext()) {
bean = iter.next();
elementsList.remove(bean);
}
refreshTable(null);
}
} else {
MessageDialog.openInformation(getShell(), Messages.getString("dialogs.XmlConvertManagerDialog.msgTitle2"), Messages.getString("dialogs.XmlConvertManagerDialog.msg2"));
}
}
});
}
use of org.eclipse.jface.viewers.IStructuredSelection in project translationstudio8 by heartsome.
the class XmlConverterConfigurationDialog method initListener.
public void initListener() {
addBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
AddOrEditXmlConvertConfigDialog dialog = new AddOrEditXmlConvertConfigDialog(getShell(), true);
int result = dialog.open();
if (result == IDialogConstants.OK_ID) {
String curentConvertXMl = dialog.getCurentConverXML();
refreshTable();
setTableSelection(curentConvertXMl);
}
}
});
editBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
editConfigXml();
}
});
deleteBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ISelection selection = tableViewer.getSelection();
if (!selection.isEmpty() && selection != null && selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
@SuppressWarnings("unchecked") Iterator<String[]> iter = structuredSelection.iterator();
while (iter.hasNext()) {
String convertXmlName = iter.next()[1];
String convertXmlLoaction = root.getLocation().append(ADConstants.AD_xmlConverterConfigFolder).append(convertXmlName).toOSString();
File convertXml = new File(convertXmlLoaction);
convertXml.delete();
}
refreshTable();
} else {
MessageDialog.openInformation(getShell(), Messages.getString("dialogs.XmlConverterConfigurationDialog.msgTitle"), Messages.getString("dialogs.XmlConverterConfigurationDialog.msg1"));
}
}
});
analysisBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
AnalysisXmlConvertConfigDialg dialog = new AnalysisXmlConvertConfigDialg(getShell());
int result = dialog.open();
if (result == IDialogConstants.OK_ID) {
String curentConvertXMl = dialog.getCurentConverXML();
refreshTable();
setTableSelection(curentConvertXMl);
}
}
});
}
Aggregations