Search in sources :

Example 16 with TaskAttribute

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());
    }
}
Also used : Space(org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) CoreException(org.eclipse.core.runtime.CoreException) RepositoryResponse(org.eclipse.mylyn.tasks.core.RepositoryResponse) TaskAttributeMetaData(org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData) CoreException(org.eclipse.core.runtime.CoreException)

Example 17 with TaskAttribute

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;
    }
}
Also used : Field(org.eclipse.linuxtools.internal.mylyn.osio.rest.ui.provisional.AbstractQueryPageSchema.Field) TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) ColumnSpan(org.eclipse.mylyn.tasks.ui.editors.LayoutHint.ColumnSpan) AbstractAttributeEditor(org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) LayoutHint(org.eclipse.mylyn.tasks.ui.editors.LayoutHint) RowSpan(org.eclipse.mylyn.tasks.ui.editors.LayoutHint.RowSpan) Point(org.eclipse.swt.graphics.Point) LayoutHint(org.eclipse.mylyn.tasks.ui.editors.LayoutHint)

Example 18 with TaskAttribute

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);
}
Also used : TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) ITask(org.eclipse.mylyn.tasks.core.ITask) SectionComposite(org.eclipse.mylyn.commons.workbench.forms.SectionComposite) Composite(org.eclipse.swt.widgets.Composite) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) TaskRepository(org.eclipse.mylyn.tasks.core.TaskRepository) TaskDataModelEvent(org.eclipse.mylyn.tasks.core.data.TaskDataModelEvent) Point(org.eclipse.swt.graphics.Point) TaskTask(org.eclipse.mylyn.internal.tasks.core.TaskTask) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) TaskDataModelListener(org.eclipse.mylyn.tasks.core.data.TaskDataModelListener) ITaskDataWorkingCopy(org.eclipse.mylyn.tasks.core.data.ITaskDataWorkingCopy) TaskDataModel(org.eclipse.mylyn.tasks.core.data.TaskDataModel)

Example 19 with TaskAttribute

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));
            }
        }
    }
}
Also used : TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute)

Example 20 with TaskAttribute

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;
}
Also used : TaskAttribute(org.eclipse.mylyn.tasks.core.data.TaskAttribute) TreeSet(java.util.TreeSet)

Aggregations

TaskAttribute (org.eclipse.mylyn.tasks.core.data.TaskAttribute)36 OSIORestClient (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestClient)13 TaskData (org.eclipse.mylyn.tasks.core.data.TaskData)13 TestData (org.eclipse.linuxtools.mylyn.osio.rest.test.support.TestData)12 Test (org.junit.Test)12 AbstractTaskDataHandler (org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler)11 TaskAttributeMapper (org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper)11 NullOperationMonitor (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.NullOperationMonitor)10 OSIORestConfiguration (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestConfiguration)10 RepositoryLocation (org.eclipse.mylyn.commons.repositories.core.RepositoryLocation)10 FileReader (java.io.FileReader)7 OSIORestTaskSchema (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestTaskSchema)5 TaskAttributeMetaData (org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData)5 JsonWriter (com.google.gson.stream.JsonWriter)3 StringWriter (java.io.StringWriter)3 ArrayList (java.util.ArrayList)3 LinkedHashSet (java.util.LinkedHashSet)3 TreeSet (java.util.TreeSet)3 Space (org.eclipse.linuxtools.internal.mylyn.osio.rest.core.response.data.Space)3 TaskCommentMapper (org.eclipse.mylyn.tasks.core.data.TaskCommentMapper)3