use of org.eclipse.mylyn.tasks.core.data.TaskAttribute in project linuxtools by eclipse.
the class OSIORestClient method postTaskData.
public RepositoryResponse postTaskData(TaskData taskData, Set<TaskAttribute> oldAttributes, TaskRepository repository, IOperationMonitor monitor) throws OSIORestException {
Space space = null;
if (taskData.isNew()) {
TaskAttribute spaceAttribute = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().SPACE.getKey());
Map<String, Space> spaces = getCachedSpaces(new NullOperationMonitor());
space = spaces.get(spaceAttribute.getValue());
String id = null;
try {
id = restRequestProvider.postNewTask(monitor, client, taskData, space, connector, repository);
} catch (CoreException e1) {
throw new OSIORestException(e1);
}
return new RepositoryResponse(ResponseKind.TASK_CREATED, id);
} else {
TaskAttribute spaceIdAttribute = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().SPACE_ID.getKey());
String spaceId = spaceIdAttribute.getValue();
try {
space = getSpaceById(spaceId, repository);
} catch (CoreException e1) {
throw new OSIORestException(e1);
}
TaskAttribute newComment = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().NEW_COMMENT.getKey());
if (newComment != null) {
String value = newComment.getValue();
if (value != null && !value.isEmpty()) {
restRequestProvider.postNewCommentTask(monitor, client, taskData, oldAttributes);
newComment.setValue("");
}
}
TaskAttribute removeLinks = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().REMOVE_LINKS.getKey());
if (removeLinks != null) {
List<String> links = removeLinks.getValues();
TaskAttributeMetaData metadata = removeLinks.getMetaData();
TaskAttribute widAttr = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().UUID.getKey());
String wid = widAttr.getValue();
for (String link : links) {
try {
String id = metadata.getValue(link);
restRequestProvider.deleteLink(monitor, client, wid, id);
} catch (Exception e) {
StatusHandler.log(new Status(IStatus.ERROR, OSIORestCore.ID_PLUGIN, // $NON-NLS-1$
NLS.bind(// $NON-NLS-1$
"Unexpected error during deletion of work item link: <{0}>", link), e));
}
}
}
TaskAttribute addLink = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().ADD_LINK.getKey());
TaskAttributeMetaData metadata = addLink.getMetaData();
// $NON-NLS-1$
String linkid = metadata.getValue("linkid");
String sourceid = taskData.getRoot().getAttribute(OSIORestTaskSchema.getDefault().UUID.getKey()).getValue();
// $NON-NLS-1$
String targetid = metadata.getValue("targetWid");
// $NON-NLS-1$
String direction = metadata.getValue("direction");
boolean isForward = true;
if (direction != null && !direction.isEmpty()) {
// $NON-NLS-1$
isForward = direction.equals("forward");
}
if (linkid != null && targetid != null) {
restRequestProvider.postNewLink(monitor, client, linkid, sourceid, targetid, isForward);
}
restRequestProvider.patchUpdateTask(monitor, client, taskData, oldAttributes, space);
return new RepositoryResponse(ResponseKind.TASK_UPDATED, taskData.getTaskId());
}
}
use of org.eclipse.mylyn.tasks.core.data.TaskAttribute in project linuxtools by eclipse.
the class RepositoryQuerySchemaPage method createFieldControls.
private void createFieldControls(Composite attributesComposite, FormToolkit toolkit, int columnCount, TaskAttribute target) {
int currentColumn = 1;
int currentPriority = 0;
int currentLayoutPriority = 0;
for (Field field : schema.getFields()) {
TaskAttribute dataAttribute = target.getAttribute(field.getKey());
AbstractAttributeEditor attributeEditor = factory.createEditor(field.getType(), dataAttribute);
editorMap.put(dataAttribute.getId(), attributeEditor);
String layoutPriorityString = dataAttribute.getMetaData().getValue("LayoutPriority");
int layoutPriority = layoutPriorityString == null ? -1 : Integer.parseInt(layoutPriorityString);
int priority = (attributeEditor.getLayoutHint() != null) ? attributeEditor.getLayoutHint().getPriority() : LayoutHint.DEFAULT_PRIORITY;
// TODO: copied from AbstractTaskEditorAttributeSection.createAttributeControls (only layoutPriority is new)
if (priority != currentPriority || currentLayoutPriority != layoutPriority) {
currentPriority = priority;
currentLayoutPriority = layoutPriority;
if (currentColumn > 1) {
while (currentColumn <= columnCount) {
// $NON-NLS-1$
Label l = toolkit.createLabel(attributesComposite, "");
GridData gd = GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).hint(0, SWT.DEFAULT).create();
l.setLayoutData(gd);
currentColumn++;
}
currentColumn = 1;
}
}
if (attributeEditor.hasLabel()) {
attributeEditor.createLabelControl(attributesComposite, toolkit);
Label label = attributeEditor.getLabelControl();
label.setBackground(attributesComposite.getBackground());
label.setForeground(attributesComposite.getForeground());
String text = label.getText();
String shortenText = TaskDiffUtil.shortenText(label, text, LABEL_WIDTH);
label.setText(shortenText);
if (!text.equals(shortenText)) {
label.setToolTipText(text);
}
GridData gd = GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).grab(true, true).hint(LABEL_WIDTH, SWT.DEFAULT).create();
if (currentColumn > 1) {
gd.horizontalIndent = COLUMN_GAP;
gd.widthHint = LABEL_WIDTH + COLUMN_GAP;
}
label.setLayoutData(gd);
currentColumn++;
}
attributeEditor.createControl(attributesComposite, toolkit);
attributeEditor.getControl().setBackground(attributesComposite.getParent().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
attributeEditor.getControl().setForeground(attributesComposite.getForeground());
LayoutHint layoutHint = attributeEditor.getLayoutHint();
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
RowSpan rowSpan = (layoutHint != null && layoutHint.rowSpan != null) ? layoutHint.rowSpan : RowSpan.SINGLE;
ColumnSpan columnSpan = (layoutHint != null && layoutHint.columnSpan != null) ? layoutHint.columnSpan : ColumnSpan.SINGLE;
// prevent clipping of decorators on Windows
gd.horizontalIndent = 1;
if (rowSpan == RowSpan.SINGLE && columnSpan == ColumnSpan.SINGLE) {
gd.widthHint = COLUMN_WIDTH;
gd.horizontalSpan = 1;
} else {
if (rowSpan == RowSpan.MULTIPLE) {
gd.heightHint = MULTI_ROW_HEIGHT;
}
if (columnSpan == ColumnSpan.SINGLE) {
gd.widthHint = COLUMN_WIDTH;
gd.horizontalSpan = 1;
} else {
gd.widthHint = MULTI_COLUMN_WIDTH;
gd.horizontalSpan = columnCount - currentColumn + 1;
}
}
attributeEditor.getControl().setLayoutData(gd);
currentColumn += gd.horizontalSpan;
currentColumn %= columnCount;
}
}
use of org.eclipse.mylyn.tasks.core.data.TaskAttribute in project linuxtools by eclipse.
the class RepositoryQuerySchemaPage method createPageContent.
@Override
protected void createPageContent(@NonNull SectionComposite parent) {
this.scrolledComposite = parent;
Composite scrolledBodyComposite = scrolledComposite.getContent();
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 10;
layout.horizontalSpacing = 0;
layout.verticalSpacing = 10;
scrolledBodyComposite.setLayout(layout);
Composite attributesComposite = new Composite(scrolledBodyComposite, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).span(2, 1).applyTo(attributesComposite);
layout = new GridLayout(6, false);
layout.marginHeight = 20;
layout.marginWidth = 10;
attributesComposite.setLayout(layout);
GridData g = new GridData(GridData.FILL, GridData.FILL, true, true);
g.widthHint = 600;
attributesComposite.setLayoutData(g);
attributesComposite.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
FormToolkit toolkit = new FormToolkit(parent.getDisplay());
TaskRepository repository = getTaskRepository();
ITask nTask = new TaskTask(repository.getConnectorKind(), repository.getRepositoryUrl(), data.getTaskId());
ITaskDataWorkingCopy workingCopy = TasksUi.getTaskDataManager().createWorkingCopy(nTask, data);
final TaskDataModel model = new TaskDataModel(repository, nTask, workingCopy);
factory = new RepositoryQueryAttributeEditorFactory(model, repository);
model.addModelListener(new TaskDataModelListener() {
@Override
public void attributeChanged(TaskDataModelEvent event) {
getContainer().updateButtons();
}
});
targetTaskData = workingCopy.getLocalData();
final TaskAttribute target = targetTaskData.getRoot();
createFieldControls(attributesComposite, toolkit, layout.numColumns, target);
Point p = scrolledBodyComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
scrolledComposite.setMinSize(p);
}
use of org.eclipse.mylyn.tasks.core.data.TaskAttribute in project linuxtools by eclipse.
the class OSIORestConfiguration method addValidOperations.
public void addValidOperations(TaskData workItem) {
TaskAttribute attributeStatus = workItem.getRoot().getMappedAttribute(TaskAttribute.STATUS);
String attributeStatusValue = attributeStatus.getValue();
TaskAttribute operationAttribute = workItem.getRoot().getAttribute(TaskAttribute.OPERATION);
if (operationAttribute == null) {
operationAttribute = workItem.getRoot().createAttribute(TaskAttribute.OPERATION);
}
TaskAttribute attribute = workItem.getRoot().createAttribute(TaskAttribute.PREFIX_OPERATION + attributeStatusValue);
TaskOperation.applyTo(attribute, attributeStatusValue, // $NON-NLS-1$
OSIORestMessages.getFormattedString("KeepStateOperation", attributeStatusValue));
// set as default
TaskOperation.applyTo(operationAttribute, attributeStatusValue, // $NON-NLS-1$
OSIORestMessages.getFormattedString("KeepStateOperation", attributeStatusValue));
for (String statusValue : statusValues) {
if (attributeStatusValue == null || (attributeStatusValue != null && attributeStatusValue.equals(statusValue))) {
if (attributeStatusValue == null) {
// $NON-NLS-1$
attributeStatusValue = "";
}
for (String transition : statusTransitions.get(statusValue)) {
attribute = workItem.getRoot().createAttribute(TaskAttribute.PREFIX_OPERATION + transition);
TaskOperation.applyTo(attribute, transition, // $NON-NLS-1$
OSIORestMessages.getFormattedString("StateChangeOperation", transition));
}
}
}
}
use of org.eclipse.mylyn.tasks.core.data.TaskAttribute in project linuxtools by eclipse.
the class OSIORestConfiguration method setSpaceOptions.
public boolean setSpaceOptions(@NonNull TaskData taskData, @NonNull Map<String, Space> spaces) {
TaskAttribute attributeSpace = taskData.getRoot().getMappedAttribute(SCHEMA.SPACE.getKey());
if (attributeSpace != null) {
SortedSet<String> spaceSet = new TreeSet<String>();
for (String key : spaces.keySet()) {
spaceSet.add(key);
}
attributeSpace.clearOptions();
for (String SpaceName : spaceSet) {
attributeSpace.putOption(SpaceName, SpaceName);
}
return true;
}
return false;
}
Aggregations