use of org.pentaho.di.ui.repository.pur.repositoryexplorer.IRevisionObject in project pentaho-kettle by pentaho.
the class RevisionController method createBindings.
private void createBindings() {
// $NON-NLS-1$
filePropertiesTabbox = (XulTabbox) document.getElementById("file-properties-tabs");
// $NON-NLS-1$
historyTab = (XulTab) document.getElementById("history");
// $NON-NLS-1$
revisionTable = (XulTree) document.getElementById("revision-table");
// $NON-NLS-1$
folderTree = (XulTree) document.getElementById("folder-tree");
// $NON-NLS-1$
fileTable = (XulTree) document.getElementById("file-table");
// Hide the history tab if versioning is off
historyTab.setVisible(false);
bf.setBindingType(Binding.Type.ONE_WAY);
BindingConvertor<int[], Boolean> forButtons = new BindingConvertor<int[], Boolean>() {
@Override
public Boolean sourceToTarget(int[] value) {
return value != null && !(value.length <= 0);
}
@Override
public int[] targetToSource(Boolean value) {
return null;
}
};
Binding openButtonBinding = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
bf.createBinding(revisionTable, "selectedRows", OPEN_REVISION_BUTTON, "!disabled", forButtons);
Binding restoreButtonBinding = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
bf.createBinding(revisionTable, "selectedRows", RESTORE_REVISION_BUTTON, "!disabled", forButtons);
bf.setBindingType(Binding.Type.ONE_WAY);
// $NON-NLS-1$ //$NON-NLS-2$
bf.createBinding(folderTree, "selectedItems", this, "historyTabVisibility");
// $NON-NLS-1$ //$NON-NLS-2$
revisionBinding = bf.createBinding(this, "revisionObjects", revisionTable, "elements");
revisionBinding = // $NON-NLS-1$ //$NON-NLS-2$
bf.createBinding(// $NON-NLS-1$ //$NON-NLS-2$
browseController, // $NON-NLS-1$ //$NON-NLS-2$
"repositoryItems", // $NON-NLS-1$ //$NON-NLS-2$
this, // $NON-NLS-1$ //$NON-NLS-2$
"revisionObjects", new BindingConvertor<List<UIRepositoryObject>, UIRepositoryObjectRevisions>() {
private void disableButtons() {
document.getElementById(OPEN_REVISION_BUTTON).setDisabled(true);
document.getElementById(RESTORE_REVISION_BUTTON).setDisabled(true);
}
@Override
public UIRepositoryObjectRevisions sourceToTarget(List<UIRepositoryObject> ro) {
if (ro == null || ro.isEmpty() || !masterVersioningEnabled) {
return new UIRepositoryObjectRevisions();
}
if (ro.get(0) instanceof UIRepositoryDirectory) {
historyTab.setVisible(false);
filePropertiesTabbox.setSelectedIndex(0);
disableButtons();
return null;
}
UIRepositoryObjectRevisions revisions = null;
try {
UIRepositoryContent rc = (UIRepositoryContent) ro.get(0);
if (rc instanceof IRevisionObject) {
Boolean versioningEnabled = ((IRevisionObject) rc).getVersioningEnabled();
// Show/hide the Verison History tab
historyTab.setVisible(versioningEnabled);
if (!versioningEnabled) {
return new UIRepositoryObjectRevisions();
}
Boolean versionCommentEnabled = ((IRevisionObject) rc).getVersionCommentEnabled();
// Show/Hide the version comment column
setRevisionTableColumns(versionCommentEnabled);
revisions = ((IRevisionObject) rc).getRevisions();
} else {
throw new IllegalStateException(BaseMessages.getString(PKG, // $NON-NLS-1$
"RevisionsController.RevisionsNotSupported"));
}
} catch (KettleException e) {
if (mainController == null || !mainController.handleLostRepository(e)) {
// convert to runtime exception so it bubbles up through the UI
throw new RuntimeException(e);
}
}
return revisions;
}
@Override
public List<UIRepositoryObject> targetToSource(UIRepositoryObjectRevisions elements) {
return null;
}
});
try {
openButtonBinding.fireSourceChanged();
restoreButtonBinding.fireSourceChanged();
revisionBinding.fireSourceChanged();
} catch (Exception e) {
if (mainController == null || !mainController.handleLostRepository(e)) {
// convert to runtime exception so it bubbles up through the UI
throw new RuntimeException(e);
}
}
}
use of org.pentaho.di.ui.repository.pur.repositoryexplorer.IRevisionObject in project pentaho-kettle by pentaho.
the class RevisionController method restoreRevision.
public void restoreRevision() {
try {
final Collection<UIRepositoryContent> content = fileTable.getSelectedItems();
final UIRepositoryContent contentToRestore = content.iterator().next();
Collection<UIRepositoryObjectRevision> versions = revisionTable.getSelectedItems();
final UIRepositoryObjectRevision versionToRestore = versions.iterator().next();
SwtConfirmBox confirmbox = promptCommitComment(document);
if (contentToRestore instanceof ILockObject && ((ILockObject) contentToRestore).isLocked()) {
// Cannot restore revision of locked content
// $NON-NLS-1$
messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
// $NON-NLS-1$
messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
// $NON-NLS-1$
messageBox.setMessage(BaseMessages.getString(PKG, "RevisionsController.RestoreLockedFileNotAllowed"));
messageBox.open();
return;
}
confirmbox.addDialogCallback(new XulDialogCallback<String>() {
public void onClose(XulComponent component, Status status, String value) {
if (!status.equals(Status.CANCEL)) {
try {
if (contentToRestore instanceof IRevisionObject) {
((IRevisionObject) contentToRestore).restoreRevision(versionToRestore, value);
List<UIRepositoryObject> objects = new ArrayList<UIRepositoryObject>();
objects.add(contentToRestore);
browseController.setRepositoryObjects(objects);
} else {
throw new IllegalStateException(BaseMessages.getString(PKG, // $NON-NLS-1$
"RevisionsController.RevisionsNotSupported"));
}
} catch (Exception e) {
if (mainController == null || !mainController.handleLostRepository(e)) {
// convert to runtime exception so it bubbles up through the UI
throw new RuntimeException(e);
}
}
}
}
public void onError(XulComponent component, Throwable err) {
if (mainController == null || !mainController.handleLostRepository(err)) {
throw new RuntimeException(err);
}
}
});
confirmbox.open();
} catch (Exception e) {
if (mainController == null || !mainController.handleLostRepository(e)) {
throw new RuntimeException(new KettleException(e));
}
}
}
Aggregations