Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RHBA-415: After rename, designer is not marked as dirty more #275

Merged
merged 1 commit into from
Apr 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public boolean equals(Object o) {

final Path path = (Path) o;

return uri.equals(path.toURI());
return this.toURI().equals(path.toURI());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2018 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.uberfire.client.mvp;

import org.uberfire.backend.vfs.Path;

/**
* Client-local event to indicate that a rename command has been executed
*/
public class RenameInProgressEvent {

private final Path path;

public RenameInProgressEvent(final Path path) {
this.path = path;
}

public Path getPath() {
return path;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;

import javax.enterprise.event.Event;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
Expand All @@ -33,6 +34,7 @@
import org.jboss.errai.ioc.client.api.ManagedInstance;
import org.uberfire.backend.vfs.ObservablePath;
import org.uberfire.backend.vfs.Path;
import org.uberfire.client.callbacks.Callback;
import org.uberfire.client.mvp.PlaceManager;
import org.uberfire.client.workbench.events.ChangeTitleWidgetEvent;
import org.uberfire.client.workbench.type.ClientResourceType;
Expand Down Expand Up @@ -122,6 +124,7 @@ public abstract class BaseEditor<T, M> {
protected Integer originalHash;
protected Integer metadataOriginalHash;
private boolean displayShowMoreVersions;
private ObservablePath path;

//for test purposes only
BaseEditor(VersionRecordManager versionRecordManager,
Expand Down Expand Up @@ -174,6 +177,7 @@ protected void init(final ObservablePath path,
final boolean addFileChangeListeners,
final boolean displayShowMoreVersions,
final Collection<MenuItems> menuItems) {
this.path = path;
this.place = place;
this.type = type;
this.menuItems.addAll(menuItems);
Expand Down Expand Up @@ -422,38 +426,33 @@ public void execute() {
});
}

/**
* Effectively the same as reload() but don't reset concurrentUpdateSessionInfo
*/
protected void onRename() {
refreshTitle();
baseView.showBusyIndicator(CommonConstants.INSTANCE.Loading());
loadContent();
changeTitleNotification.fire(new ChangeTitleWidgetEvent(place,
getTitleText(),
getTitle()));
versionRecordManager.init(
this.place.getParameter("version",
null),
versionRecordManager.getCurrentPath(),
this::selectVersion);
reload(path);
}

/**
* Override this method and use @WorkbenchPartTitleDecoration
* @return The widget for the title
*/
protected IsWidget getTitle() {
refreshTitle();
refreshTitle(versionRecordManager.getCurrentPath());
return getTitleWidget();
}

EditorTitle getTitleWidget() {
return baseView.getTitleWidget();
}

public String getTitleText() {
return versionRecordManager.getCurrentPath().getFileName() + " - " + type.getDescription();
return getTitleText(versionRecordManager.getCurrentPath());
}

private void refreshTitle() {
baseView.refreshTitle(getTitleText());
String getTitleText(final ObservablePath observablePath) {
return observablePath.getFileName() + " - " + getType().getDescription();
}

ClientResourceType getType() {
return type;
}

protected void onSave() {
Expand Down Expand Up @@ -518,12 +517,55 @@ public void onRestore(@Observes RestoreEvent restore) {

public void reload() {
concurrentUpdateSessionInfo = null;
refreshTitle();
baseView.showBusyIndicator(CommonConstants.INSTANCE.Loading());
reload(versionRecordManager.getCurrentPath());
}

void reload(final ObservablePath path) {
refreshTitle(path);
showBusyIndicator();
loadContent();
changeTitleNotification.fire(new ChangeTitleWidgetEvent(place,
getTitleText(),
getTitle()));
notifyChangeTitle(path);
initVersionRecordManager();
}

void refreshTitle(final ObservablePath observablePath) {
baseView.refreshTitle(getTitleText(observablePath));
}

void showBusyIndicator() {
baseView.showBusyIndicator(makeLoading());
}

String makeLoading() {
return CommonConstants.INSTANCE.Loading();
}

void notifyChangeTitle(final ObservablePath path) {
changeTitleNotification.fire(makeChangeTitleWidgetEvent(path));
}

ChangeTitleWidgetEvent makeChangeTitleWidgetEvent(final ObservablePath path) {

final String titleText = getTitleText(path);
final EditorTitle titleWidget = getTitleWidget();

return new ChangeTitleWidgetEvent(getPlace(), titleText, titleWidget);
}

void initVersionRecordManager() {

final String version = getPlace().getParameter("version", null);
final Callback<VersionRecord> selectVersion = getSelectVersion();

versionRecordManager.init(version, versionRecordManager.getCurrentPath(), selectVersion);
}

Callback<VersionRecord> getSelectVersion() {
return this::selectVersion;
}

PlaceRequest getPlace() {
return place;
}

void disableMenus() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.jboss.errai.common.client.api.Caller;
import org.jboss.errai.common.client.api.RemoteCallback;
import org.uberfire.backend.vfs.Path;
import org.uberfire.client.mvp.RenameInProgressEvent;
import org.uberfire.ext.editor.commons.client.file.CommandWithFileNameAndCommitMessage;
import org.uberfire.ext.editor.commons.client.file.FileNameAndCommitMessage;
import org.uberfire.ext.editor.commons.client.file.popups.RenamePopUpPresenter;
Expand All @@ -47,6 +48,7 @@ public class SaveAndRenameCommandBuilder<T, M> {
private final RenamePopUpPresenter renamePopUpPresenter;
private final BusyIndicatorView busyIndicatorView;
private final Event<NotificationEvent> notification;
private final Event<RenameInProgressEvent> renameInProgressEvent;

private Supplier<Path> pathSupplier;
private Validator renameValidator;
Expand All @@ -64,11 +66,13 @@ public class SaveAndRenameCommandBuilder<T, M> {
@Inject
public SaveAndRenameCommandBuilder(final RenamePopUpPresenter renamePopUpPresenter,
final BusyIndicatorView busyIndicatorView,
final Event<NotificationEvent> notification) {
final Event<NotificationEvent> notification,
final Event<RenameInProgressEvent> renameInProgressEvent) {

this.renamePopUpPresenter = renamePopUpPresenter;
this.busyIndicatorView = busyIndicatorView;
this.notification = notification;
this.renameInProgressEvent = renameInProgressEvent;
}

public SaveAndRenameCommandBuilder<T, M> addValidator(final Validator validator) {
Expand Down Expand Up @@ -138,15 +142,13 @@ public Command build() {

CommandWithFileNameAndCommitMessage makeSaveAndRenameCommand() {
return (details) -> {

showBusyIndicator();
callSaveAndRename(details);
};
}

CommandWithFileNameAndCommitMessage makeRenameCommand() {
return (details) -> {

showBusyIndicator();
callRename(details);
};
Expand Down Expand Up @@ -176,13 +178,22 @@ void callRename(final FileNameAndCommitMessage details) {

RemoteCallback<Path> onSuccess() {
return (Path path) -> {
notifyRenameInProgress();
onSuccess.execute(path);
hideRenamePopup();
hideBusyIndicator();
notifyItemRenamedSuccessfully();
};
}

void notifyRenameInProgress() {
renameInProgressEvent.fire(makeRenameInProgressEvent());
}

RenameInProgressEvent makeRenameInProgressEvent() {
return new RenameInProgressEvent(getPath());
}

SaveAndRenameErrorCallback onError() {
return new SaveAndRenameErrorCallback(busyIndicatorView);
}
Expand Down Expand Up @@ -219,7 +230,7 @@ private boolean fileAlreadyExists(final Throwable throwable) {
return throwable != null && throwable.getMessage() != null && throwable.getMessage().contains("FileAlreadyExistsException");
}

private Path getPath() {
Path getPath() {
return pathSupplier.get();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected void loadContent() {

@Override
protected SaveAndRenameCommandBuilder getSaveAndRenameCommandBuilder() {
return new SaveAndRenameCommandBuilder<>(null, null, null);
return new SaveAndRenameCommandBuilder<>(null, null, null, null);
}

@Override
Expand Down