use of org.eclipse.jface.viewers.ArrayContentProvider in project tdi-studio-se by Talend.
the class HL7MultiSchemaUI method createCombo.
@Override
protected void createCombo(Composite parent) {
createLabel(parent);
metaTableViewer = new ComboViewer(parent, SWT.NONE);
metaTableViewer.setContentProvider(new ArrayContentProvider());
metaTableViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof SegmentModel) {
return ((SegmentModel) element).getSeg().getName();
}
return super.getText(element);
}
});
final Combo combo = metaTableViewer.getCombo();
GridData data = new GridData();
data.widthHint = 60;
combo.setLayoutData(data);
combo.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
updateCurrentMetadataTable();
linker.removeAllLinks();
linker.getMainui().redrawLinkers();
linker.getBackgroundRefresher().refreshBackground();
}
});
}
use of org.eclipse.jface.viewers.ArrayContentProvider in project tdi-studio-se by Talend.
the class LoadChartSetDialog method createChartSetViewer.
/**
* Creates the chart set viewer.
*
* @param parent The parent composite
* @return The chart set viewer
*/
private TableViewer createChartSetViewer(Composite parent) {
final TableViewer viewer = new TableViewer(parent, SWT.BORDER | SWT.FULL_SELECTION);
GridData gridData = new GridData(GridData.FILL_BOTH);
gridData.heightHint = 300;
viewer.getTable().setLayoutData(gridData);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element.equals(defaultChartSet)) {
return NLS.bind(Messages.defaultChartSet, defaultChartSet);
}
return super.getText(element);
}
});
viewer.setInput(chartSets.toArray(new String[chartSets.size()]));
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
Object element = ((StructuredSelection) selection).getFirstElement();
if (deleteButton != null) {
deleteButton.setEnabled(!selection.isEmpty() && !predefinedChartSets.contains(element));
}
if (element != null) {
chartSet = element.toString();
} else {
viewer.setSelection(new StructuredSelection(chartSet));
}
}
});
viewer.setSelection(new StructuredSelection(defaultChartSet));
return viewer;
}
use of org.eclipse.jface.viewers.ArrayContentProvider in project translationstudio8 by heartsome.
the class ConversionWizardPage method createConversionOptionsGroup.
/**
* 转换选项组
* @param contents
* ;
*/
private void createConversionOptionsGroup(Composite contents) {
Group options = new Group(contents, SWT.NONE);
//$NON-NLS-1$
options.setText(Messages.getString("wizard.ConversionWizardPage.options"));
options.setLayout(new GridLayout(1, false));
options.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
/* 如果已经存在,是否要替换 */
final Button btnReplaceTarget = new Button(options, SWT.CHECK);
//$NON-NLS-1$
btnReplaceTarget.setText(Messages.getString("wizard.ConversionWizardPage.btnReplaceTarget"));
btnReplaceTarget.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
btnReplaceTarget.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
isReplaceTarget = btnReplaceTarget.getSelection();
for (ConversionConfigBean conversionConfigBean : conversionConfigBeans) {
conversionConfigBean.setReplaceTarget(btnReplaceTarget.getSelection());
}
validate();
}
});
final Button btnOpenPreTrans = new Button(options, SWT.CHECK);
btnOpenPreTrans.setText(Messages.getString("wizard.ConversionWizardPage.btnOpenPreTrans"));
btnOpenPreTrans.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
btnOpenPreTrans.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
isOpenPreTrans = btnOpenPreTrans.getSelection();
}
});
Composite composite = new Composite(options, SWT.NONE);
GridLayout gd = new GridLayout(1, false);
gd.marginWidth = 0;
gd.marginHeight = 0;
composite.setLayout(gd);
composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
Label tgtLangLbl = new Label(composite, SWT.NONE);
tgtLangLbl.setText(Messages.getString("wizard.ConversionWizardPage.tgtLangLbl"));
tgtLangViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
Table tgtLangTable = tgtLangViewer.getTable();
GridData gdTgtLangTable = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gdTgtLangTable.heightHint = 80;
tgtLangTable.setLayoutData(gdTgtLangTable);
tgtLangViewer.setLabelProvider(new LanguageLabelProvider());
tgtLangViewer.setContentProvider(new ArrayContentProvider());
tgtLangViewer.setInput(conversionConfigBeans.get(0).getTgtLangList());
tgtLangViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection sel = (IStructuredSelection) event.getSelection();
@SuppressWarnings("unchecked") List<Language> selectedList = sel.toList();
for (ConversionConfigBean conversionConfigBean : conversionConfigBeans) {
conversionConfigBean.setHasSelTgtLangList(selectedList);
}
validate();
}
});
tgtLangViewer.getTable().select(0);
IDialogSettings dialogSettings = Activator.getDefault().getDialogSettings();
btnReplaceTarget.setSelection(dialogSettings.getBoolean(REPLACE_TARGET));
btnOpenPreTrans.setSelection(dialogSettings.getBoolean(OPEN_PRE_TRANS));
this.isOpenPreTrans = btnOpenPreTrans.getSelection();
isReplaceTarget = btnReplaceTarget.getSelection();
for (ConversionConfigBean conversionConfigBean : conversionConfigBeans) {
conversionConfigBean.setReplaceTarget(isReplaceTarget);
}
validate();
}
use of org.eclipse.jface.viewers.ArrayContentProvider in project bndtools by bndtools.
the class RepositoryBundleSelectionPart method createSection.
void createSection(Section section, FormToolkit toolkit) {
// Toolbar buttons
ToolBar toolbar = new ToolBar(section, SWT.FLAT);
section.setTextClient(toolbar);
fillToolBar(toolbar);
Composite composite = toolkit.createComposite(section);
section.setClient(composite);
table = toolkit.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL);
viewer = new TableViewer(table);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(getLabelProvider());
// Listeners
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ToolItem remove = getRemoveItemTool();
if (remove != null)
remove.setEnabled(isRemovable(event.getSelection()));
}
});
ViewerDropAdapter dropAdapter = new ViewerDropAdapter(viewer) {
@Override
public void dragEnter(DropTargetEvent event) {
super.dragEnter(event);
event.detail = DND.DROP_COPY;
}
@Override
public boolean validateDrop(Object target, int operation, TransferData transferType) {
if (FileTransfer.getInstance().isSupportedType(transferType))
return true;
if (ResourceTransfer.getInstance().isSupportedType(transferType))
return true;
if (URLTransfer.getInstance().isSupportedType(transferType))
return true;
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
return false;
}
Iterator<?> iterator = ((IStructuredSelection) selection).iterator();
while (iterator.hasNext()) {
if (!selectionIsDroppable(iterator.next())) {
return false;
}
}
return true;
}
private boolean selectionIsDroppable(Object element) {
return element instanceof RepositoryBundle || element instanceof RepositoryBundleVersion || element instanceof ProjectBundle || element instanceof RepositoryResourceElement;
}
@Override
public boolean performDrop(Object data) {
TransferData transfer = getCurrentEvent().currentDataType;
if (URLTransfer.getInstance().isSupportedType(transfer)) {
String urlStr = (String) URLTransfer.getInstance().nativeToJava(transfer);
return handleURLDrop(urlStr);
} else if (data instanceof String[]) {
return handleFileNameDrop((String[]) data);
} else if (data instanceof IResource[]) {
return handleResourceDrop((IResource[]) data);
} else {
return handleSelectionDrop();
}
}
private boolean handleResourceDrop(IResource[] resources) {
File[] files = new File[resources.length];
for (int i = 0; i < resources.length; i++) {
files[i] = resources[i].getLocation().toFile();
}
return handleFileDrop(files);
}
private boolean handleFileNameDrop(String[] paths) {
File[] files = new File[paths.length];
for (int i = 0; i < paths.length; i++) {
files[i] = new File(paths[i]);
}
return handleFileDrop(files);
}
private boolean handleFileDrop(File[] files) {
if (files.length > 0) {
BndPreferences prefs = new BndPreferences();
boolean hideWarning = prefs.getHideWarningExternalFile();
if (!hideWarning) {
MessageDialogWithToggle dialog = MessageDialogWithToggle.openWarning(getSection().getShell(), "Add External Files", "External files cannot be directly added to a project, they must be added to a local repository first.", "Do not show this warning again.", false, null, null);
if (Window.CANCEL == dialog.getReturnCode())
return false;
if (dialog.getToggleState()) {
prefs.setHideWarningExternalFile(true);
}
}
AddFilesToRepositoryWizard wizard = new AddFilesToRepositoryWizard(null, files);
WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
if (Window.OK == dialog.open()) {
List<Pair<String, String>> addingBundles = wizard.getSelectedBundles();
List<VersionedClause> addingClauses = new ArrayList<VersionedClause>(addingBundles.size());
for (Pair<String, String> addingBundle : addingBundles) {
Attrs attribs = new Attrs();
attribs.put(Constants.VERSION_ATTRIBUTE, addingBundle.getSecond());
addingClauses.add(new VersionedClause(addingBundle.getFirst(), attribs));
}
handleAdd(addingClauses);
}
return true;
}
return false;
}
private boolean handleSelectionDrop() {
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
return false;
}
List<VersionedClause> adding = new LinkedList<VersionedClause>();
Iterator<?> iterator = ((IStructuredSelection) selection).iterator();
while (iterator.hasNext()) {
Object item = iterator.next();
if (item instanceof RepositoryBundle) {
VersionedClause newClause = RepositoryBundleUtils.convertRepoBundle((RepositoryBundle) item);
adding.add(newClause);
} else if (item instanceof RepositoryBundleVersion) {
RepositoryBundleVersion bundleVersion = (RepositoryBundleVersion) item;
VersionedClause newClause = RepositoryBundleUtils.convertRepoBundleVersion(bundleVersion, phase);
adding.add(newClause);
} else if (item instanceof RepositoryResourceElement) {
RepositoryResourceElement elt = (RepositoryResourceElement) item;
VersionedClause newClause = RepositoryBundleUtils.convertRepoBundleVersion(elt.getRepositoryBundleVersion(), phase);
adding.add(newClause);
}
}
handleAdd(adding);
return true;
}
private boolean handleURLDrop(String urlStr) {
try {
URI uri = new URI(sanitizeUrl(urlStr));
AddJpmDependenciesWizard wizard = new AddJpmDependenciesWizard(uri);
WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
if (dialog.open() == Window.OK) {
Set<ResourceDescriptor> resources = wizard.getResult();
List<VersionedClause> newBundles = new ArrayList<VersionedClause>(resources.size());
for (ResourceDescriptor resource : resources) {
Attrs attrs = new Attrs();
attrs.put(Constants.VERSION_ATTRIBUTE, resource.version != null ? resource.version.toString() : Version.emptyVersion.toString());
VersionedClause clause = new VersionedClause(resource.bsn, attrs);
newBundles.add(clause);
}
handleAdd(newBundles);
return true;
}
return false;
} catch (URISyntaxException e) {
MessageDialog.openError(getSection().getShell(), "Error", "The dropped URL was invalid: " + urlStr);
return false;
}
}
private String sanitizeUrl(String urlStr) {
int newline = urlStr.indexOf('\n');
if (newline > -1)
return urlStr.substring(0, newline).trim();
return urlStr;
}
private void handleAdd(Collection<VersionedClause> newClauses) {
if (newClauses == null || newClauses.isEmpty())
return;
List<VersionedClause> toAdd = new LinkedList<VersionedClause>();
for (VersionedClause newClause : newClauses) {
boolean found = false;
for (ListIterator<VersionedClause> iter = bundles.listIterator(); iter.hasNext(); ) {
VersionedClause existing = iter.next();
if (newClause.getName().equals(existing.getName())) {
int index = iter.previousIndex();
iter.set(newClause);
viewer.replace(newClause, index);
found = true;
break;
}
}
if (!found)
toAdd.add(newClause);
}
bundles.addAll(toAdd);
viewer.add(toAdd.toArray());
markDirty();
}
};
dropAdapter.setFeedbackEnabled(false);
dropAdapter.setExpandEnabled(false);
viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance(), ResourceTransfer.getInstance(), URLTransfer.getInstance() }, dropAdapter);
table.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.character == SWT.DEL) {
doRemove();
} else if (e.character == '+') {
doAdd();
}
}
});
// Layout
GridLayout layout = new GridLayout(1, false);
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
layout.marginHeight = 0;
layout.marginWidth = 0;
composite.setLayout(layout);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.widthHint = 50;
gd.heightHint = getTableHeightHint();
table.setLayoutData(gd);
}
use of org.eclipse.jface.viewers.ArrayContentProvider in project bndtools by bndtools.
the class TestSuiteLabelProvider method createSection.
private void createSection(Section section, FormToolkit toolkit) {
section.setText(Messages.TestSuitesPart_section_junit_tests);
Composite composite = toolkit.createComposite(section);
section.setClient(composite);
// Section toolbar buttons
ToolBar toolbar = new ToolBar(section, SWT.FLAT);
section.setTextClient(toolbar);
final ToolItem addItem = new ToolItem(toolbar, SWT.PUSH);
addItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
addItem.setToolTipText(Messages.TestSuitesPart_add);
final ToolItem removeItem = new ToolItem(toolbar, SWT.PUSH);
removeItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE));
removeItem.setDisabledImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE_DISABLED));
removeItem.setToolTipText(Messages.TestSuitesPart_remove);
removeItem.setEnabled(false);
Table table = toolkit.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
viewer = new TableViewer(table);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new TestSuiteLabelProvider());
toolbar = new ToolBar(composite, SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT);
final ToolItem btnMoveUp = new ToolItem(toolbar, SWT.PUSH);
btnMoveUp.setText("Up");
btnMoveUp.setImage(imgUp);
btnMoveUp.setEnabled(false);
final ToolItem btnMoveDown = new ToolItem(toolbar, SWT.PUSH);
btnMoveDown.setText("Down");
btnMoveDown.setImage(imgDown);
btnMoveDown.setEnabled(false);
// LISTENERS
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
boolean enabled = selection != null && !selection.isEmpty();
removeItem.setEnabled(enabled);
btnMoveUp.setEnabled(enabled);
btnMoveDown.setEnabled(enabled);
getManagedForm().fireSelectionChanged(TestSuitesPart.this, selection);
}
});
viewer.addOpenListener(new IOpenListener() {
@Override
public void open(OpenEvent event) {
String name = (String) ((IStructuredSelection) event.getSelection()).getFirstElement();
if (name != null)
doOpenSource(name);
}
});
viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { ResourceTransfer.getInstance() }, new TestSuiteListDropAdapter());
addItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doAdd();
}
});
removeItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doRemove();
}
});
table.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.character == SWT.DEL) {
doRemove();
} else if (e.character == '+') {
doAdd();
}
}
});
btnMoveUp.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doMoveUp();
}
});
btnMoveDown.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doMoveDown();
}
});
// Layout
GridLayout layout;
layout = new GridLayout(1, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.verticalSpacing = 0;
layout.horizontalSpacing = 0;
composite.setLayout(layout);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
// gd.widthHint = 75;
gd.heightHint = 75;
table.setLayoutData(gd);
toolbar.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
}
Aggregations