use of org.eclipse.jface.viewers.ISelectionChangedListener in project hale by halestudio.
the class PropertyEntitiesPage method createHeader.
/**
* @see EntitiesPage#createHeader(Composite)
*/
@Override
protected Control createHeader(Composite parent) {
Group typeSelectionGroup = new Group(parent, SWT.NONE);
typeSelectionGroup.setText("Type");
typeSelectionGroup.setLayout(new GridLayout());
sourceTargetSelector = new SourceTargetTypeSelector(typeSelectionGroup);
sourceTargetSelector.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
// set initial selection
sourceTargetSelector.setSelection(getInitialTypeSelection(SchemaSpaceID.SOURCE), SchemaSpaceID.SOURCE);
sourceTargetSelector.setSelection(getInitialTypeSelection(SchemaSpaceID.TARGET), SchemaSpaceID.TARGET);
// add selection listener
sourceTargetSelector.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
TypeEntityDefinition selectedType = sourceTargetSelector.getSelection(SchemaSpaceID.SOURCE);
for (PropertyField field : getFunctionFields()) {
if (field.getSchemaSpace() == SchemaSpaceID.SOURCE) {
field.setParentType(selectedType);
}
}
}
}, SchemaSpaceID.SOURCE);
sourceTargetSelector.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
TypeEntityDefinition selectedType = sourceTargetSelector.getSelection(SchemaSpaceID.TARGET);
for (PropertyField field : getFunctionFields()) if (field.getSchemaSpace() == SchemaSpaceID.TARGET)
field.setParentType(selectedType);
}
}, SchemaSpaceID.TARGET);
return typeSelectionGroup;
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project hale by halestudio.
the class NewRelationPage method createViewer.
/**
* @see ViewerWizardSelectionPage#createViewer(Composite)
*/
@Override
protected Pair<StructuredViewer, Control> createViewer(Composite parent) {
PatternFilter filter = new PatternFilter();
filter.setIncludeLeadingWildcard(true);
FilteredTree tree = new FilteredTree(parent, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, filter, true);
viewer = tree.getViewer();
viewer.setContentProvider(new FunctionWizardNodeContentProvider(getContainer(), initialSelection, selectionMatcher));
viewer.setLabelProvider(new FunctionWizardNodeLabelProvider());
// no input needed, but we have to set something
viewer.setInput(Boolean.TRUE);
// set focus on viewer control to prevent odd behavior
viewer.getControl().setFocus();
// expand selection
viewer.expandAll();
// selection context
contextProvider = new HALEContextProvider(viewer, null);
// help update on page shown
if (getContainer() instanceof IPageChangeProvider) {
((IPageChangeProvider) getContainer()).addPageChangedListener(changeListener = new IPageChangedListener() {
@Override
public void pageChanged(PageChangedEvent event) {
if (event.getSelectedPage() == NewRelationPage.this) {
// update the help button
if (getContainer() instanceof HaleWizardDialog) {
((HaleWizardDialog) getContainer()).setHelpButtonEnabled(getHelpContext() != null);
}
}
}
});
}
// help update on selection change
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IContext context = getHelpContext();
// update the help button
if (getContainer() instanceof HaleWizardDialog) {
((HaleWizardDialog) getContainer()).setHelpButtonEnabled(context != null);
}
// update the help
if (context != null) {
TrayDialog trayDialog = (TrayDialog) getContainer();
if (trayDialog.getTray() != null) {
// if the tray is already open, update the help
performHelp();
}
}
}
});
// load page configuration
// XXX would be better if called from outside
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
restore(ps.getConfigurationService());
return new Pair<StructuredViewer, Control>(viewer, tree);
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project hale by halestudio.
the class URLSource method createControls.
/**
* @see ImportSource#createControls(Composite)
*/
@Override
public void createControls(Composite parent) {
parent.setLayout(new GridLayout(3, false));
detectImage = HALEUIPlugin.getImageDescriptor("icons/find_obj.gif").createImage();
// source file
sourceURL = new URLSourceURIFieldEditor("sourceURL", "Source URL:", parent) {
@Override
protected void onHistorySelected(URI location, IContentType contentType) {
// select the content type associated with the recent URL
types.setSelection(new StructuredSelection(contentType));
updateState(false);
}
};
sourceURL.setPage(getPage());
// set content types for file field
Collection<IOProviderDescriptor> factories = getConfiguration().getFactories();
supportedTypes = new HashSet<IContentType>();
for (IOProviderDescriptor factory : factories) {
supportedTypes.addAll(factory.getSupportedTypes());
}
sourceURL.setContentTypes(supportedTypes);
sourceURL.setPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
if (event.getProperty().equals(FieldEditor.IS_VALID)) {
getPage().setMessage(null);
updateState(false);
} else if (event.getProperty().equals(FieldEditor.VALUE)) {
getPage().setMessage(null);
updateState(false);
}
}
});
// content type selection
// label
Label typesLabel = new Label(parent, SWT.NONE);
typesLabel.setText("Content type");
// types combo
Composite group = new Composite(parent, SWT.NONE);
group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
group.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create());
types = new ComboViewer(group, SWT.DROP_DOWN | SWT.READ_ONLY);
types.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
types.setContentProvider(ArrayContentProvider.getInstance());
types.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof IContentType) {
return ((IContentType) element).getName();
}
return super.getText(element);
}
});
types.setInput(supportedTypes);
// process selection changes
types.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
updateState(true);
}
});
// detect button
detect = new Button(group, SWT.PUSH);
detect.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
detect.setText("Detect");
detect.setImage(detectImage);
detect.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
runDetectContentType();
}
});
// provider selection
// label
Label providerLabel = new Label(parent, SWT.NONE);
providerLabel.setText("Import as");
// create provider combo
ComboViewer providers = createProviders(parent);
providers.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1));
// initial state update
updateState(true);
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project hale by halestudio.
the class RuleStylePage method createControl.
/**
* @see IDialogPage#createControl(Composite)
*/
@Override
public void createControl(Composite parent) {
changed = false;
Composite page = new Composite(parent, SWT.NONE);
page.setLayout(new GridLayout(2, false));
// DISABLED - this method seems to change the rule order - Rule[]
// ruleArray = SLD.rules(getParent().getStyle());
// use list instead:
List<Rule> ruleList;
try {
ruleList = getParent().getStyle().featureTypeStyles().get(0).rules();
} catch (Exception e) {
ruleList = new ArrayList<Rule>();
}
// init index
if (ruleList.size() > 0) {
currentIndex = 0;
} else {
currentIndex = -1;
}
currentEditor = null;
// populate rule map
rules = new ArrayList<RuleItem>(ruleList.size() + 5);
for (int i = 0; i < ruleList.size(); i++) {
Rule rule = ruleList.get(i);
if (rule != null) {
rules.add(new RuleItem(rule));
}
}
// rule list
Composite ruleArea = new Composite(page, SWT.NONE);
ruleArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
GridLayout leftLayout = new GridLayout(5, true);
leftLayout.horizontalSpacing = 1;
leftLayout.verticalSpacing = 1;
ruleArea.setLayout(leftLayout);
// label
Label rulesLabel = new Label(ruleArea, SWT.NONE);
rulesLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 5, 1));
rulesLabel.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
rulesLabel.setText(Messages.RuleStylePage_RuleLabelText);
// viewer
listViewer = new ListViewer(ruleArea);
listViewer.getList().setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 5, 1));
listViewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// ignore
}
@Override
public void dispose() {
// ignore
}
@SuppressWarnings("unchecked")
@Override
public Object[] getElements(Object inputElement) {
try {
List<RuleItem> rules = (List<RuleItem>) inputElement;
return rules.toArray();
} catch (Exception e) {
return null;
}
}
});
listViewer.setInput(rules);
if (currentIndex >= 0 && currentIndex < rules.size()) {
listViewer.setSelection(new StructuredSelection(rules.get(currentIndex)));
}
listViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
RuleItem item = (RuleItem) ((IStructuredSelection) event.getSelection()).getFirstElement();
int newIndex = rules.indexOf(item);
if (currentIndex != newIndex) {
try {
updateCurrentRule();
} catch (Exception e) {
log.userError("Invalid editor state, could not update rule.", e);
return;
}
currentIndex = newIndex;
updateEditor();
}
}
});
// buttons
addButton = new Button(ruleArea, SWT.PUSH);
addButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
addButton.setImage(addImage);
addButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
addRule();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// ignore
}
});
addButton.setToolTipText(Messages.RuleStylePage_AddRuleButtonToolTippText);
removeButton = new Button(ruleArea, SWT.PUSH);
removeButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
removeButton.setImage(removeImage);
removeButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
removeCurrentRule();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// ignore
}
});
removeButton.setToolTipText(Messages.RuleStylePage_RemoveRuleButtonToolTippText);
upButton = new Button(ruleArea, SWT.PUSH);
upButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
upButton.setImage(upImage);
upButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
moveCurrentRuleUp();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// ignore
}
});
upButton.setToolTipText(Messages.RuleStylePage_UpRuleButtonToolTippText);
downButton = new Button(ruleArea, SWT.PUSH);
downButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
downButton.setImage(downImage);
downButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
moveCurrentRuleDown();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// ignore
}
});
downButton.setToolTipText(Messages.RuleStylePage_DownRuleButtonToolTippText);
renameButton = new Button(ruleArea, SWT.PUSH);
renameButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
renameButton.setImage(renameImage);
renameButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
renameCurrentRule();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// ignore
}
});
renameButton.setToolTipText(Messages.RuleStylePage_RenameRuleButtonToolTippText);
// editor area
editorArea = new Composite(page, SWT.NONE);
editorArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
editorArea.setLayout(new FillLayout());
setControl(page);
updateEditor();
}
use of org.eclipse.jface.viewers.ISelectionChangedListener in project hale by halestudio.
the class MismatchPropertiesBlock method createMasterPart.
/* (non-Javadoc)
* @see org.eclipse.ui.forms.MasterDetailsBlock#createMasterPart(org.eclipse.ui.forms.IManagedForm, org.eclipse.swt.widgets.Composite)
*/
@Override
protected void createMasterPart(final IManagedForm managedForm, Composite parent) {
FormToolkit toolkit = managedForm.getToolkit();
Section section = toolkit.createSection(parent, Section.DESCRIPTION | Section.TITLE_BAR);
// $NON-NLS-1$
section.setText("Mismatches");
section.setDescription(// $NON-NLS-1$
"Select the Mismatch or one of it's children to view and edit it.");
section.marginWidth = 10;
section.marginHeight = 5;
Composite client = toolkit.createComposite(section, SWT.WRAP);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginWidth = 2;
layout.marginHeight = 2;
client.setLayout(layout);
Tree tree = toolkit.createTree(client, SWT.NULL);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 20;
gd.widthHint = 250;
tree.setLayoutData(gd);
toolkit.paintBordersFor(client);
section.setClient(client);
final SectionPart spart = new SectionPart(section);
managedForm.addPart(spart);
TreeViewer mismatchTreeViewer = new TreeViewer(tree);
mismatchTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
managedForm.fireSelectionChanged(spart, event.getSelection());
}
});
mismatchTreeViewer.setContentProvider(new MismatchTreeContentProvider());
mismatchTreeViewer.setLabelProvider(new MismatchTreeLabelProvider());
mismatchTreeViewer.setInput(getDummyCell());
}
Aggregations