Merge branch 'master' into spi

6.19.x
Artem Zatsarynnyi 2017-07-24 09:47:06 +03:00
commit 5fda7b42f0
45 changed files with 683 additions and 233 deletions

View File

@ -42,6 +42,8 @@ import java.util.Map;
import java.util.ServiceLoader;
import java.util.concurrent.ConcurrentHashMap;
import static java.lang.String.format;
/**
* Provides implementations of DTO interfaces.
*
@ -386,11 +388,41 @@ public final class DtoFactory {
private <T> DtoProvider<T> getDtoProvider(Class<T> dtoInterface) {
DtoProvider<?> dtoProvider = dtoInterface2Providers.get(dtoInterface);
if (dtoProvider == null) {
throw new IllegalArgumentException("Unknown DTO type " + dtoInterface);
if (!dtoInterface.isInterface()) {
throw new IllegalArgumentException(format("Only interfaces can be DTO, but %s is not", dtoInterface));
}
if (hasDtoAnnotation(dtoInterface)) {
throw new IllegalArgumentException(format("Provider of implementation for DTO type %s isn't found", dtoInterface));
} else {
throw new IllegalArgumentException(dtoInterface + " is not a DTO type");
}
}
return (DtoProvider<T>)dtoProvider;
}
/**
* Checks if dtoInterface or its parent have DTO annotation.
*
* @param dtoInterface
* DTO interface
* @return true if only dtoInterface or one of its parent have DTO annotation.
*/
private boolean hasDtoAnnotation(Class dtoInterface) {
if (dtoInterface.isAnnotationPresent(DTO.class)) {
return true;
}
for (Class parent: dtoInterface.getInterfaces()) {
if (hasDtoAnnotation(parent)) {
return true;
}
}
return false;
}
/**
* Registers DtoProvider for DTO interface.
*

View File

@ -19,11 +19,11 @@ import com.google.gson.JsonPrimitive;
import org.eclipse.che.dto.definitions.ComplicatedDto;
import org.eclipse.che.dto.definitions.DTOHierarchy;
import org.eclipse.che.dto.definitions.DTOHierarchy.GrandchildDto;
import org.eclipse.che.dto.definitions.DtoWithAny;
import org.eclipse.che.dto.definitions.DtoWithDelegate;
import org.eclipse.che.dto.definitions.DtoWithFieldNames;
import org.eclipse.che.dto.definitions.SimpleDto;
import org.eclipse.che.dto.definitions.DTOHierarchy.GrandchildDto;
import org.eclipse.che.dto.definitions.model.Model;
import org.eclipse.che.dto.definitions.model.ModelComponentDto;
import org.eclipse.che.dto.definitions.model.ModelDto;
@ -108,7 +108,7 @@ public class ServerDtoTest {
}
@Test
public void testDeerializerWithFieldNames() throws Exception {
public void testDeserializerWithFieldNames() throws Exception {
final String fooString = "Something";
final String _default = "test_default_keyword";
@ -380,4 +380,16 @@ public class ServerDtoTest {
assertEquals(childDto.getChildField(), "child-field");
assertEquals(childDto.getParentField(), "parent-field");
}
@Test(expectedExceptions = IllegalArgumentException.class,
expectedExceptionsMessageRegExp = "Only interfaces can be DTO, but class java.lang.String is not")
public void shouldThrowExceptionWhenThereIsClassType() {
DtoFactory.newDto(String.class);
}
@Test(expectedExceptions = IllegalArgumentException.class,
expectedExceptionsMessageRegExp = "interface org.eclipse.che.dto.definitions.DTOHierarchy\\$GrandchildWithoutDto is not a DTO type")
public void shouldThrowExceptionWhenInterfaceIsNotAnnotatedAsDto() {
DtoFactory.newDto(DTOHierarchy.GrandchildWithoutDto.class);
}
}

View File

@ -13,6 +13,8 @@ package org.eclipse.che.dto.definitions;
import org.eclipse.che.dto.shared.DTO;
import java.io.Closeable;
/**
* Keeps DTO interfaces for hierarchy test
*
@ -60,4 +62,10 @@ public final class DTOHierarchy {
void setShadowedField(GrandchildDto v);
}
public interface Child2 extends Parent {
String getChild2Field();
}
public interface GrandchildWithoutDto extends Child, Child2 {
}
}

View File

@ -43,9 +43,9 @@ export class ProjectSourceSelectorController {
*/
private selectedSource: ProjectSource;
/**
* button's values by Id.
* State of a button.
*/
private buttonValues: { [butonId: string]: boolean } = {};
private buttonState: { [buttonId: string]: boolean } = {};
/**
* Selected button's type.
*/
@ -142,13 +142,13 @@ export class ProjectSourceSelectorController {
*/
updateData({buttonState, buttonType, template = null}: { buttonState: boolean, buttonType: ButtonType, template?: che.IProjectTemplate }): void {
const buttonValue = template
const buttonId = template
? template.name
: ButtonType[ButtonType.ADD_PROJECT];
// leave only one selected button
this.buttonValues = {
[buttonValue]: true
this.buttonState = {
[buttonId]: true
};
if (!buttonState) {

View File

@ -8,14 +8,13 @@
che-font-icon="material-design icon-ic_add_24px"
che-on-change="projectSourceSelectorController.updateData({buttonState: state, buttonType: projectSourceSelectorController.buttonType.ADD_PROJECT})"
ng-init="projectSourceSelectorController.selectedButtonType = projectSourceSelectorController.buttonType.ADD_PROJECT"
che-value="projectSourceSelectorController.buttonValues['ADD_PROJECT']"></toggle-single-button>
che-state="projectSourceSelectorController.buttonState['ADD_PROJECT']"></toggle-single-button>
<toggle-single-button class="project-metadata"
ng-repeat="projectTemplate in projectSourceSelectorController.projectTemplates"
che-title="{{projectTemplate.name}}"
che-state="false"
che-font-icon="chefont cheico-project"
che-on-change="projectSourceSelectorController.updateData({buttonState: state, buttonType: projectSourceSelectorController.buttonType.PROJECT_TEMPLATE, template: projectTemplate})"
che-value="projectSourceSelectorController.buttonValues[projectTemplate.name]"
che-state="projectSourceSelectorController.buttonState[projectTemplate.name]"
uib-tooltip="{{projectTemplate.name}}"></toggle-single-button>
</div>

View File

@ -48,7 +48,7 @@ export class CheStackLibraryFilter implements ng.IDirective {
};
// select suggestion by keys
$element.bind('keypress keydown', (event: any) => {
$element.on('keypress keydown', (event: any) => {
if (event.which === 38) {
// on press 'up'
// select prev suggestion
@ -71,5 +71,15 @@ export class CheStackLibraryFilter implements ng.IDirective {
ctrl.selectSuggestion(ctrl.selectedIndex);
}
});
// select suggestion by mouse click
$element.on('click', 'md-chip', (event: any) => {
const suggestions = ctrl.suggestions.map((suggestion: string) => {
return suggestion.toLowerCase();
});
const suggestionText = angular.element(event.currentTarget).find('.stack-library-filter-suggestion-text').text().toLowerCase();
ctrl.selectedIndex = suggestions.indexOf(suggestionText);
ctrl.selectSuggestion(ctrl.selectedIndex);
});
}
}

View File

@ -35,8 +35,10 @@
class="stack-library-filter-suggestions"
readonly="true">
<md-chip-template>
<div class="stack-library-filter-suggestion-text">{{$chip | uppercase}}</div>
<div class="stack-library-filter-suggestion-btn" ng-click="cheStackLibraryFilterCtrl.onSelectSuggestion($chip)">
<div class="stack-library-filter-suggestion-text"
ng-dblclick="cheStackLibraryFilterCtrl.onSelectSuggestion($chip)">{{$chip | uppercase}}</div>
<div class="stack-library-filter-suggestion-btn"
ng-click="cheStackLibraryFilterCtrl.onSelectSuggestion($chip)">
<i class="fa fa-plus"></i>
</div>
</md-chip-template>

View File

@ -27,7 +27,9 @@
layout="row"
layout-align="start center" layout-align-gt-md="end center">
<toggle-button-popover button-title="Filters"
button-font-icon="fa fa-sliders">
button-font-icon="fa fa-sliders"
che-popover-trigger-outside-click="true"
ng-class="{'stack-selector-active-tags-filter': stackSelectorController.selectedTags.length}">
<che-stack-library-filter stack-tags="stackSelectorController.allStackTags"
selected-tags="stackSelectorController.selectedTags"
on-tags-changes="stackSelectorController.onTagsChanges(tags)">

View File

@ -2,6 +2,9 @@
$stack-selector-list-header-border = lighten($very-light-grey-color, 4%)
$stack-selector-list-header-background = lighten($very-light-grey-color, 28%)
& *
outline none
.stack-selector-buttons-right
& > *
margin 0
@ -19,6 +22,9 @@
md-icon
font-size 28px
toggle-button-popover.stack-selector-active-tags-filter toggle-single-button md-icon
color $primary-color !important
.stack-selector-list
background-color $stack-selector-list-header-background
border-top 1px solid $stack-selector-list-header-border

View File

@ -16,7 +16,7 @@ interface ITestScope extends ng.IRootScopeService {
}
/**
* Test of the WorkspaceRecipeImport
* Test of the CheToggleButtonPopover directive.
* @author Oleksii Kurinnyi
*/
describe('CheToggleButtonPopover >', () => {
@ -50,10 +50,9 @@ describe('CheToggleButtonPopover >', () => {
httpBackend.when('OPTIONS', '/api/').respond({});
$rootScope.model = {
popoverButtonTitle: 'Popover Button Title',
initialState: false,
value: false,
popoverContent: 'Simple popover content',
title: 'Popover Button Title',
state: false,
content: 'Simple popover content',
onChange: (state: boolean) => {
/* tslint:disable */
const newState = state;
@ -63,14 +62,17 @@ describe('CheToggleButtonPopover >', () => {
}));
afterEach(() => {
$timeout.verifyNoPendingTasks();
});
function getCompiledElement() {
const element = $compile(angular.element(
`<div><toggle-button-popover button-title="model.popoverButtonTitle"
button-state="model.initialState"
button-value="model.value"
`<div><toggle-button-popover button-title="model.title"
button-state="model.state"
button-on-change="model.onChange(state)"
che-popover-placement="right-top">
<div>{{model.popoverContent}}</div>
<div>{{model.content}}</div>
</toggle-button-popover></div>`
))($rootScope);
$rootScope.$digest();
@ -87,10 +89,16 @@ describe('CheToggleButtonPopover >', () => {
});
it('should have content hidden', () => {
expect(compiledDirective.html()).not.toContain($rootScope.model.popoverContent);
// timeout should be flashed
$timeout.flush();
expect(compiledDirective.html()).not.toContain($rootScope.model.content);
});
it('should have button disabled', () => {
// timeout should be flashed
$timeout.flush();
expect(toggleSingleButton.get(0)).toBeTruthy();
expect(toggleSingleButton.hasClass('toggle-single-button-disabled')).toBeTruthy();
});
@ -106,7 +114,7 @@ describe('CheToggleButtonPopover >', () => {
// timeout should be flashed to get callback called and content visible
$timeout.flush();
expect(compiledDirective.html()).toContain($rootScope.model.popoverContent);
expect(compiledDirective.html()).toContain($rootScope.model.content);
});
it('should enable button', () => {
@ -127,10 +135,10 @@ describe('CheToggleButtonPopover >', () => {
});
describe(`change value of button-value attribute >`, () => {
describe(`change state of toggle button from outside of directive >`, () => {
beforeEach(() => {
$rootScope.model.value = true;
$rootScope.model.state = true;
$rootScope.$digest();
});
@ -138,7 +146,7 @@ describe('CheToggleButtonPopover >', () => {
// timeout should be flashed to get callback called and content visible
$timeout.flush();
expect(compiledDirective.html()).toContain($rootScope.model.popoverContent);
expect(compiledDirective.html()).toContain($rootScope.model.content);
});
it('should enable button', () => {
@ -167,7 +175,7 @@ describe('CheToggleButtonPopover >', () => {
let toggleSingleButton;
beforeEach(() => {
$rootScope.model.initialState = true;
$rootScope.model.state = true;
compiledDirective = getCompiledElement();
toggleSingleButton = compiledDirective.find('button');
@ -176,7 +184,7 @@ describe('CheToggleButtonPopover >', () => {
});
it('should have content visible', () => {
expect(compiledDirective.html()).toContain($rootScope.model.popoverContent);
expect(compiledDirective.html()).toContain($rootScope.model.content);
});
it('should have button enabled', () => {
@ -184,7 +192,6 @@ describe('CheToggleButtonPopover >', () => {
expect(toggleSingleButton.hasClass('toggle-single-button-disabled')).toBeFalsy();
});
describe('click on button >', () => {
beforeEach(() => {
@ -193,14 +200,16 @@ describe('CheToggleButtonPopover >', () => {
});
it('should make content hidden', () => {
// timeout should be flashed to get callback called and content visible
// timeout should be flashed to get callback called and content hidden
$timeout.flush();
$timeout.flush();
expect(compiledDirective.html()).not.toContain($rootScope.model.popoverContent);
expect(compiledDirective.html()).not.toContain($rootScope.model.content);
});
it('should disable button', () => {
// timeout should be flashed to get callback called and content visible
// timeout should be flashed to get callback called and content hidden
$timeout.flush();
$timeout.flush();
expect(toggleSingleButton.hasClass('toggle-single-button-disabled')).toBeTruthy();
@ -209,7 +218,8 @@ describe('CheToggleButtonPopover >', () => {
it('should call the callback', () => {
spyOn($rootScope.model, 'onChange');
// timeout should be flashed to get callback called and content visible
// timeout should be flashed to get callback called and content hidden
$timeout.flush();
$timeout.flush();
expect($rootScope.model.onChange).toHaveBeenCalledWith(false);
@ -217,23 +227,24 @@ describe('CheToggleButtonPopover >', () => {
});
describe(`change value of button-value attribute >`, () => {
describe(`change state of toggle button from outside of directive >`, () => {
beforeEach(() => {
$rootScope.model.value = false;
$rootScope.model.state = false;
$rootScope.$digest();
});
it('should make content hidden', () => {
// timeout should be flashed to get callback called and content visible
// timeout should be flashed to get callback called and content hidden
$timeout.flush();
$timeout.flush();
expect(compiledDirective.html()).not.toContain($rootScope.model.popoverContent);
expect(compiledDirective.html()).not.toContain($rootScope.model.content);
});
it('should disable button', () => {
// timeout should be flashed to get callback called and content visible
// timeout should be flashed to get callback called and content hidden
$timeout.flush();
$timeout.flush();
expect(toggleSingleButton.hasClass('toggle-single-button-disabled')).toBeTruthy();
@ -242,7 +253,8 @@ describe('CheToggleButtonPopover >', () => {
it('should call the callback', () => {
spyOn($rootScope.model, 'onChange');
// timeout should be flashed to get callback called and content visible
// timeout should be flashed to get callback called and content hidden
$timeout.flush();
$timeout.flush();
expect($rootScope.model.onChange).toHaveBeenCalledWith(false);

View File

@ -10,22 +10,13 @@
*/
'use strict';
interface IPopoverAttrs extends ng.IAttributes {
buttonTitle: string;
buttonFontIcon: string;
buttonOnChange: string;
buttonState?: string;
buttonValue?: boolean;
chePopoverTitle?: string;
chePopoverPlacement?: string;
}
interface IPopoverScope extends ng.IScope {
onChange: Function;
isOpenPopover: boolean;
buttonInitState?: boolean;
buttonState?: boolean;
buttonOnChange?: Function;
buttonOnReset?: Function;
chePopoverTriggerOutsideClick?: boolean;
}
/**
@ -40,14 +31,14 @@ interface IPopoverScope extends ng.IScope {
*
* @param {string} button-title button's title
* @param {string} button-font-icon button's icon CSS class
* @param {expression=} button-state expression which defines initial state of button.
* @param {expression=} button-state expression which defines state of button.
* @param {Function} button-on-change callback on model change
* @param {boolean} button-value button's state
* @param {string=} che-popover-title popover's title
* @param {string=} che-popover-placement popover's placement
* @param {expression=} che-popover-close-outside-click if <code>true</close> then click outside of popover will close the it
* @usage
* <toggle-button-popover button-title="Filter"
* button-state="ctrl.filterInitState"
* button-state="ctrl.filterState"
* button-on-change="ctrl.filterStateOnChange(state)"><div>My popover</div></toggle-button-popover>
*
* @author Oleksii Orel
@ -59,10 +50,10 @@ export class CheToggleButtonPopover implements ng.IDirective {
buttonTitle: '@',
buttonFontIcon: '@',
buttonOnChange: '&?buttonOnChange',
buttonInitState: '=?buttonState',
buttonValue: '=?',
buttonState: '=?buttonState',
chePopoverTitle: '@?',
chePopoverPlacement: '@?'
chePopoverPlacement: '@?',
chePopoverTriggerOutsideClick: '=?'
};
private $timeout: ng.ITimeoutService;
@ -83,15 +74,15 @@ export class CheToggleButtonPopover implements ng.IDirective {
return `<toggle-single-button che-title="{{buttonTitle}}"
che-font-icon="{{buttonFontIcon}}"
che-on-change="onChange(state)"
che-state="buttonInitState ? buttonInitState : false"
che-value="buttonValue"
che-state="buttonState"
popover-title="{{chePopoverTitle ? chePopoverTitle : ''}}"
popover-placement="{{chePopoverPlacement ? chePopoverPlacement : 'bottom'}}"
popover-is-open="isOpenPopover"
popover-trigger="{{chePopoverTriggerOutsideClick ? 'outsideClick' : 'none'}}"
uib-popover-html="'<div class=\\'che-transclude\\'></div>'"></toggle-single-button>`;
}
link($scope: IPopoverScope, $element: ng.IAugmentedJQuery, $attrs: IPopoverAttrs, ctrl: any, $transclude: ng.ITranscludeFunction): void {
link($scope: IPopoverScope, $element: ng.IAugmentedJQuery, $attrs: ng.IAttributes, ctrl: any, $transclude: ng.ITranscludeFunction): void {
$scope.onChange = (state: boolean) => {
this.$timeout(() => {
@ -109,5 +100,32 @@ export class CheToggleButtonPopover implements ng.IDirective {
});
};
if (!$scope.buttonState) {
$scope.buttonState = false;
}
$scope.onChange($scope.buttonState);
// close popover on Esc is pressed
$element.attr('tabindex', 0);
$element.on('keypress keydown', (event: any) => {
if (event.which === 27) {
// on press 'esc'
$scope.$apply(() => {
$scope.buttonState = false;
});
}
});
if ($scope.chePopoverTriggerOutsideClick) {
// update toggle single button state after popover is closed by outside click
const watcher = $scope.$watch(() => { return $scope.isOpenPopover; }, (newVal: boolean) => {
$scope.buttonState = newVal;
});
$scope.$on('$destroy', () => {
watcher();
});
}
}
}

View File

@ -0,0 +1,209 @@
/*
* Copyright (c) 2015-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*/
import {CheHttpBackend} from '../../api/test/che-http-backend';
interface ITestScope extends ng.IRootScopeService {
model?: any;
}
/**
* Test of the ToggleSingleButton directive.
* @author Oleksii Kurinnyi
*/
describe('ToggleSingleButton >', () => {
let $rootScope: ITestScope,
$timeout: ng.ITimeoutService,
$compile: ng.ICompileService,
compiledDirective: ng.IAugmentedJQuery;
/**
* Backend for handling http operations
*/
let httpBackend: ng.IHttpBackendService;
/**
* setup module
*/
beforeEach(angular.mock.module('userDashboard'));
beforeEach(inject((_$timeout_: ng.ITimeoutService,
_$compile_: ng.ICompileService,
_$rootScope_: ng.IRootScopeService,
cheHttpBackend: CheHttpBackend) => {
$rootScope = _$rootScope_.$new();
$timeout = _$timeout_;
$compile = _$compile_;
httpBackend = cheHttpBackend.getHttpBackend();
// avoid tracking requests from branding controller
httpBackend.whenGET(/.*/).respond(200, '');
httpBackend.when('OPTIONS', '/api/').respond({});
$rootScope.model = {
title: 'Toggle Single Button Title',
state: false,
onChange: (state: boolean) => {
/* tslint:disable */
const newState = state;
/* tslint:enable */
}
};
}));
afterEach(() => {
$timeout.verifyNoPendingTasks();
});
function getCompiledElement() {
const element = $compile(angular.element(
`<div><toggle-single-button che-title="{{model.title}}"
che-state="model.state"
che-on-change="model.onChange(state)">
</toggle-single-button></div>`
))($rootScope);
$rootScope.$digest();
return element;
}
describe('initially switched off > ', () => {
let toggleSingleButton;
beforeEach(() => {
compiledDirective = getCompiledElement();
toggleSingleButton = compiledDirective.find('button');
});
it('should have button disabled', () => {
// timeout should be flashed
$timeout.flush();
expect(toggleSingleButton.get(0)).toBeTruthy();
expect(toggleSingleButton.hasClass('toggle-single-button-disabled')).toBeTruthy();
});
describe('click on button >', () => {
it('should enable button', () => {
toggleSingleButton.click();
$rootScope.$digest();
// timeout should be flashed to get callback called and content visible
$timeout.flush();
expect(toggleSingleButton.hasClass('toggle-single-button-disabled')).toBeFalsy();
});
it('should call the callback', () => {
spyOn($rootScope.model, 'onChange');
toggleSingleButton.click();
$rootScope.$digest();
// timeout should be flashed to get callback called and content visible
$timeout.flush();
expect($rootScope.model.onChange).toHaveBeenCalledWith(true);
});
});
describe(`change state of toggle button from outside of directive >`, () => {
it('should enable button', () => {
$rootScope.model.state = true;
$rootScope.$digest();
// timeout should be flashed to get callback called and content visible
$timeout.flush();
expect(toggleSingleButton.hasClass('toggle-single-button-disabled')).toBeFalsy();
});
it('should call the callback', () => {
spyOn($rootScope.model, 'onChange');
$rootScope.model.state = true;
$rootScope.$digest();
// timeout should be flashed to get callback called and content visible
$timeout.flush();
expect($rootScope.model.onChange).toHaveBeenCalledWith(true);
});
});
});
describe('initially switched on >', () => {
let toggleSingleButton;
beforeEach(() => {
$rootScope.model.state = true;
compiledDirective = getCompiledElement();
toggleSingleButton = compiledDirective.find('button');
$timeout.flush();
});
it('should have button enabled', () => {
expect(toggleSingleButton.get(0)).toBeTruthy();
expect(toggleSingleButton.hasClass('toggle-single-button-disabled')).toBeFalsy();
});
describe('click on button >', () => {
it('should disable button', () => {
toggleSingleButton.click();
$rootScope.$digest();
expect(toggleSingleButton.hasClass('toggle-single-button-disabled')).toBeTruthy();
});
it('should call the callback', () => {
spyOn($rootScope.model, 'onChange');
toggleSingleButton.click();
$rootScope.$digest();
expect($rootScope.model.onChange).toHaveBeenCalledWith(false);
});
});
describe(`change state of toggle button from outside of directive >`, () => {
it('should disable button', () => {
$rootScope.model.state = false;
$rootScope.$digest();
expect(toggleSingleButton.hasClass('toggle-single-button-disabled')).toBeTruthy();
});
it('should call the callback', () => {
spyOn($rootScope.model, 'onChange');
$rootScope.model.state = false;
$rootScope.$digest();
expect($rootScope.model.onChange).toHaveBeenCalledWith(false);
});
});
});
});

View File

@ -23,7 +23,7 @@
* @param {string} che-title button's title
* @param {expression=} che-multiline-title allows multi line title if attr exists
* @param {string=} che-font-icon button's icon CSS class
* @param {expression=} che-state expression which defines initial state of button.
* @param {expression=} che-state expression which defines state of button.
* @param {Function} che-on-change callback on model change
* @usage
* <toggle-single-button che-title="Filter"
@ -33,10 +33,15 @@
* @author Oleksii Kurinnyi
*/
interface IToggleSingleButtonAttrs extends ng.IAttributes {
cheMultilineTitle?: boolean;
}
interface IToggleSingleButtonScope extends ng.IScope {
init?: boolean;
state?: boolean;
state: boolean;
changeState: () => void;
onChange: (data: {state: boolean}) => void;
multilineTitle?: string;
}
/**
@ -59,31 +64,28 @@ export class ToggleSingleButton {
constructor() {
// scope values
this.scope = {
init: '=?cheState',
state: '=?cheValue',
state: '=?cheState',
title: '@cheTitle',
multilineTitle: '=?cheMultilineTitle',
fontIcon: '@?cheFontIcon',
onChange: '&cheOnChange'
onChange: '&?cheOnChange'
};
}
link($scope: IToggleSingleButtonScope, $element: ng.IAugmentedJQuery, $attrs: ng.IAttributes): void {
link($scope: IToggleSingleButtonScope, $element: ng.IAugmentedJQuery, $attrs: IToggleSingleButtonAttrs): void {
if (angular.isDefined($attrs.cheMultilineTitle)) {
$scope.multilineTitle = 'true';
}
if ($scope.init) {
$scope.state = $scope.init;
$scope.onChange({state: true});
}
const watcher = $scope.$watch(() => { return $scope.state; }, (newValue: boolean, oldValue: boolean) => {
if (newValue === oldValue) {
return;
}
$scope.onChange({state: newValue});
$scope.onChange({state: $scope.state});
});
$scope.$on('$destroy', () => {
watcher();
});

View File

@ -15,7 +15,7 @@ import java.util.Map;
import org.eclipse.che.ide.api.editor.text.Position;
import org.eclipse.che.ide.api.editor.text.annotation.Annotation;
import org.eclipse.che.ide.api.editor.events.DocumentChangeHandler;
import org.eclipse.che.ide.api.editor.events.DocumentChangedHandler;
import org.eclipse.che.ide.api.editor.document.UseDocumentHandle;
/**
@ -33,7 +33,7 @@ import org.eclipse.che.ide.api.editor.document.UseDocumentHandle;
* using the callback.</li>
* </ul>
*/
public interface AnnotationModel extends UseDocumentHandle, DocumentChangeHandler, QueryAnnotationsHandler {
public interface AnnotationModel extends UseDocumentHandle, DocumentChangedHandler, QueryAnnotationsHandler {
/**

View File

@ -13,7 +13,7 @@ package org.eclipse.che.ide.api.editor.annotation;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import org.eclipse.che.ide.api.editor.document.DocumentHandle;
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent;
import org.eclipse.che.ide.api.editor.events.DocumentChangedEvent;
import org.eclipse.che.ide.api.editor.partition.DocumentPositionMap;
import org.eclipse.che.ide.api.editor.text.BadLocationException;
import org.eclipse.che.ide.api.editor.text.BadPositionCategoryException;
@ -261,7 +261,7 @@ public class AnnotationModelImpl implements AnnotationModel {
}
@Override
public void onDocumentChange(final DocumentChangeEvent event) {
public void onDocumentChanged(final DocumentChangedEvent event) {
this.documentChanged = true;
}

View File

@ -11,7 +11,7 @@
package org.eclipse.che.ide.api.editor.autosave;
import org.eclipse.che.ide.api.editor.document.UseDocumentHandle;
import org.eclipse.che.ide.api.editor.events.DocumentChangeHandler;
import org.eclipse.che.ide.api.editor.events.DocumentChangedHandler;
import org.eclipse.che.ide.api.editor.texteditor.TextEditor;
/**
@ -19,7 +19,7 @@ import org.eclipse.che.ide.api.editor.texteditor.TextEditor;
*
* @author Roman Nikitenko
*/
public interface AutoSaveMode extends DocumentChangeHandler, UseDocumentHandle {
public interface AutoSaveMode extends DocumentChangedHandler, UseDocumentHandle {
/**
* Installs auto save mode on the given editor.

View File

@ -13,10 +13,10 @@ package org.eclipse.che.ide.api.editor.events;
import org.eclipse.che.ide.api.editor.document.DocumentHandle;
import com.google.gwt.event.shared.GwtEvent;
public class DocumentChangeEvent extends GwtEvent<DocumentChangeHandler> {
public class DocumentChangedEvent extends GwtEvent<DocumentChangedHandler> {
/** The type instance for this event. */
public static final Type<DocumentChangeHandler> TYPE = new Type<>();
public static final Type<DocumentChangedHandler> TYPE = new Type<>();
/** The document handle */
private final DocumentHandle document;
@ -32,7 +32,7 @@ public class DocumentChangeEvent extends GwtEvent<DocumentChangeHandler> {
private final int removedCharCount;
public DocumentChangeEvent(final DocumentHandle document, final int offset, final int length, final String text, int removedCharCount) {
public DocumentChangedEvent(final DocumentHandle document, final int offset, final int length, final String text, int removedCharCount) {
this.offset = offset;
this.length = length;
this.text = text;
@ -41,13 +41,13 @@ public class DocumentChangeEvent extends GwtEvent<DocumentChangeHandler> {
}
@Override
public Type<DocumentChangeHandler> getAssociatedType() {
public Type<DocumentChangedHandler> getAssociatedType() {
return TYPE;
}
@Override
protected void dispatch(final DocumentChangeHandler handler) {
handler.onDocumentChange(this);
protected void dispatch(final DocumentChangedHandler handler) {
handler.onDocumentChanged(this);
}
public int getOffset() {

View File

@ -12,7 +12,7 @@ package org.eclipse.che.ide.api.editor.events;
import com.google.gwt.event.shared.EventHandler;
public interface DocumentChangeHandler extends EventHandler {
public interface DocumentChangedHandler extends EventHandler {
void onDocumentChange(DocumentChangeEvent event);
void onDocumentChanged(DocumentChangedEvent event);
}

View File

@ -0,0 +1,72 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.ide.api.editor.events;
import com.google.gwt.event.shared.GwtEvent;
import org.eclipse.che.ide.api.editor.document.DocumentHandle;
public class DocumentChangingEvent extends GwtEvent<DocumentChangingHandler> {
/** The type instance for this event. */
public static final Type<DocumentChangingHandler> TYPE = new Type<>();
/** The document handle */
private final DocumentHandle document;
/** The document offset */
private final int offset;
/** Length of the replaced document text */
private final int length;
/** Text inserted into the document */
private final String text;
private final int removedCharCount;
public DocumentChangingEvent(final DocumentHandle document, final int offset, final int length, final String text, int removedCharCount) {
this.offset = offset;
this.length = length;
this.text = text;
this.document = document;
this.removedCharCount = removedCharCount;
}
@Override
public Type<DocumentChangingHandler> getAssociatedType() {
return TYPE;
}
@Override
protected void dispatch(final DocumentChangingHandler handler) {
handler.onDocumentChanging(this);
}
public int getOffset() {
return offset;
}
public int getLength() {
return length;
}
public String getText() {
return text;
}
public DocumentHandle getDocument() {
return document;
}
public int getRemoveCharCount() {
return removedCharCount;
}
}

View File

@ -0,0 +1,18 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.ide.api.editor.events;
import com.google.gwt.event.shared.EventHandler;
public interface DocumentChangingHandler extends EventHandler {
void onDocumentChanging(DocumentChangingEvent event);
}

View File

@ -13,7 +13,7 @@ package org.eclipse.che.ide.api.editor.partition;
import java.util.Collections;
import java.util.List;
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent;
import org.eclipse.che.ide.api.editor.events.DocumentChangedEvent;
import org.eclipse.che.ide.api.editor.text.TypedRegion;
import org.eclipse.che.ide.api.editor.text.TypedRegionImpl;
import org.eclipse.che.ide.api.editor.document.DocumentHandle;
@ -53,7 +53,7 @@ public class ConstantPartitioner implements DocumentPartitioner {
}
@Override
public void onDocumentChange(final DocumentChangeEvent event) {
public void onDocumentChanged(final DocumentChangedEvent event) {
final int removed = event.getLength();
int added = 0;
if (event.getText() != null) {

View File

@ -14,7 +14,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent;
import org.eclipse.che.ide.api.editor.events.DocumentChangedEvent;
import org.eclipse.che.ide.api.editor.text.BadLocationException;
import org.eclipse.che.ide.api.editor.text.BadPositionCategoryException;
import org.eclipse.che.ide.api.editor.text.Position;
@ -87,7 +87,7 @@ public class DefaultPartitioner implements DocumentPartitioner {
}
@Override
public void onDocumentChange(final DocumentChangeEvent event) {
public void onDocumentChanged(final DocumentChangedEvent event) {
this.scanner.setScannedString(event.getDocument().getDocument().getContents());
updatePositions();
}

View File

@ -12,7 +12,7 @@ package org.eclipse.che.ide.api.editor.partition;
import java.util.List;
import org.eclipse.che.ide.api.editor.events.DocumentChangeHandler;
import org.eclipse.che.ide.api.editor.events.DocumentChangedHandler;
import org.eclipse.che.ide.api.editor.text.TypedRegion;
import org.eclipse.che.ide.api.editor.document.UseDocumentHandle;
@ -21,7 +21,7 @@ import org.eclipse.che.ide.api.editor.document.UseDocumentHandle;
* Partitioners parse a document and splits it in partitions, which are contiguous zones of text
* of a specific type (for example comment, literal string, code etc.).
*/
public interface DocumentPartitioner extends DocumentChangeHandler, UseDocumentHandle {
public interface DocumentPartitioner extends DocumentChangedHandler, UseDocumentHandle {
/** The identifier of the default partition content type. */
String DEFAULT_CONTENT_TYPE = "__dftl_partition_content_type";

View File

@ -15,7 +15,7 @@ import com.google.inject.assistedinject.AssistedInject;
import org.eclipse.che.ide.api.editor.document.Document;
import org.eclipse.che.ide.api.editor.document.DocumentHandle;
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent;
import org.eclipse.che.ide.api.editor.events.DocumentChangedEvent;
import org.eclipse.che.ide.api.editor.partition.DocumentPartitioner;
import org.eclipse.che.ide.api.editor.texteditor.TextEditor;
@ -72,7 +72,7 @@ public class DefaultReconciler implements Reconciler {
}
@Override
public void onDocumentChange(final DocumentChangeEvent event) {
public void onDocumentChanged(final DocumentChangedEvent event) {
}
@Override

View File

@ -11,7 +11,7 @@
package org.eclipse.che.ide.api.editor.reconciler;
import org.eclipse.che.ide.api.editor.document.UseDocumentHandle;
import org.eclipse.che.ide.api.editor.events.DocumentChangeHandler;
import org.eclipse.che.ide.api.editor.events.DocumentChangedHandler;
import org.eclipse.che.ide.api.editor.texteditor.TextEditor;
/**
@ -21,7 +21,7 @@ import org.eclipse.che.ide.api.editor.texteditor.TextEditor;
*
* @author Evgen Vidolob
*/
public interface Reconciler extends UseDocumentHandle, DocumentChangeHandler {
public interface Reconciler extends UseDocumentHandle, DocumentChangedHandler {
/**
* Installs the reconciler on the given text view. After this method has been finished, the reconciler is operational, i.e., it works

View File

@ -18,7 +18,7 @@ import com.google.inject.assistedinject.AssistedInject;
import org.eclipse.che.ide.api.editor.EditorInput;
import org.eclipse.che.ide.api.editor.document.Document;
import org.eclipse.che.ide.api.editor.document.DocumentHandle;
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent;
import org.eclipse.che.ide.api.editor.events.DocumentChangedEvent;
import org.eclipse.che.ide.api.editor.partition.DocumentPartitioner;
import org.eclipse.che.ide.api.editor.text.Region;
import org.eclipse.che.ide.api.editor.text.RegionImpl;
@ -177,7 +177,7 @@ public class ReconcilerWithAutoSave implements Reconciler {
*
* @param event the document event for which to create a dirty region
*/
private void createDirtyRegion(final DocumentChangeEvent event) {
private void createDirtyRegion(final DocumentChangedEvent event) {
if (event.getLength() == 0 && event.getText() != null) {
// Insert
dirtyRegionQueue.addDirtyRegion(new DirtyRegion(event.getOffset(),
@ -221,7 +221,7 @@ public class ReconcilerWithAutoSave implements Reconciler {
}
@Override
public void onDocumentChange(final DocumentChangeEvent event) {
public void onDocumentChanged(final DocumentChangedEvent event) {
if (documentHandle == null || !documentHandle.isSameAs(event.getDocument())) {
return;
}

View File

@ -17,7 +17,7 @@ import com.google.gwt.event.dom.client.HasFocusHandlers;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.RequiresResize;
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent;
import org.eclipse.che.ide.api.editor.events.DocumentChangedEvent;
import org.eclipse.che.ide.api.editor.text.Region;
import org.eclipse.che.ide.api.hotkeys.HotKeyItem;
import org.eclipse.che.ide.api.editor.codeassist.AdditionalInfoCallback;
@ -56,7 +56,7 @@ public interface EditorWidget extends IsWidget,
/**
* Sets the content of the editor.<br>
* The operation <em>must</em> send a {@link DocumentChangeEvent} on the document private event bus.
* The operation <em>must</em> send a {@link DocumentChangedEvent} on the document private event bus.
*
* @param newValue
* the new contents

View File

@ -286,7 +286,9 @@ public class EditorAgentImpl implements EditorAgent,
editor.addCloseHandler(this);
workspaceAgent.openPart(editor, EDITING, constraints);
finalizeInit(file, callback, editor, editorProvider);
finalizeInit(file, callback, editor, editorProvider).then(arg -> {
workspaceAgent.setActivePart(editor);
});
}
private Promise<Void> finalizeInit(final VirtualFile file,
@ -297,7 +299,6 @@ public class EditorAgentImpl implements EditorAgent,
openedEditors.add(editor);
openedEditorsToProviders.put(editor, editorProvider.getId());
workspaceAgent.setActivePart(editor);
editor.addPropertyListener((source, propId) -> {
if (propId == EditorPartPresenter.PROP_INPUT) {
promiseCallback.onSuccess(null);

View File

@ -20,7 +20,7 @@ import org.eclipse.che.ide.api.editor.EditorOpenedEventHandler;
import org.eclipse.che.ide.api.editor.EditorPartPresenter;
import org.eclipse.che.ide.api.editor.autosave.AutoSaveMode;
import org.eclipse.che.ide.api.editor.document.DocumentHandle;
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent;
import org.eclipse.che.ide.api.editor.events.DocumentChangedEvent;
import org.eclipse.che.ide.api.editor.reconciler.DirtyRegion;
import org.eclipse.che.ide.api.editor.reconciler.DirtyRegionQueue;
import org.eclipse.che.ide.api.editor.texteditor.TextEditor;
@ -156,13 +156,13 @@ public class AutoSaveModeImpl implements AutoSaveMode, EditorSettingsChangedHand
public void onEditorOpened(EditorOpenedEvent editorOpenedEvent) {
if (documentHandle != null && editor == editorOpenedEvent.getEditor()) {
HandlerRegistration documentChangeHandlerRegistration =
documentHandle.getDocEventBus().addHandler(DocumentChangeEvent.TYPE, this);
documentHandle.getDocEventBus().addHandler(DocumentChangedEvent.TYPE, this);
handlerRegistrations.add(documentChangeHandlerRegistration);
}
}
@Override
public void onDocumentChange(final DocumentChangeEvent event) {
public void onDocumentChanged(final DocumentChangedEvent event) {
if (documentHandle == null || !event.getDocument().isSameAs(documentHandle)) {
return;
}
@ -184,7 +184,7 @@ public class AutoSaveModeImpl implements AutoSaveMode, EditorSettingsChangedHand
* @param event
* the document event for which to create a dirty region
*/
private void createDirtyRegion(final DocumentChangeEvent event) {
private void createDirtyRegion(final DocumentChangedEvent event) {
if (event.getRemoveCharCount() == 0 && event.getText() != null && !event.getText().isEmpty()) {
// Insert
dirtyRegionQueue.addDirtyRegion(new DirtyRegion(event.getOffset(),

View File

@ -11,7 +11,7 @@
package org.eclipse.che.ide.editor.synchronization;
import org.eclipse.che.ide.api.editor.EditorPartPresenter;
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent;
import org.eclipse.che.ide.api.editor.events.DocumentChangedEvent;
import org.eclipse.che.ide.api.event.FileContentUpdateEvent;
import org.eclipse.che.ide.resource.Path;
@ -19,7 +19,7 @@ import javax.validation.constraints.NotNull;
import java.util.Set;
/**
* Contains list of opened files with the same {@link Path} and listens to {@link DocumentChangeEvent} and {@link FileContentUpdateEvent}
* Contains list of opened files with the same {@link Path} and listens to {@link DocumentChangedEvent} and {@link FileContentUpdateEvent}
* to provide the synchronization of the content for them.
*
* @author Roman Nikitenko

View File

@ -20,8 +20,8 @@ import org.eclipse.che.ide.api.editor.EditorWithAutoSave;
import org.eclipse.che.ide.api.editor.document.Document;
import org.eclipse.che.ide.api.editor.document.DocumentHandle;
import org.eclipse.che.ide.api.editor.document.DocumentStorage;
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent;
import org.eclipse.che.ide.api.editor.events.DocumentChangeHandler;
import org.eclipse.che.ide.api.editor.events.DocumentChangedEvent;
import org.eclipse.che.ide.api.editor.events.DocumentChangedHandler;
import org.eclipse.che.ide.api.editor.text.TextPosition;
import org.eclipse.che.ide.api.editor.texteditor.TextEditor;
import org.eclipse.che.ide.api.event.FileContentUpdateEvent;
@ -41,7 +41,7 @@ import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMod
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL;
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.SUCCESS;
public class EditorGroupSynchronizationImpl implements EditorGroupSynchronization, DocumentChangeHandler, FileContentUpdateHandler {
public class EditorGroupSynchronizationImpl implements EditorGroupSynchronization, DocumentChangedHandler, FileContentUpdateHandler {
private final DocumentStorage documentStorage;
private final NotificationManager notificationManager;
private final HandlerRegistration fileContentUpdateHandlerRegistration;
@ -66,7 +66,7 @@ public class EditorGroupSynchronizationImpl implements EditorGroupSynchronizatio
}
if (synchronizedEditors.isEmpty()) {
HandlerRegistration handlerRegistration = documentHandle.getDocEventBus().addHandler(DocumentChangeEvent.TYPE, this);
HandlerRegistration handlerRegistration = documentHandle.getDocEventBus().addHandler(DocumentChangedEvent.TYPE, this);
synchronizedEditors.put(editor, handlerRegistration);
return;
}
@ -83,7 +83,7 @@ public class EditorGroupSynchronizationImpl implements EditorGroupSynchronizatio
editorDocument.replace(0, oldContent.length(), groupMemberContent);
}
HandlerRegistration handlerRegistration = documentHandle.getDocEventBus().addHandler(DocumentChangeEvent.TYPE, this);
HandlerRegistration handlerRegistration = documentHandle.getDocEventBus().addHandler(DocumentChangedEvent.TYPE, this);
synchronizedEditors.put(editor, handlerRegistration);
}
@ -121,7 +121,7 @@ public class EditorGroupSynchronizationImpl implements EditorGroupSynchronizatio
}
@Override
public void onDocumentChange(DocumentChangeEvent event) {
public void onDocumentChanged(DocumentChangedEvent event) {
DocumentHandle activeEditorDocumentHandle = getDocumentHandleFor(groupLeaderEditor);
if (activeEditorDocumentHandle == null || !event.getDocument().isSameAs(activeEditorDocumentHandle)) {
return;

View File

@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.che.ide.project;
import com.google.gwt.http.client.URL;
import com.google.inject.Inject;
import org.eclipse.che.api.project.shared.dto.CopyOptions;
@ -39,6 +38,7 @@ import java.util.Map;
import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.gwt.http.client.RequestBuilder.DELETE;
import static com.google.gwt.http.client.RequestBuilder.PUT;
import static com.google.gwt.safehtml.shared.UriUtils.encodeAllowEscapes;
import static org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.createFromAsyncRequest;
import static org.eclipse.che.ide.rest.HTTPHeader.ACCEPT;
import static org.eclipse.che.ide.rest.HTTPHeader.CONTENT_TYPE;
@ -112,7 +112,7 @@ public class ProjectServiceClient {
* @since 4.4.0
*/
public Promise<SourceEstimation> estimate(Path path, String pType) {
final String url = getBaseUrl() + ESTIMATE + path(path.toString()) + "?type=" + pType;
final String url = encodeAllowEscapes(getBaseUrl() + ESTIMATE + path(path.toString()) + "?type=" + pType);
return reqFactory.createGetRequest(url)
.header(ACCEPT, MimeType.APPLICATION_JSON)
@ -131,7 +131,7 @@ public class ProjectServiceClient {
* @since 4.4.0
*/
public Promise<List<SourceEstimation>> resolveSources(Path path) {
final String url = getBaseUrl() + RESOLVE + path(path.toString());
final String url = encodeAllowEscapes(getBaseUrl() + RESOLVE + path(path.toString()));
return reqFactory.createGetRequest(url)
.header(ACCEPT, MimeType.APPLICATION_JSON)
@ -154,8 +154,8 @@ public class ProjectServiceClient {
public Promise<Void> importProject(final Path path,
final SourceStorageDto source) {
return createFromAsyncRequest(callback -> {
final String url = PROJECT + IMPORT + path(path.toString());
// TODO (spi ide): must be reworked with JSON-RPC
// final String url = encodeAllowEscapes(PROJECT + IMPORT + path(path.toString()));
// final Message message = new MessageBuilder(POST, url).data(dtoFactory.toJson(source))
// .header(CONTENTTYPE, APPLICATION_JSON)
// .build();
@ -193,7 +193,8 @@ public class ProjectServiceClient {
* @since 4.4.0
*/
public Promise<List<ItemReference>> search(QueryExpression expression) {
final String url = getBaseUrl() + SEARCH + (isNullOrEmpty(expression.getPath()) ? Path.ROOT : path(expression.getPath()));
final String url =
encodeAllowEscapes(getBaseUrl() + SEARCH + (isNullOrEmpty(expression.getPath()) ? Path.ROOT : path(expression.getPath())));
StringBuilder queryParameters = new StringBuilder();
if (expression.getName() != null && !expression.getName().isEmpty()) {
@ -254,7 +255,7 @@ public class ProjectServiceClient {
* @see ProjectConfigDto
*/
public Promise<List<ProjectConfigDto>> createBatchProjects(List<NewProjectConfigDto> configurations) {
final String url = getBaseUrl() + BATCH_PROJECTS;
final String url = encodeAllowEscapes(getBaseUrl() + BATCH_PROJECTS);
final String loaderMessage = configurations.size() > 1 ? "Creating the batch of projects..." : "Creating project...";
return reqFactory.createPostRequest(url, configurations)
.header(ACCEPT, MimeType.APPLICATION_JSON)
@ -275,7 +276,7 @@ public class ProjectServiceClient {
* @since 4.4.0
*/
public Promise<ItemReference> createFile(Path path, String content) {
final String url = getBaseUrl() + FILE + path(path.parent().toString()) + "?name=" + URL.encodeQueryString(path.lastSegment());
final String url = encodeAllowEscapes(getBaseUrl() + FILE + path(path.parent().toString()) + "?name=" + path.lastSegment());
return reqFactory.createPostRequest(url, null)
.data(content)
@ -293,7 +294,7 @@ public class ProjectServiceClient {
* @since 4.4.0
*/
public Promise<String> getFileContent(Path path) {
final String url = getBaseUrl() + FILE + path(path.toString());
final String url = encodeAllowEscapes(getBaseUrl() + FILE + path(path.toString()));
return reqFactory.createGetRequest(url)
.loader(loaderFactory.newLoader("Loading file content..."))
@ -312,7 +313,7 @@ public class ProjectServiceClient {
* @since 4.4.0
*/
public Promise<Void> setFileContent(Path path, String content) {
final String url = getBaseUrl() + FILE + path(path.toString());
final String url = encodeAllowEscapes(getBaseUrl() + FILE + path(path.toString()));
return reqFactory.createRequest(PUT, url, null, false)
.data(content)
@ -331,7 +332,7 @@ public class ProjectServiceClient {
* @since 4.4.0
*/
public Promise<ItemReference> createFolder(Path path) {
final String url = getBaseUrl() + FOLDER + path(path.toString());
final String url = encodeAllowEscapes(getBaseUrl() + FOLDER + path(path.toString()));
return reqFactory.createPostRequest(url, null)
.loader(loaderFactory.newLoader("Creating folder..."))
@ -348,7 +349,7 @@ public class ProjectServiceClient {
* @since 4.4.0
*/
public Promise<Void> deleteItem(Path path) {
final String url = getBaseUrl() + path(path.toString());
final String url = encodeAllowEscapes(getBaseUrl() + path(path.toString()));
return reqFactory.createRequest(DELETE, url, null, false)
.loader(loaderFactory.newLoader("Deleting project..."))
@ -371,7 +372,7 @@ public class ProjectServiceClient {
* @since 4.4.0
*/
public Promise<Void> copy(Path source, Path target, String newName, boolean overwrite) {
final String url = getBaseUrl() + COPY + path(source.toString()) + "?to=" + URL.encodeQueryString(target.toString());
final String url = encodeAllowEscapes(getBaseUrl() + COPY + path(source.toString()) + "?to=" + target.toString());
final CopyOptions copyOptions = dtoFactory.createDto(CopyOptions.class);
copyOptions.setName(newName);
@ -398,7 +399,7 @@ public class ProjectServiceClient {
* @since 4.4.0
*/
public Promise<Void> move(Path source, Path target, String newName, boolean overwrite) {
final String url = getBaseUrl() + MOVE + path(source.toString()) + "?to=" + URL.encodeQueryString(target.toString());
final String url = encodeAllowEscapes(getBaseUrl() + MOVE + path(source.toString()) + "?to=" + target.toString());
final MoveOptions moveOptions = dtoFactory.createDto(MoveOptions.class);
moveOptions.setName(newName);
@ -424,7 +425,8 @@ public class ProjectServiceClient {
* @since 4.4.0
*/
public Promise<TreeElement> getTree(Path path, int depth, boolean includeFiles) {
final String url = getBaseUrl() + TREE + path(path.toString()) + "?depth=" + depth + "&includeFiles=" + includeFiles;
final String url =
encodeAllowEscapes(getBaseUrl() + TREE + path(path.toString()) + "?depth=" + depth + "&includeFiles=" + includeFiles);
// temporary workaround for CHE-3467, remove loader for disable UI blocking
// later this loader should be added with the new mechanism of client-server synchronization
@ -445,7 +447,7 @@ public class ProjectServiceClient {
* @since 4.4.0
*/
public Promise<ItemReference> getItem(Path path) {
final String url = getBaseUrl() + ITEM + path(path.toString());
final String url = encodeAllowEscapes(getBaseUrl() + ITEM + path(path.toString()));
return reqFactory.createGetRequest(url)
.header(ACCEPT, MimeType.APPLICATION_JSON)
@ -464,7 +466,7 @@ public class ProjectServiceClient {
* @since 4.4.0
*/
public Promise<ProjectConfigDto> getProject(Path path) {
final String url = getBaseUrl() + path(path.toString());
final String url = encodeAllowEscapes(getBaseUrl() + path(path.toString()));
return reqFactory.createGetRequest(url)
.header(ACCEPT, MimeType.APPLICATION_JSON)
@ -482,7 +484,7 @@ public class ProjectServiceClient {
* @since 4.4.0
*/
public Promise<ProjectConfigDto> updateProject(ProjectConfigDto configuration) {
final String url = getBaseUrl() + path(configuration.getPath());
final String url = encodeAllowEscapes(getBaseUrl() + path(configuration.getPath()));
return reqFactory.createRequest(PUT, url, configuration, false)
.header(CONTENT_TYPE, MimeType.APPLICATION_JSON)

View File

@ -21,7 +21,7 @@ import org.eclipse.che.ide.api.editor.document.Document;
import org.eclipse.che.ide.api.editor.document.DocumentEventBus;
import org.eclipse.che.ide.api.editor.document.DocumentHandle;
import org.eclipse.che.ide.api.editor.document.DocumentStorage;
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent;
import org.eclipse.che.ide.api.editor.events.DocumentChangedEvent;
import org.eclipse.che.ide.api.editor.texteditor.TextEditor;
import org.eclipse.che.ide.api.notification.NotificationManager;
import org.junit.Before;
@ -64,7 +64,7 @@ public class EditorGroupSynchronizationImplTest {
@Mock
private HandlerRegistration handlerRegistration;
@Mock
private DocumentChangeEvent documentChangeEvent;
private DocumentChangedEvent documentChangeEvent;
private EditorPartPresenter activeEditor;
private EditorPartPresenter openedEditor1;
@ -102,7 +102,7 @@ public class EditorGroupSynchronizationImplTest {
editorGroupSynchronization.addEditor(activeEditor);
verify(documentEventBus).addHandler(Matchers.<DocumentChangeEvent.Type>anyObject(), eq(editorGroupSynchronization));
verify(documentEventBus).addHandler(Matchers.<DocumentChangedEvent.Type>anyObject(), eq(editorGroupSynchronization));
}
@Test
@ -118,7 +118,7 @@ public class EditorGroupSynchronizationImplTest {
verify((EditorWithAutoSave)openedEditor1).isAutoSaveEnabled();
verify(document, times(2)).getContents();
verify(document).replace(anyInt(), anyInt(), anyString());
verify(documentEventBus).addHandler(Matchers.<DocumentChangeEvent.Type>anyObject(), eq(editorGroupSynchronization));
verify(documentEventBus).addHandler(Matchers.<DocumentChangedEvent.Type>anyObject(), eq(editorGroupSynchronization));
}
@Test
@ -145,7 +145,7 @@ public class EditorGroupSynchronizationImplTest {
when(documentChangeEvent.getDocument()).thenReturn(documentHandle1);
when(documentHandle1.isSameAs(documentHandle)).thenReturn(false);
editorGroupSynchronization.onDocumentChange(documentChangeEvent);
editorGroupSynchronization.onDocumentChanged(documentChangeEvent);
verify(document, never()).replace(anyInt(), anyInt(), anyString());
}
@ -163,7 +163,7 @@ public class EditorGroupSynchronizationImplTest {
when(documentHandle1.isSameAs(documentHandle)).thenReturn(true);
addEditorsToGroup();
editorGroupSynchronization.onDocumentChange(documentChangeEvent);
editorGroupSynchronization.onDocumentChanged(documentChangeEvent);
verify(document, times(2)).replace(eq(offset), eq(removeCharCount), eq(text));
}

View File

@ -2364,7 +2364,7 @@
"goal": "Build"
}
}, {
"commandLine": "cd ${current.project.path} && scl enable rh-maven33 'java -jar target/*-fat.jar'",
"commandLine": "scl enable rh-maven33 'mvn vertx:run -f ${current.project.path}'",
"name": "run",
"type": "custom",
"attributes": {

View File

@ -12,6 +12,16 @@ package org.eclipse.che.ide.editor.orion.client;
import com.google.web.bindery.event.shared.HandlerRegistration;
import org.eclipse.che.ide.api.editor.document.AbstractDocument;
import org.eclipse.che.ide.api.editor.document.Document;
import org.eclipse.che.ide.api.editor.events.CursorActivityHandler;
import org.eclipse.che.ide.api.editor.events.DocumentChangedEvent;
import org.eclipse.che.ide.api.editor.events.DocumentChangingEvent;
import org.eclipse.che.ide.api.editor.events.HasCursorActivityHandlers;
import org.eclipse.che.ide.api.editor.position.PositionConverter;
import org.eclipse.che.ide.api.editor.text.LinearRange;
import org.eclipse.che.ide.api.editor.text.TextPosition;
import org.eclipse.che.ide.api.editor.text.TextRange;
import org.eclipse.che.ide.api.resources.File;
import org.eclipse.che.ide.api.resources.VirtualFile;
import org.eclipse.che.ide.editor.orion.client.jso.ModelChangedEventOverlay;
@ -21,15 +31,6 @@ import org.eclipse.che.ide.editor.orion.client.jso.OrionSelectionOverlay;
import org.eclipse.che.ide.editor.orion.client.jso.OrionTextModelOverlay;
import org.eclipse.che.ide.editor.orion.client.jso.OrionTextModelOverlay.EventHandler;
import org.eclipse.che.ide.editor.orion.client.jso.OrionTextViewOverlay;
import org.eclipse.che.ide.api.editor.document.AbstractDocument;
import org.eclipse.che.ide.api.editor.document.Document;
import org.eclipse.che.ide.api.editor.events.CursorActivityHandler;
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent;
import org.eclipse.che.ide.api.editor.events.HasCursorActivityHandlers;
import org.eclipse.che.ide.api.editor.position.PositionConverter;
import org.eclipse.che.ide.api.editor.text.LinearRange;
import org.eclipse.che.ide.api.editor.text.TextPosition;
import org.eclipse.che.ide.api.editor.text.TextRange;
/**
* The implementation of {@link Document} for Orion.
@ -60,6 +61,14 @@ public class OrionDocument extends AbstractDocument {
fireDocumentChangeEvent(parameter);
}
}, true);
this.editorOverlay.getModel().addEventListener("Changing", new EventHandler<ModelChangedEventOverlay>() {
@Override
public void onEvent(ModelChangedEventOverlay parameter) {
fireDocumentChangingEvent(parameter);
}
}, true);
}
private void fireDocumentChangeEvent(final ModelChangedEventOverlay param) {
@ -70,15 +79,33 @@ public class OrionDocument extends AbstractDocument {
String text = editorOverlay.getModel().getText(startOffset, startOffset + addedCharCount);
final DocumentChangeEvent event = new DocumentChangeEvent(this,
startOffset,
addedCharCount,
text,
removedCharCount);
final DocumentChangedEvent event = new DocumentChangedEvent(this,
startOffset,
addedCharCount,
text,
removedCharCount);
// according to https://github.com/codenvy/che-core/pull/122
getDocEventBus().fireEvent(event);
}
private void fireDocumentChangingEvent(final ModelChangedEventOverlay param) {
int startOffset = param.start();
int addedCharCount = param.addedCharCount();
int removedCharCount = param.removedCharCount();
String text = editorOverlay.getModel().getText(startOffset, startOffset + addedCharCount);
final DocumentChangingEvent event = new DocumentChangingEvent(this,
startOffset,
addedCharCount,
text,
removedCharCount);
// according to https://github.com/codenvy/che-core/pull/122
getDocEventBus().fireEvent(event);
}
@Override
public TextPosition getPositionFromIndex(final int index) {
final int line = this.editorOverlay.getModel().getLineAtOffset(index);
@ -112,12 +139,6 @@ public class OrionDocument extends AbstractDocument {
return result;
}
@Override
public void setCursorPosition(final TextPosition position) {
this.editorOverlay.setCaretOffset(getIndexFromPosition(position));
}
@Override
public int getLineAtOffset(int offset) {
return this.editorOverlay.getTextView().getLineAtOffset(offset);
@ -134,6 +155,12 @@ public class OrionDocument extends AbstractDocument {
return getPositionFromIndex(offset);
}
@Override
public void setCursorPosition(final TextPosition position) {
this.editorOverlay.setCaretOffset(getIndexFromPosition(position));
}
public int getCursorOffset() {
return this.editorOverlay.getTextView().getCaretOffset();
}
@ -169,34 +196,6 @@ public class OrionDocument extends AbstractDocument {
return this.positionConverter;
}
private class OrionPositionConverter implements PositionConverter {
@Override
public PixelCoordinates textToPixel(TextPosition textPosition) {
final int textOffset = getIndexFromPosition(textPosition);
return offsetToPixel(textOffset);
}
@Override
public PixelCoordinates offsetToPixel(int textOffset) {
OrionPixelPositionOverlay location = textViewOverlay.getLocationAtOffset(textOffset);
location.setY(location.getY() + textViewOverlay.getLineHeight());
location = textViewOverlay.convert(location, "document", "page");
return new PixelCoordinates(location.getX(), location.getY());
}
@Override
public TextPosition pixelToText(PixelCoordinates coordinates) {
final int offset = pixelToOffset(coordinates);
return getPositionFromIndex(offset);
}
@Override
public int pixelToOffset(PixelCoordinates coordinates) {
return textViewOverlay.getOffsetAtLocation(coordinates.getX(), coordinates.getY());
}
}
public void replace(int offset, int length, String text) {
this.editorOverlay.getModel().setText(text, offset, offset + length);
updateModificationTimeStamp();
@ -213,7 +212,7 @@ public class OrionDocument extends AbstractDocument {
private void updateModificationTimeStamp() {
VirtualFile file = this.getFile();
if (file instanceof File) {
if (file instanceof File) {
((File)file).updateModificationStamp(editorOverlay.getText());
}
}
@ -287,4 +286,32 @@ public class OrionDocument extends AbstractDocument {
LinearRange.createWithStart(lineStart + range.getFrom().getCharacter()).andEnd(lineEnd + range.getTo().getCharacter());
setSelectedRange(linearRange, show);
}
private class OrionPositionConverter implements PositionConverter {
@Override
public PixelCoordinates textToPixel(TextPosition textPosition) {
final int textOffset = getIndexFromPosition(textPosition);
return offsetToPixel(textOffset);
}
@Override
public PixelCoordinates offsetToPixel(int textOffset) {
OrionPixelPositionOverlay location = textViewOverlay.getLocationAtOffset(textOffset);
location.setY(location.getY() + textViewOverlay.getLineHeight());
location = textViewOverlay.convert(location, "document", "page");
return new PixelCoordinates(location.getX(), location.getY());
}
@Override
public TextPosition pixelToText(PixelCoordinates coordinates) {
final int offset = pixelToOffset(coordinates);
return getPositionFromIndex(offset);
}
@Override
public int pixelToOffset(PixelCoordinates coordinates) {
return textViewOverlay.getOffsetAtLocation(coordinates.getX(), coordinates.getY());
}
}
}

View File

@ -31,7 +31,7 @@ import org.eclipse.che.ide.api.editor.document.DocumentHandle;
import org.eclipse.che.ide.api.editor.editorconfig.TextEditorConfiguration;
import org.eclipse.che.ide.api.editor.events.CompletionRequestEvent;
import org.eclipse.che.ide.api.editor.events.CompletionRequestHandler;
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent;
import org.eclipse.che.ide.api.editor.events.DocumentChangedEvent;
import org.eclipse.che.ide.api.editor.events.TextChangeEvent;
import org.eclipse.che.ide.api.editor.events.TextChangeHandler;
import org.eclipse.che.ide.api.editor.formatter.ContentFormatter;
@ -143,7 +143,7 @@ public class OrionEditorInit {
final DocumentPartitioner partitioner = configuration.getPartitioner();
if (partitioner != null) {
partitioner.setDocumentHandle(documentHandle);
documentHandle.getDocEventBus().addHandler(DocumentChangeEvent.TYPE, partitioner);
documentHandle.getDocEventBus().addHandler(DocumentChangedEvent.TYPE, partitioner);
partitioner.initialize();
}
}
@ -156,7 +156,7 @@ public class OrionEditorInit {
final Reconciler reconciler = configuration.getReconciler();
if (reconciler != null) {
reconciler.setDocumentHandle(documentHandle);
documentHandle.getDocEventBus().addHandler(DocumentChangeEvent.TYPE, reconciler);
documentHandle.getDocEventBus().addHandler(DocumentChangedEvent.TYPE, reconciler);
reconciler.install(textEditor);
}
}
@ -175,7 +175,7 @@ public class OrionEditorInit {
((HasAnnotationRendering)textEditor).configure(annotationModel, documentHandle);
}
annotationModel.setDocumentHandle(documentHandle);
documentHandle.getDocEventBus().addHandler(DocumentChangeEvent.TYPE, annotationModel);
documentHandle.getDocEventBus().addHandler(DocumentChangedEvent.TYPE, annotationModel);
// the model listens to QueryAnnotation events
documentHandle.getDocEventBus().addHandler(QueryAnnotationsEvent.TYPE, annotationModel);

View File

@ -212,6 +212,18 @@ public abstract class AbstractDebugger implements Debugger, DebuggerObservable {
}
private void openCurrentFile() {
// Handle the situation when resource isn't found in the workspace
// It means that it is impossible to open it.
if (currentLocation.getResourcePath() == null) {
for (DebuggerObserver observer : observers) {
observer.onBreakpointStopped(currentLocation.getTarget(),
currentLocation.getTarget(),
currentLocation.getLineNumber());
}
return;
}
//todo we need add possibility to handle few files
activeFileHandler.openFile(currentLocation,
new AsyncCallback<VirtualFile>() {

View File

@ -596,7 +596,12 @@ public class JavaDebugger implements EventsHandler, Debugger {
setCurrentThread(event.thread());
com.sun.jdi.Location jdiLocation = event.location();
Location location = debuggerUtil.getLocation(jdiLocation);
Location location;
try {
location = debuggerUtil.getLocation(jdiLocation);
} catch (DebuggerException de) {
location = new LocationImpl(jdiLocation.declaringType().name(), jdiLocation.lineNumber());
}
debuggerCallback.onEvent(new SuspendEventImpl(location));
return false;
}

View File

@ -18,8 +18,8 @@ import org.eclipse.che.api.promises.client.OperationException;
import org.eclipse.che.api.promises.client.Promise;
import org.eclipse.che.api.promises.client.PromiseError;
import org.eclipse.che.ide.api.editor.document.Document;
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent;
import org.eclipse.che.ide.api.editor.events.DocumentChangeHandler;
import org.eclipse.che.ide.api.editor.events.DocumentChangedEvent;
import org.eclipse.che.ide.api.editor.events.DocumentChangedHandler;
import org.eclipse.che.ide.api.editor.formatter.ContentFormatter;
import org.eclipse.che.ide.api.editor.text.TextPosition;
import org.eclipse.che.ide.api.editor.text.TextRange;
@ -89,9 +89,9 @@ public class LanguageServerFormatter implements ContentFormatter {
this.editor = editor;
if (capabilities.getDocumentOnTypeFormattingProvider() != null &&
capabilities.getDocumentOnTypeFormattingProvider().getFirstTriggerCharacter() != null) {
editor.getDocument().getDocumentHandle().getDocEventBus().addHandler(DocumentChangeEvent.TYPE, new DocumentChangeHandler() {
editor.getDocument().getDocumentHandle().getDocEventBus().addHandler(DocumentChangedEvent.TYPE, new DocumentChangedHandler() {
@Override
public void onDocumentChange(DocumentChangeEvent event) {
public void onDocumentChanged(DocumentChangedEvent event) {
if (capabilities.getDocumentOnTypeFormattingProvider().getFirstTriggerCharacter().equals(event.getText())) {
Document document = event.getDocument().getDocument();

View File

@ -14,11 +14,14 @@ import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import org.eclipse.che.ide.api.editor.document.Document;
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent;
import org.eclipse.che.ide.api.editor.events.DocumentChangeHandler;
import org.eclipse.che.ide.api.editor.events.DocumentChangedEvent;
import org.eclipse.che.ide.api.editor.events.DocumentChangedHandler;
import org.eclipse.che.ide.api.editor.events.DocumentChangingEvent;
import org.eclipse.che.ide.api.editor.events.DocumentChangingHandler;
import org.eclipse.che.ide.api.editor.reconciler.DirtyRegion;
import org.eclipse.che.ide.api.editor.reconciler.ReconcilingStrategy;
import org.eclipse.che.ide.api.editor.text.Region;
import org.eclipse.che.ide.api.editor.text.TextPosition;
import org.eclipse.che.plugin.languageserver.ide.editor.sync.TextDocumentSynchronize;
import org.eclipse.che.plugin.languageserver.ide.editor.sync.TextDocumentSynchronizeFactory;
import org.eclipse.lsp4j.ServerCapabilities;
@ -35,6 +38,8 @@ public class LanguageServerReconcileStrategy implements ReconcilingStrategy {
private final TextDocumentSynchronize synchronize;
private int version = 0;
private TextPosition lastEventStart;
private TextPosition lastEventEnd;
@Inject
public LanguageServerReconcileStrategy(TextDocumentSynchronizeFactory synchronizeFactory,
@ -42,7 +47,7 @@ public class LanguageServerReconcileStrategy implements ReconcilingStrategy {
Either<TextDocumentSyncKind, TextDocumentSyncOptions> sync = serverCapabilities.getTextDocumentSync();
TextDocumentSyncKind documentSync;
if(sync.isLeft()){
if (sync.isLeft()) {
documentSync = sync.getLeft();
} else {
documentSync = sync.getRight().getChange();
@ -53,12 +58,20 @@ public class LanguageServerReconcileStrategy implements ReconcilingStrategy {
@Override
public void setDocument(Document document) {
document.getDocumentHandle().getDocEventBus().addHandler(DocumentChangeEvent.TYPE, new DocumentChangeHandler() {
document.getDocumentHandle().getDocEventBus().addHandler(DocumentChangedEvent.TYPE, new DocumentChangedHandler() {
@Override
public void onDocumentChange(DocumentChangeEvent event) {
synchronize.syncTextDocument(event, ++version);
public void onDocumentChanged(DocumentChangedEvent event) {
synchronize.syncTextDocument(event.getDocument().getDocument(), lastEventStart, lastEventEnd, event.getText(), ++version);
}
});
document.getDocumentHandle().getDocEventBus().addHandler(DocumentChangingEvent.TYPE, new DocumentChangingHandler() {
@Override
public void onDocumentChanging(DocumentChangingEvent event) {
lastEventStart = event.getDocument().getDocument().getPositionFromIndex(event.getOffset());
lastEventEnd = event.getDocument().getDocument().getPositionFromIndex(event.getOffset() + event.getRemoveCharCount());
}
});
}
@Override

View File

@ -20,8 +20,8 @@ import org.eclipse.che.api.promises.client.FunctionException;
import org.eclipse.che.api.promises.client.Promise;
import org.eclipse.che.api.promises.client.PromiseError;
import org.eclipse.che.ide.api.editor.document.Document;
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent;
import org.eclipse.che.ide.api.editor.events.DocumentChangeHandler;
import org.eclipse.che.ide.api.editor.events.DocumentChangedEvent;
import org.eclipse.che.ide.api.editor.events.DocumentChangedHandler;
import org.eclipse.che.ide.api.editor.signature.SignatureHelp;
import org.eclipse.che.ide.api.editor.signature.SignatureHelpProvider;
import org.eclipse.che.ide.api.editor.texteditor.HandlesTextOperations;
@ -87,9 +87,9 @@ public class LanguageServerSignatureHelp implements SignatureHelpProvider {
if (capabilities.getSignatureHelpProvider() != null && capabilities.getSignatureHelpProvider().getTriggerCharacters() != null) {
final List<String> triggerCharacters = capabilities.getSignatureHelpProvider().getTriggerCharacters();
handlerRegistration = editor.getDocument().getDocumentHandle().getDocEventBus()
.addHandler(DocumentChangeEvent.TYPE, new DocumentChangeHandler() {
.addHandler(DocumentChangedEvent.TYPE, new DocumentChangedHandler() {
@Override
public void onDocumentChange(DocumentChangeEvent event) {
public void onDocumentChanged(DocumentChangedEvent event) {
if (triggerCharacters.contains(event.getText())) {
((HandlesTextOperations)editor)
.doOperation(TextEditorOperations.SIGNATURE_HELP);

View File

@ -12,9 +12,8 @@ package org.eclipse.che.plugin.languageserver.ide.editor.sync;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.che.ide.api.editor.document.Document;
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent;
import org.eclipse.che.ide.api.editor.text.TextPosition;
import org.eclipse.che.ide.dto.DtoFactory;
import org.eclipse.che.plugin.languageserver.ide.service.TextDocumentServiceClient;
import org.eclipse.lsp4j.DidChangeTextDocumentParams;
@ -41,8 +40,7 @@ class FullTextDocumentSynchronize implements TextDocumentSynchronize {
}
@Override
public void syncTextDocument(DocumentChangeEvent event, int version) {
Document document = event.getDocument().getDocument();
public void syncTextDocument(Document document, TextPosition start, TextPosition end, String insertedText, int version) {
DidChangeTextDocumentParams changeDTO = dtoFactory.createDto(DidChangeTextDocumentParams.class);
String uri = document.getFile().getLocation().toString();
@ -53,7 +51,7 @@ class FullTextDocumentSynchronize implements TextDocumentSynchronize {
changeDTO.setTextDocument(versionedDocId);
TextDocumentContentChangeEvent actualChange = dtoFactory.createDto(TextDocumentContentChangeEvent.class);
actualChange.setText(event.getDocument().getDocument().getContents());
actualChange.setText(document.getContents());
changeDTO.setContentChanges(Collections.singletonList(actualChange));
textDocumentService.didChange(changeDTO);
}

View File

@ -12,9 +12,7 @@ package org.eclipse.che.plugin.languageserver.ide.editor.sync;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.che.ide.api.editor.document.Document;
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent;
import org.eclipse.che.ide.api.editor.text.TextPosition;
import org.eclipse.che.ide.dto.DtoFactory;
import org.eclipse.che.plugin.languageserver.ide.service.TextDocumentServiceClient;
@ -44,16 +42,7 @@ class IncrementalTextDocumentSynchronize implements TextDocumentSynchronize {
}
@Override
public void syncTextDocument(DocumentChangeEvent event, int version) {
Document document = event.getDocument().getDocument();
TextPosition startPosition = document.getPositionFromIndex(event.getOffset());
TextPosition endPosition;
if (event.getRemoveCharCount() != 0) {
endPosition = new TextPosition(startPosition.getLine(), startPosition.getCharacter() + event.getRemoveCharCount());
} else {
endPosition = new TextPosition(startPosition.getLine(), startPosition.getCharacter());
}
public void syncTextDocument(Document document, TextPosition startPosition, TextPosition endPosition, String insertedText, int version) {
DidChangeTextDocumentParams changeDTO = dtoFactory.createDto(DidChangeTextDocumentParams.class);
String uri = document.getFile().getLocation().toString();
changeDTO.setUri(uri);
@ -74,7 +63,7 @@ class IncrementalTextDocumentSynchronize implements TextDocumentSynchronize {
TextDocumentContentChangeEvent actualChange = dtoFactory.createDto(TextDocumentContentChangeEvent.class);
actualChange.setRange(range);
actualChange.setText(event.getText());
actualChange.setText(insertedText);
changeDTO.setContentChanges(Collections.singletonList(actualChange));
textDocumentService.didChange(changeDTO);

View File

@ -10,7 +10,8 @@
*******************************************************************************/
package org.eclipse.che.plugin.languageserver.ide.editor.sync;
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent;
import org.eclipse.che.ide.api.editor.document.Document;
import org.eclipse.che.ide.api.editor.text.TextPosition;
/**
* Handle TextDocument synchronization
@ -18,5 +19,5 @@ import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent;
* @author Evgen Vidolob
*/
public interface TextDocumentSynchronize {
void syncTextDocument(DocumentChangeEvent event, int version);
void syncTextDocument(Document document, TextPosition start, TextPosition end, String insertedText, int version);
}

View File

@ -12,8 +12,8 @@ package org.eclipse.che.plugin.languageserver.ide.editor.sync;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent;
import org.eclipse.che.ide.api.editor.document.Document;
import org.eclipse.che.ide.api.editor.text.TextPosition;
import org.eclipse.lsp4j.TextDocumentSyncKind;
/**
@ -56,8 +56,8 @@ public class TextDocumentSynchronizeFactory {
private static class NoneSynchronize implements TextDocumentSynchronize {
@Override
public void syncTextDocument(DocumentChangeEvent event, int version) {
//no implementation
public void syncTextDocument(Document document, TextPosition start, TextPosition end, String insertedText, int version) {
// no-op implementation
}
}
}