Rework the query property page.
This commit is contained in:
parent
25db1103ec
commit
f734495fd4
@ -5,23 +5,33 @@
|
||||
package io.gitea.mylyn.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.jface.dialogs.ErrorDialog;
|
||||
import org.eclipse.jface.layout.GridDataFactory;
|
||||
import org.eclipse.jface.layout.GridLayoutFactory;
|
||||
import org.eclipse.jface.operation.IRunnableContext;
|
||||
import org.eclipse.jface.viewers.ArrayContentProvider;
|
||||
import org.eclipse.jface.viewers.CheckboxTableViewer;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
import org.eclipse.jface.viewers.TableViewer;
|
||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||
import org.eclipse.jface.wizard.IWizardPage;
|
||||
import org.eclipse.mylyn.commons.core.ICoreRunnable;
|
||||
import org.eclipse.mylyn.commons.net.Policy;
|
||||
import org.eclipse.mylyn.commons.ui.CommonUiUtil;
|
||||
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
|
||||
import org.eclipse.mylyn.tasks.core.TaskRepository;
|
||||
import org.eclipse.mylyn.tasks.ui.TasksUiImages;
|
||||
import org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositoryQueryPage;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.FocusEvent;
|
||||
import org.eclipse.swt.events.FocusListener;
|
||||
import org.eclipse.swt.events.KeyEvent;
|
||||
import org.eclipse.swt.events.KeyListener;
|
||||
import org.eclipse.swt.events.DisposeEvent;
|
||||
import org.eclipse.swt.events.DisposeListener;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
@ -33,9 +43,13 @@ import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Group;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.TableItem;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
import org.eclipse.swt.widgets.ToolBar;
|
||||
import org.eclipse.swt.widgets.ToolItem;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
|
||||
import io.gitea.ApiException;
|
||||
import io.gitea.model.GiteaUser;
|
||||
import io.gitea.model.IssueState;
|
||||
import io.gitea.model.Milestone;
|
||||
import io.gitea.mylyn.core.ConnectionManager;
|
||||
@ -43,247 +57,645 @@ import io.gitea.mylyn.core.GiteaConnection;
|
||||
|
||||
public class GiteaQueryPage extends AbstractRepositoryQueryPage implements IWizardPage {
|
||||
|
||||
private Button openButton;
|
||||
private Button closedButton;
|
||||
private Text titleText;
|
||||
private Text assigneeText;
|
||||
private Text newLabel;
|
||||
private Combo milestoneCombo;
|
||||
private TableViewer labelsViewer;
|
||||
private SelectionListener completeListener = new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
setPageComplete(isPageComplete());
|
||||
}
|
||||
};
|
||||
|
||||
private SelectionListener completeListener = new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
setPageComplete(isPageComplete());
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @param pageName
|
||||
* @param taskRepository
|
||||
* @param query
|
||||
*/
|
||||
public GiteaQueryPage(String pageName, TaskRepository taskRepository, IRepositoryQuery query) {
|
||||
super(pageName, taskRepository, query);
|
||||
setDescription("Specify your query");
|
||||
setPageComplete(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pageName
|
||||
* @param taskRepository
|
||||
* @param query
|
||||
*/
|
||||
public GiteaQueryPage(String pageName, TaskRepository taskRepository, IRepositoryQuery query) {
|
||||
super(pageName, taskRepository, query);
|
||||
setDescription("Specify your query");
|
||||
setPageComplete(false);
|
||||
}
|
||||
// ---------------------------------------------------------------------
|
||||
// DEFINE QUERY TITLE AREA
|
||||
// ---------------------------------------------------------------------
|
||||
private Text titleText;
|
||||
|
||||
private void createLabelsArea(Composite parent) {
|
||||
Group labelsArea = new Group(parent, SWT.NONE);
|
||||
labelsArea.setText(Labels.QUERY_GROUP_LABELS);
|
||||
GridDataFactory.fillDefaults().grab(true, true).applyTo(labelsArea);
|
||||
GridLayoutFactory.swtDefaults().applyTo(labelsArea);
|
||||
/**
|
||||
* Create Query title area . Query title is 2 columns based (not same size)
|
||||
*
|
||||
* @implNote allocate {@titleText} private Text widget.
|
||||
*/
|
||||
private void createQueryTitleArea(Composite parent) {
|
||||
Composite titleArea = new Composite(parent, SWT.NONE);
|
||||
GridLayoutFactory.fillDefaults().numColumns(2).applyTo(titleArea);
|
||||
GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(titleArea);
|
||||
|
||||
labelsViewer = new TableViewer(labelsArea, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
|
||||
new Label(titleArea, SWT.NONE).setText(Labels.QUERY_TITLE);
|
||||
titleText = new Text(titleArea, SWT.SINGLE | SWT.BORDER);
|
||||
GridDataFactory.fillDefaults().grab(true, false).applyTo(titleText);
|
||||
titleText.addModifyListener(new ModifyListener() {
|
||||
public void modifyText(ModifyEvent e) {
|
||||
setPageComplete(isPageComplete());
|
||||
}
|
||||
});
|
||||
|
||||
GridDataFactory.fillDefaults().grab(true, true).hint(100, 80).applyTo(labelsViewer.getControl());
|
||||
labelsViewer.setContentProvider(ArrayContentProvider.getInstance());
|
||||
labelsViewer.setLabelProvider(new LabelProvider() {
|
||||
public Image getImage(Object element) {
|
||||
return GiteaImages.LABEL;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
newLabel = new Text(labelsArea, SWT.BORDER);
|
||||
GridDataFactory.fillDefaults().grab(true, false).applyTo(newLabel);
|
||||
// ---------------------------------------------------------------------
|
||||
// FILTER BY ISSUE STATE AREA
|
||||
// ---------------------------------------------------------------------
|
||||
private Button openButton;
|
||||
private Button closedButton;
|
||||
|
||||
Composite btnArea = new Composite(labelsArea, SWT.NONE);
|
||||
GridDataFactory.fillDefaults().grab(true, true).applyTo(btnArea);
|
||||
GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(true).applyTo(btnArea);
|
||||
/**
|
||||
* Create issue state filter area.
|
||||
*
|
||||
* @param parent Composite the state filter area is attached to.
|
||||
* @implNote allocate {@openButton} and @{closedButton} private buttons.
|
||||
*/
|
||||
private void createIssueStateArea(Composite parent) {
|
||||
Composite statusArea = new Composite(parent, SWT.NONE);
|
||||
GridLayoutFactory.fillDefaults().numColumns(4).equalWidth(false).applyTo(statusArea);
|
||||
GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(statusArea);
|
||||
|
||||
final Button btnAdd = new Button(btnArea, SWT.BORDER);
|
||||
btnAdd.setText(Labels.QUERY_NEW_LABEL_REGEX);
|
||||
GridDataFactory.fillDefaults().grab(true, false).applyTo(btnAdd);
|
||||
new Label(statusArea, SWT.NONE).setText(Labels.QUERY_STATE);
|
||||
|
||||
Button btnRemove = new Button(btnArea, SWT.BORDER);
|
||||
btnRemove.setText(Labels.QUERY_REMOVE_LABEL_REGEX);
|
||||
GridDataFactory.fillDefaults().grab(true, false).applyTo(btnRemove);
|
||||
openButton = new Button(statusArea, SWT.CHECK);
|
||||
openButton.setSelection(true);
|
||||
openButton.setText(IssueState.STATE_OPENED.toString());
|
||||
openButton.addSelectionListener(completeListener);
|
||||
|
||||
btnAdd.addSelectionListener(new SelectionListener() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
String[] split = newLabel.getText().split(",");
|
||||
for (String s : split) {
|
||||
if (s.trim().length() > 0) {
|
||||
labelsViewer.add(s.trim());
|
||||
}
|
||||
}
|
||||
newLabel.setText("");
|
||||
}
|
||||
closedButton = new Button(statusArea, SWT.CHECK);
|
||||
closedButton.setSelection(true);
|
||||
closedButton.setText(IssueState.STATE_CLOSED.toString());
|
||||
closedButton.addSelectionListener(completeListener);
|
||||
|
||||
@Override
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
}
|
||||
});
|
||||
createRefreshButton(statusArea);
|
||||
|
||||
btnRemove.addSelectionListener(new SelectionListener() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
removeSelection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
}
|
||||
});
|
||||
// ---------------------------------------------------------------------
|
||||
// REFRESH BUTTON
|
||||
// ---------------------------------------------------------------------
|
||||
private void createRefreshButton(Composite parent) {
|
||||
ToolBar toolbar = new ToolBar(parent, SWT.FLAT);
|
||||
ToolItem updateItem = new ToolItem(toolbar, SWT.PUSH);
|
||||
final Image updateImage = TasksUiImages.REPOSITORY_UPDATE_CONFIGURATION.createImage();
|
||||
toolbar.addDisposeListener(new DisposeListener() {
|
||||
|
||||
newLabel.addFocusListener(new FocusListener() {
|
||||
@Override
|
||||
public void widgetDisposed(DisposeEvent e) {
|
||||
updateImage.dispose();
|
||||
}
|
||||
});
|
||||
updateItem.setImage(updateImage);
|
||||
updateItem.setToolTipText(Messages.MylynGiteaUIQueryPage_TooltipUpdateRepository);
|
||||
GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).grab(true, false).applyTo(toolbar);
|
||||
updateItem.addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
@Override
|
||||
public void focusLost(FocusEvent e) {
|
||||
getShell().setDefaultButton(null);
|
||||
setPageComplete(isPageComplete());
|
||||
}
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
refreshRepository();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void focusGained(FocusEvent e) {
|
||||
getShell().setDefaultButton(btnAdd);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
labelsViewer.getTable().addKeyListener(new KeyListener() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.keyCode == SWT.DEL) {
|
||||
removeSelection();
|
||||
}
|
||||
}
|
||||
// ---------------------------------------------------------------------
|
||||
// FILTER BY MILESTONE AREA
|
||||
// ---------------------------------------------------------------------
|
||||
private Combo milestoneCombo;
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Create milestones selection area.
|
||||
*
|
||||
* @param parent Composite the milestone selection area is attached to.
|
||||
* @implNote Allocate {@literal milestoneCombo} private Combo.
|
||||
*/
|
||||
private void createFilterByMilestoneArea(Composite parent) {
|
||||
Composite milestonesArea = new Composite(parent, SWT.NONE);
|
||||
GridLayoutFactory.fillDefaults().numColumns(4).equalWidth(false).applyTo(milestonesArea);
|
||||
GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(milestonesArea);
|
||||
|
||||
private void removeSelection() {
|
||||
StructuredSelection selection = (StructuredSelection) labelsViewer.getSelection();
|
||||
if (!selection.isEmpty()) {
|
||||
labelsViewer.remove(selection.toArray());
|
||||
}
|
||||
}
|
||||
Label milestonesLabel = new Label(milestonesArea, SWT.NONE);
|
||||
milestonesLabel.setText(Labels.QUERY_MILESTONE);
|
||||
|
||||
private void createOptionsArea(Composite parent) {
|
||||
Composite optionsArea = new Composite(parent, SWT.NONE);
|
||||
GridLayoutFactory.fillDefaults().numColumns(2).applyTo(optionsArea);
|
||||
GridDataFactory.fillDefaults().grab(true, true).applyTo(optionsArea);
|
||||
milestoneCombo = new Combo(milestonesArea, SWT.DROP_DOWN | SWT.READ_ONLY);
|
||||
GridDataFactory.fillDefaults().grab(true, false).applyTo(milestoneCombo);
|
||||
updateMilestones();
|
||||
|
||||
Composite statusArea = new Composite(optionsArea, SWT.NONE);
|
||||
GridLayoutFactory.fillDefaults().numColumns(4).equalWidth(false).applyTo(statusArea);
|
||||
GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(statusArea);
|
||||
}
|
||||
|
||||
new Label(statusArea, SWT.NONE).setText(Labels.QUERY_STATE);
|
||||
// ---------------------------------------------------------------------
|
||||
// FILTER BY ASSIGNED MEMBER AREA
|
||||
// ---------------------------------------------------------------------
|
||||
private Text assigneeText;
|
||||
private CheckboxTableViewer assignedViewer;
|
||||
private void refreshAssignedText() {
|
||||
if ((assigneeText != null) && (assignedViewer != null)) {
|
||||
List<String> checkedItemsList = new ArrayList<String>();
|
||||
for (Object o : assignedViewer.getCheckedElements()) {
|
||||
checkedItemsList.add(((String) o));
|
||||
}
|
||||
assigneeText.setText(StringUtils.join(checkedItemsList, ",")); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
openButton = new Button(statusArea, SWT.CHECK);
|
||||
openButton.setSelection(true);
|
||||
openButton.setText(IssueState.STATE_OPENED.toString());
|
||||
openButton.addSelectionListener(completeListener);
|
||||
|
||||
/**
|
||||
* Create filter by assigned member area.
|
||||
*
|
||||
* @param parent Composite the filter by assigned member area is attached to.
|
||||
* @implNote Allocate {@literal assignedViewer} private attribute.
|
||||
*/
|
||||
private void createFilterByAssignedMembersArea(Composite parent) {
|
||||
Group assignedArea = new Group(parent, SWT.NONE);
|
||||
assignedArea.setText(Labels.QUERY_ASSIGNEE);
|
||||
GridDataFactory.fillDefaults().grab(true, true).applyTo(assignedArea);
|
||||
GridLayoutFactory.swtDefaults().applyTo(assignedArea);
|
||||
|
||||
closedButton = new Button(statusArea, SWT.CHECK);
|
||||
closedButton.setSelection(true);
|
||||
closedButton.setText(IssueState.STATE_CLOSED.toString());
|
||||
closedButton.addSelectionListener(completeListener);
|
||||
assigneeText = new Text(assignedArea, SWT.BORDER | SWT.SINGLE);
|
||||
GridDataFactory.fillDefaults().grab(true, false).applyTo(assigneeText);
|
||||
|
||||
Label milestonesLabel = new Label(optionsArea, SWT.NONE);
|
||||
milestonesLabel.setText(Labels.QUERY_MILESTONE);
|
||||
assignedViewer = CheckboxTableViewer.newCheckList(assignedArea, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
|
||||
|
||||
milestoneCombo = new Combo(optionsArea, SWT.DROP_DOWN | SWT.READ_ONLY);
|
||||
GridDataFactory.fillDefaults().grab(true, false).applyTo(milestoneCombo);
|
||||
GiteaConnection connection = ConnectionManager.getSafe(getTaskRepository());
|
||||
if (connection != null) {
|
||||
milestoneCombo.add("");
|
||||
for (Milestone s : connection.getMilestones()) {
|
||||
milestoneCombo.add(s.getTitle());
|
||||
}
|
||||
}
|
||||
GridDataFactory.fillDefaults().grab(true, true).hint(100, 80).applyTo(assignedViewer.getControl());
|
||||
assignedViewer.setContentProvider(ArrayContentProvider.getInstance());
|
||||
assignedViewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
||||
@Override
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
setPageComplete(isPageComplete());
|
||||
refreshAssignedText();
|
||||
}
|
||||
});
|
||||
|
||||
Composite buttonsArea = new Composite(assignedArea, SWT.BORDER | SWT.NONE);
|
||||
GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonsArea);
|
||||
GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(true).applyTo(buttonsArea);
|
||||
|
||||
Label assigneeLabel = new Label(optionsArea, SWT.NONE);
|
||||
assigneeLabel.setText(Labels.QUERY_ASSIGNEE);
|
||||
final Button selectAllButton = new Button(buttonsArea, SWT.BORDER);
|
||||
selectAllButton.setText(Labels.QUERY_SELECT_ALL_BUTTON);
|
||||
GridDataFactory.fillDefaults().grab(true, false).applyTo(selectAllButton);
|
||||
|
||||
assigneeText = new Text(optionsArea, SWT.BORDER | SWT.SINGLE);
|
||||
GridDataFactory.fillDefaults().grab(true, false).applyTo(assigneeText);
|
||||
}
|
||||
selectAllButton.addSelectionListener(new SelectionListener() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
assignedViewer.setAllChecked(true);
|
||||
refreshAssignedText();
|
||||
}
|
||||
|
||||
public void createControl(Composite parent) {
|
||||
Composite displayArea = new Composite(parent, SWT.NONE);
|
||||
GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(true).applyTo(displayArea);
|
||||
GridDataFactory.fillDefaults().grab(true, true).applyTo(displayArea);
|
||||
@Override
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
}
|
||||
});
|
||||
|
||||
if (!inSearchContainer()) {
|
||||
Composite titleArea = new Composite(displayArea, SWT.NONE);
|
||||
GridLayoutFactory.fillDefaults().numColumns(2).applyTo(titleArea);
|
||||
GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(titleArea);
|
||||
Button selectNoneButton = new Button(buttonsArea, SWT.BORDER);
|
||||
selectNoneButton.setText(Labels.QUERY_SELECT_NONE_BUTTON);
|
||||
GridDataFactory.fillDefaults().grab(true, false).applyTo(selectNoneButton);
|
||||
|
||||
new Label(titleArea, SWT.NONE).setText(Labels.QUERY_TITLE);
|
||||
titleText = new Text(titleArea, SWT.SINGLE | SWT.BORDER);
|
||||
GridDataFactory.fillDefaults().grab(true, false).applyTo(titleText);
|
||||
titleText.addModifyListener(new ModifyListener() {
|
||||
public void modifyText(ModifyEvent e) {
|
||||
setPageComplete(isPageComplete());
|
||||
}
|
||||
});
|
||||
}
|
||||
selectNoneButton.addSelectionListener(new SelectionListener() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
assignedViewer.setAllChecked(false);
|
||||
refreshAssignedText();
|
||||
}
|
||||
|
||||
createOptionsArea(displayArea);
|
||||
@Override
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
}
|
||||
});
|
||||
|
||||
createLabelsArea(displayArea);
|
||||
try {
|
||||
updateAssigned();
|
||||
} catch (ApiException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
initialize();
|
||||
setControl(displayArea);
|
||||
}
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
IRepositoryQuery query = getQuery();
|
||||
if (query == null) {
|
||||
return;
|
||||
}
|
||||
// ---------------------------------------------------------------------
|
||||
// FILTER BY LABELS AREA
|
||||
// ---------------------------------------------------------------------
|
||||
// private TableViewer labelsViewer;
|
||||
private Text labelsText;
|
||||
private CheckboxTableViewer labelsViewer; // not issue type, not priority
|
||||
|
||||
titleText.setText(query.getSummary());
|
||||
assigneeText.setText(query.getAttribute("assignee"));
|
||||
milestoneCombo.setText(query.getAttribute("milestone"));
|
||||
private void refreshLabelsText() {
|
||||
if ((labelsText != null) && (labelsViewer != null)) {
|
||||
List<String> checkedItemsList = new ArrayList<String>();
|
||||
for (Object o : labelsViewer.getCheckedElements()) {
|
||||
checkedItemsList.add(((String) o));
|
||||
}
|
||||
labelsText.setText(StringUtils.join(checkedItemsList, ",")); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
openButton.setSelection(Boolean.parseBoolean(query.getAttribute("opened")));
|
||||
closedButton.setSelection(Boolean.parseBoolean(query.getAttribute("closed")));
|
||||
// --private CheckboxTableViewer prioritiesViewer; // 'priority' labels
|
||||
// --private CheckboxTableViewer issueTypesViewer;// 'issue' type labels
|
||||
private void createFilterByLabelsArea(Composite parent) {
|
||||
// Group labelsArea = new Group(parent, SWT.NONE);
|
||||
// labelsArea.setText(Labels.QUERY_GROUP_LABELS);
|
||||
// GridDataFactory.fillDefaults().grab(true, true).applyTo(labelsArea);
|
||||
// GridLayoutFactory.swtDefaults().applyTo(labelsArea);
|
||||
|
||||
for (String label : query.getAttribute("labels").split(",")) {
|
||||
if (label.trim().length() > 0) {
|
||||
labelsViewer.add(label.trim());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* -- Group issuesArea = new Group(parent, SWT.NONE);
|
||||
* issuesArea.setText(Labels.QUERY_GROUP_LABELS_ISSUE_TYPES);
|
||||
* GridDataFactory.fillDefaults().grab(true, true).applyTo(issuesArea);
|
||||
* GridLayoutFactory.swtDefaults().applyTo(issuesArea);
|
||||
*
|
||||
* Group prioritiesArea = new Group(parent, SWT.NONE);
|
||||
* prioritiesArea.setText(Labels.QUERY_GROUP_LABELS_PRIORITIES);
|
||||
* GridDataFactory.fillDefaults().grab(true, true).applyTo(prioritiesArea);
|
||||
* GridLayoutFactory.swtDefaults().applyTo(prioritiesArea); --
|
||||
*/
|
||||
Group labelsArea = new Group(parent, SWT.READ_ONLY);
|
||||
labelsArea.setText(Labels.QUERY_GROUP_LABELS);
|
||||
GridDataFactory.fillDefaults().grab(true, true).applyTo(labelsArea);
|
||||
GridLayoutFactory.swtDefaults().applyTo(labelsArea);
|
||||
|
||||
}
|
||||
labelsText = new Text(labelsArea, SWT.BORDER);
|
||||
GridDataFactory.fillDefaults().grab(true, false).applyTo(labelsText);
|
||||
|
||||
public boolean isPageComplete() {
|
||||
boolean complete = inSearchContainer() ? true : super.isPageComplete();
|
||||
if (complete) {
|
||||
String message = null;
|
||||
if (!openButton.getSelection() && !closedButton.getSelection()) {
|
||||
message = "Select either closed, opened or both issue states";
|
||||
}
|
||||
labelsViewer = CheckboxTableViewer.newCheckList(labelsArea, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
|
||||
|
||||
setErrorMessage(message);
|
||||
complete = message == null;
|
||||
}
|
||||
return complete;
|
||||
}
|
||||
GridDataFactory.fillDefaults().grab(true, true).hint(100, 80).applyTo(labelsViewer.getControl());
|
||||
labelsViewer.setContentProvider(ArrayContentProvider.getInstance());
|
||||
labelsViewer.setLabelProvider(new LabelProvider() {
|
||||
public Image getImage(Object element) {
|
||||
return GiteaImages.LABEL;
|
||||
}
|
||||
});
|
||||
labelsViewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
||||
@Override
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
setPageComplete(isPageComplete());
|
||||
refreshLabelsText();
|
||||
}
|
||||
});
|
||||
|
||||
public String getQueryTitle() {
|
||||
return titleText != null ? titleText.getText() : null;
|
||||
}
|
||||
/*
|
||||
* -- TODO: filter labels by priority prioritiesViewer =
|
||||
* CheckboxTableViewer.newCheckList(prioritiesArea, SWT.BORDER | SWT.V_SCROLL |
|
||||
* SWT.H_SCROLL);
|
||||
*
|
||||
* GridDataFactory.fillDefaults().grab(true, true).hint(100,
|
||||
* 80).applyTo(prioritiesViewer.getControl());
|
||||
* prioritiesViewer.setContentProvider(ArrayContentProvider.getInstance());
|
||||
* prioritiesViewer.setLabelProvider(new LabelProvider() { public Image
|
||||
* getImage(Object element) { return GiteaImages.LABEL; } });
|
||||
* prioritiesViewer.addSelectionChangedListener(new ISelectionChangedListener()
|
||||
* {
|
||||
*
|
||||
* @Override public void selectionChanged(SelectionChangedEvent event) {
|
||||
* setPageComplete(isPageComplete()); } }); --
|
||||
*/
|
||||
/*
|
||||
* -- TODO: filter labels by issue type issueTypesViewer =
|
||||
* CheckboxTableViewer.newCheckList(issuesArea, SWT.BORDER | SWT.V_SCROLL |
|
||||
* SWT.H_SCROLL);
|
||||
*
|
||||
* GridDataFactory.fillDefaults().grab(true, true).hint(100,
|
||||
* 80).applyTo(issueTypesViewer.getControl());
|
||||
* issueTypesViewer.setContentProvider(ArrayContentProvider.getInstance());
|
||||
* issueTypesViewer.setLabelProvider(new LabelProvider() { public Image
|
||||
* getImage(Object element) { return GiteaImages.LABEL; } });
|
||||
* issueTypesViewer.addSelectionChangedListener(new ISelectionChangedListener()
|
||||
* {
|
||||
*
|
||||
* @Override public void selectionChanged(SelectionChangedEvent event) {
|
||||
* setPageComplete(isPageComplete()); } }); --
|
||||
*/
|
||||
|
||||
public void applyTo(IRepositoryQuery query) {
|
||||
query.setSummary(titleText.getText());
|
||||
query.setAttribute("assignee", assigneeText.getText());
|
||||
query.setAttribute("milestone", milestoneCombo.getText());
|
||||
query.setAttribute("opened", "" + openButton.getSelection());
|
||||
query.setAttribute("closed", "" + closedButton.getSelection());
|
||||
Composite buttonsArea = new Composite(labelsArea, SWT.BORDER | SWT.NONE);
|
||||
GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonsArea);
|
||||
GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(true).applyTo(buttonsArea);
|
||||
|
||||
ArrayList<String> labels = new ArrayList<String>();
|
||||
final Button selectAllButton = new Button(buttonsArea, SWT.BORDER);
|
||||
selectAllButton.setText(Labels.QUERY_SELECT_ALL_BUTTON);
|
||||
GridDataFactory.fillDefaults().grab(true, false).applyTo(selectAllButton);
|
||||
|
||||
for (TableItem i : labelsViewer.getTable().getItems()) {
|
||||
labels.add(i.getText());
|
||||
}
|
||||
query.setAttribute("labels", StringUtils.join(labels, ","));
|
||||
}
|
||||
selectAllButton.addSelectionListener(new SelectionListener() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
labelsViewer.setAllChecked(true);
|
||||
refreshLabelsText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
}
|
||||
});
|
||||
|
||||
Button selectNoneButton = new Button(buttonsArea, SWT.BORDER);
|
||||
selectNoneButton.setText(Labels.QUERY_SELECT_NONE_BUTTON);
|
||||
GridDataFactory.fillDefaults().grab(true, false).applyTo(selectNoneButton);
|
||||
|
||||
selectNoneButton.addSelectionListener(new SelectionListener() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
labelsViewer.setAllChecked(false);
|
||||
refreshLabelsText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* newLabel.addFocusListener(new FocusListener() {
|
||||
*
|
||||
* @Override public void focusLost(FocusEvent e) {
|
||||
* getShell().setDefaultButton(null); setPageComplete(isPageComplete()); }
|
||||
*
|
||||
* @Override public void focusGained(FocusEvent e) {
|
||||
* getShell().setDefaultButton(btnAdd); } });
|
||||
* labelsViewer.getTable().addKeyListener(new KeyListener() {
|
||||
*
|
||||
* @Override public void keyReleased(KeyEvent e) { if (e.keyCode == SWT.DEL) {
|
||||
* removeSelection(); } }
|
||||
*
|
||||
* @Override public void keyPressed(KeyEvent e) { } });
|
||||
*/
|
||||
updateLabels();
|
||||
|
||||
}
|
||||
|
||||
private void createLeftColumnArea(Composite parent) {
|
||||
Composite leftArea = new Composite(parent, SWT.NONE);
|
||||
GridLayoutFactory.fillDefaults().numColumns(2).applyTo(leftArea);
|
||||
GridDataFactory.fillDefaults().grab(true, true).applyTo(leftArea);
|
||||
|
||||
createIssueStateArea(leftArea);
|
||||
createFilterByAssignedMembersArea(leftArea);
|
||||
|
||||
}
|
||||
|
||||
private void createRightColumnArea(Composite parent) {
|
||||
Composite rightArea = new Composite(parent, SWT.NONE);
|
||||
GridLayoutFactory.fillDefaults().numColumns(2).applyTo(rightArea);
|
||||
GridDataFactory.fillDefaults().grab(true, true).applyTo(rightArea);
|
||||
|
||||
createFilterByMilestoneArea(rightArea);
|
||||
createFilterByLabelsArea(rightArea);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Composite displayArea (2 columns based).
|
||||
* |---------------------------------------| |
|
||||
* <QueryTitleArea.....................> | | <LeftColumnArea> |
|
||||
* <RightColumnArea> | |---------------------------------------|
|
||||
*/
|
||||
public void createControl(Composite parent) {
|
||||
Composite displayArea = new Composite(parent, SWT.NONE);
|
||||
GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(true).applyTo(displayArea);
|
||||
GridDataFactory.fillDefaults().grab(true, true).applyTo(displayArea);
|
||||
|
||||
if (!inSearchContainer()) {
|
||||
createQueryTitleArea(displayArea);
|
||||
}
|
||||
|
||||
createLeftColumnArea(displayArea);
|
||||
|
||||
createRightColumnArea(displayArea);
|
||||
|
||||
initialize();
|
||||
setControl(displayArea);
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
IRepositoryQuery query = getQuery();
|
||||
if (query == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
titleText.setText(query.getSummary());
|
||||
// assigneeText.setText(query.getAttribute("assignee"));
|
||||
milestoneCombo.setText(query.getAttribute("milestone"));
|
||||
|
||||
openButton.setSelection(Boolean.parseBoolean(query.getAttribute("opened")));
|
||||
closedButton.setSelection(Boolean.parseBoolean(query.getAttribute("closed")));
|
||||
|
||||
try {
|
||||
updateAssigned();
|
||||
} catch (ApiException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
updateLabels();
|
||||
|
||||
/*
|
||||
* for (String label : query.getAttribute("labels").split(",")) { if
|
||||
* (label.trim().length() > 0) { labelsViewer.add(label.trim()); } }
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
public boolean isPageComplete() {
|
||||
boolean complete = inSearchContainer() ? true : super.isPageComplete();
|
||||
if (complete) {
|
||||
String message = null;
|
||||
if (!openButton.getSelection() && !closedButton.getSelection()) {
|
||||
message = "Select either closed, opened or both issue states";
|
||||
}
|
||||
|
||||
setErrorMessage(message);
|
||||
complete = message == null;
|
||||
}
|
||||
return complete;
|
||||
}
|
||||
|
||||
public String getQueryTitle() {
|
||||
return titleText != null ? titleText.getText() : null;
|
||||
}
|
||||
|
||||
public void applyTo(IRepositoryQuery query) {
|
||||
query.setSummary(titleText.getText());
|
||||
|
||||
query.setAttribute("assignee", labelsText.getText());
|
||||
|
||||
query.setAttribute("milestone", milestoneCombo.getText());
|
||||
query.setAttribute("opened", "" + openButton.getSelection());
|
||||
query.setAttribute("closed", "" + closedButton.getSelection());
|
||||
|
||||
ArrayList<String> labels = new ArrayList<String>();
|
||||
/*
|
||||
* TODO: filter labels by issue type or priorities {{{ for (Object o :
|
||||
* issueTypesViewer.getCheckedElements()) { labels.add(((String)o)); } for
|
||||
* (Object o : prioritiesViewer.getCheckedElements()) { labels.add(((String)o));
|
||||
* } }}}
|
||||
*/
|
||||
for (Object o : labelsViewer.getCheckedElements()) {
|
||||
labels.add(((String) o));
|
||||
}
|
||||
query.setAttribute("labels", StringUtils.join(labels, ","));
|
||||
}
|
||||
|
||||
private boolean updateLabels() {
|
||||
if (labelsViewer == null)
|
||||
return false;
|
||||
if (labelsViewer.getControl().isDisposed())
|
||||
return false;
|
||||
boolean hasLabels = false;
|
||||
GiteaConnection connection = ConnectionManager.getSafe(getTaskRepository());
|
||||
if (connection != null) {
|
||||
List<io.gitea.model.Label> labels = connection.getLabels();
|
||||
// Collections.sort(labels, Comparator.comparing(
|
||||
// io.gitea.model.Label::getName, String.CASE_INSENSITIVE_ORDER));
|
||||
hasLabels = !labels.isEmpty();
|
||||
List<String> allLabelsNames = new ArrayList<String>();
|
||||
|
||||
labels.forEach((label) -> allLabelsNames.add(label.getName()));
|
||||
labelsViewer.setInput(allLabelsNames);
|
||||
|
||||
/*
|
||||
* TODO: filter labels by issue types and priorities {{{ List<String>
|
||||
* issueTypesNames = IssueType.getAllIssueType(allLabelsNames); List<String>
|
||||
* prioritiesNames = GiteaPriorityLevel.getAllPriorityLabels(allLabelsNames);
|
||||
* List<String> otherLabelsNames = new ArrayList<String>();
|
||||
* allLabelsNames.forEach((label) -> { if ((!prioritiesNames.contains(label))
|
||||
* &&(!issueTypesNames.contains(label))) otherLabelsNames.add(label); });
|
||||
*
|
||||
* labelsViewer.setInput(otherLabelsNames);
|
||||
* prioritiesViewer.setInput(prioritiesNames);
|
||||
* issueTypesViewer.setInput(issueTypesNames); }}}
|
||||
*/
|
||||
|
||||
// When coming from existing query, update the dialog to reflect query ...
|
||||
IRepositoryQuery query = getQuery();
|
||||
if (query != null) {
|
||||
List<String> labelsInQuery = new ArrayList<String>();
|
||||
Arrays.asList(query.getAttribute("labels").split(",")).forEach((label) -> {
|
||||
if (label.trim().length() > 0)
|
||||
labelsInQuery.add(label.trim());
|
||||
});
|
||||
List<String> labelsToCheck = new ArrayList<String>();
|
||||
/*
|
||||
* TODO: filter labels by issue types and priority {{{ List<String>
|
||||
* priorityToCheck = new ArrayList<String>(); List<String> issueTypeToCheck =
|
||||
* new ArrayList<String>(); }}}
|
||||
*/
|
||||
List<String> labelToGreyed = new ArrayList<String>();
|
||||
labelsInQuery.forEach((label) -> {
|
||||
if (allLabelsNames.contains(label))
|
||||
labelsToCheck.add(label);
|
||||
/*
|
||||
* TODO: filter labels by issue types or priorities {{{ if
|
||||
* (prioritiesNames.contains(label)) priorityToCheck.add(label); else if
|
||||
* (otherLabelsNames.contains(label)) labelsToCheck.add(label); else
|
||||
* labelToGreyed.add(label); }}}
|
||||
*/
|
||||
});
|
||||
|
||||
labelsViewer.setCheckedElements(labelsToCheck.toArray());
|
||||
refreshLabelsText();
|
||||
/*
|
||||
* TODO: filter labels by issue types or priorities {{{
|
||||
* prioritiesViewer.setCheckedElements(labelsToCheck.toArray()); }}}
|
||||
*/
|
||||
|
||||
// labelsViewer.setGrayedElements(labelsToGreyed.toArray());
|
||||
}
|
||||
}
|
||||
|
||||
return hasLabels;
|
||||
}
|
||||
|
||||
private boolean updateMilestones() {
|
||||
if (milestoneCombo.isDisposed())
|
||||
return false;
|
||||
boolean hasMilestones = false;
|
||||
GiteaConnection connection = ConnectionManager.getSafe(getTaskRepository());
|
||||
if (connection != null) {
|
||||
List<Milestone> milestones = connection.getMilestones();
|
||||
hasMilestones = !milestones.isEmpty();
|
||||
milestoneCombo.removeAll();
|
||||
// Collections.sort(milestones, Comparator.comparing(
|
||||
// Milestone::getTitle, String.CASE_INSENSITIVE_ORDER));
|
||||
milestoneCombo.add("");
|
||||
for (Milestone s : milestones) {
|
||||
milestoneCombo.add(s.getTitle());
|
||||
}
|
||||
milestoneCombo.select(0);
|
||||
}
|
||||
return hasMilestones;
|
||||
}
|
||||
|
||||
private boolean updateAssigned() throws ApiException {
|
||||
boolean hasAssigned = false;
|
||||
if (labelsViewer == null)
|
||||
return false;
|
||||
if (labelsViewer.getControl().isDisposed())
|
||||
return false;
|
||||
|
||||
GiteaConnection connection = ConnectionManager.getSafe(getTaskRepository());
|
||||
if (connection != null) {
|
||||
IRepositoryQuery query = getQuery();
|
||||
List<String> usersNames = new ArrayList<String>();
|
||||
connection.repoListAllCollaborators().forEach((user) -> usersNames.add(GiteaUser.getName(user)));
|
||||
|
||||
List<String> assignedInQuery = new ArrayList<String>();
|
||||
Arrays.asList(query.getAttribute("assignee").split(",")).forEach((assignee) -> {
|
||||
if (assignee.trim().length() > 0)
|
||||
assignedInQuery.add(assignee.trim());
|
||||
});
|
||||
List<String> assignedList = new ArrayList<String>();
|
||||
usersNames.forEach((assignee) -> {
|
||||
if (assignedInQuery.contains(assignee))
|
||||
assignedList.add(assignee);
|
||||
});
|
||||
assignedViewer.setInput(usersNames);
|
||||
assignedViewer.setCheckedElements(assignedList.toArray());
|
||||
}
|
||||
return hasAssigned;
|
||||
}
|
||||
|
||||
private void refreshRepository() {
|
||||
try {
|
||||
ICoreRunnable runnable = new ICoreRunnable() {
|
||||
|
||||
@Override
|
||||
public void run(IProgressMonitor monitor) throws CoreException {
|
||||
Policy.monitorFor(monitor);
|
||||
monitor.beginTask("", 3); //$NON-NLS-1$
|
||||
GiteaConnection connection = ConnectionManager.getSafe(getTaskRepository());
|
||||
|
||||
monitor.setTaskName(Messages.MylynGiteaUIQueryPage_LoadingLabels);
|
||||
connection.refreshLabels();
|
||||
monitor.worked(1);
|
||||
|
||||
monitor.setTaskName(Messages.MylynGiteaUIQueryPage_LoadingMembers);
|
||||
connection.refreshMembers();
|
||||
monitor.worked(1);
|
||||
|
||||
monitor.setTaskName(Messages.MylynGiteaUIQueryPage_LoadingMilestones);
|
||||
connection.refreshMilestones();
|
||||
monitor.done();
|
||||
|
||||
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
updateLabels();
|
||||
updateMilestones();
|
||||
initialize();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
IRunnableContext context = getContainer();
|
||||
if (context == null)
|
||||
if (inSearchContainer())
|
||||
context = getSearchContainer().getRunnableContext();
|
||||
else
|
||||
context = PlatformUI.getWorkbench().getProgressService();
|
||||
CommonUiUtil.run(context, runnable);
|
||||
} catch (CoreException e) {
|
||||
IStatus status = e.getStatus();
|
||||
ErrorDialog.openError(getShell(), Messages.MylynGiteaUIQueryPage_ErrorLoading, e.getLocalizedMessage(),
|
||||
status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
23
io.gitea.mylyn.ui/src/io/gitea/mylyn/ui/Messages.java
Executable file
23
io.gitea.mylyn.ui/src/io/gitea/mylyn/ui/Messages.java
Executable file
@ -0,0 +1,23 @@
|
||||
// Copyright (c) 2021, Fr.Terrot. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package io.gitea.mylyn.ui;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
public class Messages extends NLS {
|
||||
private static final String BUNDLE_NAME = "io.gitea.mylyn.ui.messages"; //$NON-NLS-1$
|
||||
public static String MylynGiteaUIQueryPage_TooltipUpdateRepository;
|
||||
public static String MylynGiteaUIQueryPage_ErrorLoading;
|
||||
public static String MylynGiteaUIQueryPage_LoadingLabels;
|
||||
public static String MylynGiteaUIQueryPage_LoadingMilestones;
|
||||
public static String MylynGiteaUIQueryPage_LoadingMembers;
|
||||
static {
|
||||
// initialize resource bundle
|
||||
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
|
||||
}
|
||||
|
||||
private Messages() {
|
||||
}
|
||||
}
|
5
io.gitea.mylyn.ui/src/io/gitea/mylyn/ui/Messages.properties
Executable file
5
io.gitea.mylyn.ui/src/io/gitea/mylyn/ui/Messages.properties
Executable file
@ -0,0 +1,5 @@
|
||||
MylynGiteaUIQueryPage_TooltipUpdateRepository=Update milestones, labels and team members
|
||||
MylynGiteaUIQueryPage_ErrorLoading=Error loading labels and milestones
|
||||
MylynGiteaUIQueryPage_TaskLoadingLabels=Loading labels...
|
||||
MylynGiteaUIQueryPage_TaskLoadingMilestones=Loading Milestones...
|
||||
MylynGiteaUIQueryPage_TaskLoadingMembers=Loading team members...
|
Loading…
Reference in New Issue
Block a user