package net.sourceforge.tagsea.tasks.waypoints; import net.sourceforge.tagsea.core.ui.IWaypointFilter; import net.sourceforge.tagsea.core.ui.IWaypointFilterUI; import net.sourceforge.tagsea.tasks.TaskWaypointPlugin; import net.sourceforge.tagsea.tasks.TaskWaypointPreferences; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; // public class WaypointFilterUI implements IWaypointFilterUI { private Button anyResourceButton; private Button anyResourceInSameProjectButton; private Button selectedResourceButton; private Button selectedResourceAndChildrenButton; private Button linkToResourceButton; private Button filterAutoGenerated; private Text autoGeneratedMatchText; private Label autoGeneratedLabel; public void applyToFilter() { IPreferenceStore store = TaskWaypointPlugin.getDefault().getPreferenceStore(); if (anyResourceButton.getSelection()) { store.setValue(TaskWaypointPreferences.FILTER_PREFERENCE_KEY, TaskWaypointPreferences.FILTER_ANY); } else if (anyResourceInSameProjectButton.getSelection()){ store.setValue(TaskWaypointPreferences.FILTER_PREFERENCE_KEY, TaskWaypointPreferences.FILTER_PROJECT); } else if (selectedResourceButton.getSelection()) { store.setValue(TaskWaypointPreferences.FILTER_PREFERENCE_KEY, TaskWaypointPreferences.FILTER_SELECTED); } else if (selectedResourceAndChildrenButton.getSelection()) { store.setValue(TaskWaypointPreferences.FILTER_PREFERENCE_KEY, TaskWaypointPreferences.FILTER_CHILDREN); } store.setValue(TaskWaypointPreferences.LINK_TO_RESOURCES_KEY, linkToResourceButton.getSelection()); store.setValue(TaskWaypointPreferences.AUTO_GENERATED_KEY, filterAutoGenerated.getSelection()); store.setValue(TaskWaypointPreferences.AUTO_GENERATED_MATCH_KEY, autoGeneratedMatchText.getText()); } public Control createControl(Composite parent) { Composite page = new Composite(parent, SWT.NONE); page.setLayout(new GridLayout()); page.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); linkToResourceButton = createButton(page, "Link to Resources Filter", SWT.CHECK); Composite group = new Composite(page, SWT.NONE); group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); GridLayout layout = new GridLayout(); layout.marginLeft = 15; group.setLayout(layout); group.setFont(parent.getFont()); anyResourceButton = createButton(group, "On any element", SWT.RADIO); anyResourceInSameProjectButton = createButton(group, "On any element in selected project", SWT.RADIO); selectedResourceButton = createButton(group, "On selected element", SWT.RADIO); selectedResourceAndChildrenButton = createButton(group, "On selected element and its children", SWT.RADIO); String filterType = TaskWaypointPreferences.getCurrentFilterType(); if (filterType.equals(TaskWaypointPreferences.FILTER_ANY)) { anyResourceButton.setSelection(true); } else if (filterType.equals(TaskWaypointPreferences.FILTER_CHILDREN)) { selectedResourceAndChildrenButton.setSelection(true); } else if (filterType.equals(TaskWaypointPreferences.FILTER_PROJECT)) { anyResourceInSameProjectButton.setSelection(true); } else if (filterType.equals(TaskWaypointPreferences.FILTER_SELECTED)) { selectedResourceButton.setSelection(true); } if (TaskWaypointPreferences.isFilterLinkedToResources()) { linkToResourceButton.setSelection(true); setRadioEnablment(false); } linkToResourceButton.addSelectionListener(new SelectionAdapter(){ /* (non-Javadoc) * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) */ @Override public void widgetSelected(SelectionEvent e) { setRadioEnablment(!linkToResourceButton.getSelection()); } }); filterAutoGenerated = createButton(page, "Filter Auto-generated tasks", SWT.CHECK); boolean isFilterAutoGenerated = TaskWaypointPreferences.isFilterAutoGenerated(); filterAutoGenerated.setLayoutData(new GridData(SWT.FILL, GridData.BEGINNING, true, false)); filterAutoGenerated.setSelection(isFilterAutoGenerated); filterAutoGenerated.addSelectionListener(new SelectionAdapter(){ @Override public void widgetSelected(SelectionEvent e) { boolean isFilterAutoGenerated = filterAutoGenerated.getSelection(); autoGeneratedLabel.setEnabled(isFilterAutoGenerated); autoGeneratedMatchText.setEnabled(isFilterAutoGenerated); } }); Composite matchComposite = new Composite(page, SWT.NONE); matchComposite.setLayoutData(new GridData(SWT.FILL, GridData.BEGINNING, true, false)); matchComposite.setLayout(new GridLayout(2, false)); autoGeneratedLabel = new Label(matchComposite, SWT.NONE); autoGeneratedLabel.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false)); autoGeneratedLabel.setText("Begins with: "); autoGeneratedMatchText = new Text(matchComposite, SWT.SINGLE | SWT.BORDER); autoGeneratedMatchText.setLayoutData(new GridData(SWT.FILL, GridData.BEGINNING, true, false)); autoGeneratedMatchText.setText(TaskWaypointPreferences.getAutoGeneratedMatchText()); autoGeneratedLabel.setEnabled(isFilterAutoGenerated); autoGeneratedMatchText.setEnabled(isFilterAutoGenerated); return page; } /** * @param b */ private void setRadioEnablment(boolean b) { anyResourceButton.setEnabled(b); anyResourceInSameProjectButton.setEnabled(b); selectedResourceAndChildrenButton.setEnabled(b); selectedResourceButton.setEnabled(b); } /** * Creates a radio button with the given parent and text. * * @param parent the parent composite * @param text the text for the check box * @return the radio box button */ Button createButton(Composite parent, String text, int type) { Button button = new Button(parent, type); button.setText(text); button.setFont(parent.getFont()); return button; } public void initialize(IWaypointFilter filter) { } }