use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.
the class RepositoryExplorerDialog method exportTransformations.
public void exportTransformations(RepositoryDirectoryInterface root) {
try {
DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN);
if (dialog.open() != null) {
String directory = dialog.getFilterPath();
ObjectId[] dirids = ((root == null) ? directoryTree : root).getDirectoryIDs();
for (int d = 0; d < dirids.length; d++) {
RepositoryDirectoryInterface repdir = directoryTree.findDirectory(dirids[d]);
String[] trans = rep.getTransformationNames(dirids[d], false);
// See if the directory exists...
File dir = new File(directory + repdir.getPath());
if (!dir.exists()) {
dir.mkdir();
log.logBasic("Exporting transformation", "Created directory [" + dir.getName() + "]");
}
for (int i = 0; i < trans.length; i++) {
// reads last version
TransMeta ti = rep.loadTransformation(trans[i], repdir, null, true, null);
if (log.isBasic()) {
log.logBasic("Exporting transformation", "[" + trans[i] + "] in directory [" + repdir.getPath() + "]");
}
String xml = XMLHandler.getXMLHeader() + ti.getXML();
String filename = directory + repdir.getPath() + Const.FILE_SEPARATOR + fixFileName(trans[i]) + ".ktr";
File f = new File(filename);
try {
FileOutputStream fos = new FileOutputStream(f);
fos.write(xml.getBytes(Const.XML_ENCODING));
fos.close();
} catch (IOException e) {
throw new RuntimeException("Exporting transformation: Couldn't create file [" + filename + "]", e);
}
}
}
}
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.ExportTrans.UnexpectedError.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.ExportTrans.UnexpectedError.Message"), e);
}
}
use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.
the class RepositoryExplorerDialog method moveJob.
public boolean moveJob(String xml, RepositoryDirectoryInterface repdir) {
debug = "Move Job";
boolean retval = false;
try {
debug = "parse xml";
Document doc = XMLHandler.loadXMLString(xml);
String dirname = XMLHandler.getTagValue(doc, "dragdrop", "directory");
String jobname = XMLHandler.getTagValue(doc, "dragdrop", "job");
if (dirname != null && jobname != null) {
debug = "dirname=" + dirname + ", jobname=" + jobname;
// OK, find this transformation...
RepositoryDirectoryInterface fromdir = directoryTree.findDirectory(dirname);
if (fromdir != null) {
debug = "fromdir found: move job!";
ObjectId existingjobID = rep.getJobId(jobname, repdir);
if (existingjobID == null) {
ObjectId id = rep.getJobId(jobname, fromdir);
rep.renameJob(id, repdir, jobname);
retval = true;
} else {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Job.Move.ErrorDuplicate.Message", jobname) + Const.CR);
mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Job.Move.ErrorDuplicate.Title"));
mb.open();
}
} else {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Job.Move.ErrorMoving.Message") + dirname + "]" + Const.CR);
mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Job.Move.ErrorMoving.Title"));
mb.open();
}
}
} catch (Exception dbe) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Job.Move.UnexpectedError.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Move.UnexpectedError.Message"), dbe);
}
return retval;
}
use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.
the class RepositoryExplorerDialog method doDoubleClick.
public void doDoubleClick() {
final TreeItem[] tisel = wTree.getSelection();
if (tisel.length == 1 || sameCategory(tisel)) {
final TreeItem ti = tisel[0];
final int level = ConstUI.getTreeLevel(ti);
int cat = getItemCategory(ti);
if ((level >= 2) && ((cat == ITEM_CATEGORY_JOB_DIRECTORY) || (cat == ITEM_CATEGORY_TRANSFORMATION_DIRECTORY) || (cat == ITEM_CATEGORY_JOB) || (cat == ITEM_CATEGORY_TRANSFORMATION))) {
String[] realpath;
if ((cat == ITEM_CATEGORY_JOB_DIRECTORY) || (cat == ITEM_CATEGORY_TRANSFORMATION_DIRECTORY)) {
// The first levels of path[] don't belong to the path to this directory!
realpath = new String[level - 1];
} else {
// The first 3 levels of path[] don't belong to the path to this transformation or Job!
realpath = new String[level - 2];
}
final String[] path = ConstUI.getTreeStrings(ti);
for (int i = 0; i < realpath.length; i++) {
realpath[i] = path[i + 2];
}
// Find the directory in the directory tree...
final RepositoryDirectoryInterface repdir = directoryTree.findDirectory(realpath);
switch(cat) {
case ITEM_CATEGORY_JOB_DIRECTORY:
case ITEM_CATEGORY_TRANSFORMATION_DIRECTORY:
{
if (!readonly) {
createDirectory(ti, repdir);
}
break;
}
case ITEM_CATEGORY_TRANSFORMATION:
{
openTransformation(ti.getText(), repdir);
break;
}
case ITEM_CATEGORY_JOB:
{
openJob(ti.getText(), repdir);
break;
}
default:
}
}
}
}
use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.
the class RepositoryExplorerDialog method renameInTree.
public void renameInTree() {
TreeItem[] ti = wTree.getSelection();
if (ti.length == 1) {
// Get the parent.
final TreeItem item = ti[0];
int level = ConstUI.getTreeLevel(item);
String[] text = ConstUI.getTreeStrings(item);
int cat = getItemCategory(item);
switch(cat) {
case ITEM_CATEGORY_DATABASE:
renameDatabase();
break;
case ITEM_CATEGORY_TRANSFORMATION:
String name = item.getText();
// The first 3 levels of text[] don't belong to the path to this transformation!
String[] path = new String[level - 2];
for (int i = 0; i < path.length; i++) {
path[i] = text[i + 2];
}
// Find the directory in the directory tree...
RepositoryDirectoryInterface repdir = directoryTree.findDirectory(path);
if (repdir != null) {
renameTransformation(name, repdir);
}
break;
case ITEM_CATEGORY_JOB:
name = item.getText();
// The first 3 levels of text[] don't belong to the path to this transformation!
path = new String[level - 2];
for (int i = 0; i < path.length; i++) {
path[i] = text[i + 2];
}
// Find the directory in the directory tree...
repdir = directoryTree.findDirectory(path);
if (repdir != null) {
renameJob(name, repdir);
}
break;
case ITEM_CATEGORY_USER:
renameUser();
break;
default:
break;
}
}
}
use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.
the class RepositoryExplorerDialog method open.
public RepositoryObjectReference open() {
debug = "opening repository explorer";
try {
debug = "open new independent shell";
Shell parent = getParent();
Display display = parent.getDisplay();
shell = new Shell(display, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
props.setLook(shell);
shell.setImage(GUIResource.getInstance().getImageFolderConnections());
shell.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Title") + rep.getName() + "]");
FormLayout formLayout = new FormLayout();
formLayout.marginWidth = Const.FORM_MARGIN;
formLayout.marginHeight = Const.FORM_MARGIN;
shell.setLayout(formLayout);
// Add a small toolbar to expand/collapse all items
//
ToolBar treeTb = new ToolBar(shell, SWT.HORIZONTAL | SWT.FLAT);
props.setLook(treeTb);
fdTreeTb = new FormData();
fdTreeTb.left = new FormAttachment(0, 0);
fdTreeTb.top = new FormAttachment(0, 0);
treeTb.setLayoutData(fdTreeTb);
// Add the items...
//
exportToXML = new ToolItem(treeTb, SWT.PUSH);
exportToXML.setImage(GUIResource.getInstance().getImageExport());
exportToXML.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ExportToXML.Label"));
exportToXML.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ExportToXML.Tooltip"));
importFromXML = new ToolItem(treeTb, SWT.PUSH);
importFromXML.setImage(GUIResource.getInstance().getImageImport());
importFromXML.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ImportFromXML.Label"));
importFromXML.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ImportFromXML.Tooltip"));
new ToolItem(treeTb, SWT.SEPARATOR);
showHideDeleted = new ToolItem(treeTb, SWT.PUSH);
showHideDeleted.setImage(GUIResource.getInstance().getImageShowDeleted());
showHideDeleted.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ShowDeleted.Label"));
showHideDeleted.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ShowDeleted.Tooltip"));
showHideDeleted.setEnabled(rep.getRepositoryMeta().getRepositoryCapabilities().supportsRevisions());
new ToolItem(treeTb, SWT.SEPARATOR);
expandAll = new ToolItem(treeTb, SWT.PUSH);
expandAll.setImage(GUIResource.getInstance().getImageExpandAll());
expandAll.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ExpandAll.Label"));
expandAll.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ExpandAll.Tooltip"));
collapseAll = new ToolItem(treeTb, SWT.PUSH);
collapseAll.setImage(GUIResource.getInstance().getImageCollapseAll());
collapseAll.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.CollapseAll.Label"));
collapseAll.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.CollapseAll.Tooltip"));
// Tree
wTree = new Tree(shell, SWT.MULTI | SWT.BORDER);
wTree.setHeaderVisible(true);
props.setLook(wTree);
// Add some columns to it as well...
nameColumn = new TreeColumn(wTree, SWT.LEFT);
nameColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.Name"));
nameColumn.setWidth(350);
nameColumn.setAlignment(10);
nameColumn.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
setSort(0);
}
});
// No sorting on the type column just yet.
typeColumn = new TreeColumn(wTree, SWT.LEFT);
typeColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.Type"));
typeColumn.setWidth(100);
typeColumn.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
setSort(1);
}
});
userColumn = new TreeColumn(wTree, SWT.LEFT);
userColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.User"));
userColumn.setWidth(100);
userColumn.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
setSort(2);
}
});
changedColumn = new TreeColumn(wTree, SWT.LEFT);
changedColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.Changed"));
changedColumn.setWidth(120);
changedColumn.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
setSort(3);
}
});
descriptionColumn = new TreeColumn(wTree, SWT.LEFT);
descriptionColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.Description"));
descriptionColumn.setWidth(120);
descriptionColumn.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
setSort(4);
}
});
lockColumn = new TreeColumn(wTree, SWT.LEFT);
lockColumn.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Column.LockMessage"));
lockColumn.setWidth(120);
lockColumn.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
setSort(5);
}
});
// Add a memory to the tree.
TreeMemory.addTreeListener(wTree, STRING_REPOSITORY_EXPLORER_TREE_NAME);
// Buttons
wOK = new Button(shell, SWT.PUSH);
wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
FormData fdTree = new FormData();
int margin = 10;
// To the right of the label
fdTree.left = new FormAttachment(0, 0);
fdTree.top = new FormAttachment(treeTb, 0);
fdTree.right = new FormAttachment(100, 0);
fdTree.bottom = new FormAttachment(100, -50);
wTree.setLayoutData(fdTree);
BaseStepDialog.positionBottomButtons(shell, new Button[] { wOK }, margin, null);
// Add listeners
wOK.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
close();
}
});
wTree.addMenuDetectListener(new MenuDetectListener() {
@Override
public void menuDetected(MenuDetectEvent e) {
setTreeMenu();
}
});
wTree.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
if (e.button == 1) {
// left double click!
doDoubleClick();
}
}
});
wTree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
// F2 --> rename...
if (e.keyCode == SWT.F2) {
if (!readonly) {
renameInTree();
}
}
// F5 --> refresh...
if (e.keyCode == SWT.F5) {
refreshTree();
}
}
});
expandAll.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
expandAllItems(wTree.getItems(), true);
}
});
collapseAll.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
expandAllItems(wTree.getItems(), false);
}
});
importFromXML.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
importAll();
}
});
exportToXML.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
exportAll(null);
}
});
showHideDeleted.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
includeDeleted = !includeDeleted;
if (includeDeleted) {
showHideDeleted.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.HideDeleted.Label"));
showHideDeleted.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.HideDeleted.Tooltip"));
} else {
showHideDeleted.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ShowDeleted.Label"));
showHideDeleted.setToolTipText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.ToolItem.ShowDeleted.Tooltip"));
}
refreshTree();
}
});
// Drag & Drop
Transfer[] ttypes = new Transfer[] { TextTransfer.getInstance() };
DragSource ddSource = new DragSource(wTree, DND.DROP_MOVE);
ddSource.setTransfer(ttypes);
ddSource.addDragListener(new DragSourceListener() {
@Override
public void dragStart(DragSourceEvent event) {
debug = "drag start";
event.doit = true;
}
@Override
public void dragSetData(DragSourceEvent event) {
debug = "drag set data";
event.data = "";
event.doit = false;
TreeItem[] ti = wTree.getSelection();
if (ti.length >= 1) {
int cat = getItemCategory(ti[0]);
//
if (cat == ITEM_CATEGORY_TRANSFORMATION) {
debug = "drag set: drag around transformation";
RepositoryDirectoryInterface repdir = getDirectory(ti[0]);
if (repdir != null) {
//
// Pass info as a piece of XML
//
String xml = XMLHandler.getXMLHeader();
xml += "<dragdrop>" + Const.CR;
xml += " " + XMLHandler.addTagValue("directory", repdir.getPath());
xml += " " + XMLHandler.addTagValue("transformation", ti[0].getText());
xml += "</dragdrop>" + Const.CR;
event.data = xml;
event.doit = true;
}
} else if (cat == ITEM_CATEGORY_JOB) {
debug = "drag set: drag around job";
RepositoryDirectoryInterface repdir = getDirectory(ti[0]);
if (repdir != null) {
//
// Pass info as a piece of XML
//
String xml = XMLHandler.getXMLHeader();
xml += "<dragdrop>" + Const.CR;
xml += " " + XMLHandler.addTagValue("directory", repdir.getPath());
xml += " " + XMLHandler.addTagValue("job", ti[0].getText());
xml += "</dragdrop>" + Const.CR;
event.data = xml;
event.doit = true;
}
} else {
debug = "do nothing";
String xml = XMLHandler.getXMLHeader();
xml += "<dragdrop>" + Const.CR;
xml += "</dragdrop>" + Const.CR;
event.data = xml;
event.doit = true;
}
}
}
@Override
public void dragFinished(DragSourceEvent event) {
}
});
DropTarget ddTarget = new DropTarget(wTree, DND.DROP_MOVE);
ddTarget.setTransfer(ttypes);
ddTarget.addDropListener(new DropTargetListener() {
@Override
public void dragEnter(DropTargetEvent event) {
}
@Override
public void dragLeave(DropTargetEvent event) {
debug = "drag leave";
}
@Override
public void dragOperationChanged(DropTargetEvent event) {
}
@Override
public void dragOver(DropTargetEvent event) {
debug = "drag over";
}
@Override
public void drop(DropTargetEvent event) {
try {
debug = "Drop item in tree";
if (event.data == null) {
// no data to copy, indicate failure in event.detail
event.detail = DND.DROP_NONE;
return;
}
// event.feedback = DND.FEEDBACK_NONE;
TreeItem ti = (TreeItem) event.item;
if (ti != null) {
debug = "Get category";
int category = getItemCategory(ti);
if (category == ITEM_CATEGORY_TRANSFORMATION_DIRECTORY || category == ITEM_CATEGORY_TRANSFORMATION) {
debug = "Get directory";
RepositoryDirectoryInterface repdir = getDirectory(ti);
if (repdir != null) {
event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
if (moveTransformation((String) event.data, repdir)) {
refreshTree();
} else {
MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Move.UnableToMove.Message"));
mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Move.UnableToMove.Title"));
mb.open();
}
}
} else if (category == ITEM_CATEGORY_JOB_DIRECTORY || category == ITEM_CATEGORY_JOB) {
debug = "Get directory";
RepositoryDirectoryInterface repdir = getDirectory(ti);
if (repdir != null) {
event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
if (moveJob((String) event.data, repdir)) {
refreshTree();
} else {
MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Job.Move.UnableToMove.Message"));
mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Job.Move.UnableToMove.Title"));
mb.open();
}
}
} else {
MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Move.SorryOneItemAtATime.Message"));
mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Trans.Move.SorryOneItemAtATime.Title"));
mb.open();
}
}
} catch (Throwable e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Drop.UnexpectedError.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Drop.UnexpectedError.Message1") + debug + "]" + Const.CR + BaseMessages.getString(PKG, "RepositoryExplorerDialog.Drop.UnexpectedError.Message2"), e);
}
}
@Override
public void dropAccept(DropTargetEvent event) {
debug = "drop accept";
}
});
// Detect X or ALT-F4 or something that kills this window...
shell.addShellListener(new ShellAdapter() {
@Override
public void shellClosed(ShellEvent e) {
close();
}
});
debug = "set screen size and position";
BaseStepDialog.setSize(shell, 400, 480, true);
// refreshes too.
setSort(0);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
} catch (Throwable e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Main.UnexpectedError.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Main.UnexpectedError.Message1") + debug + "]" + Const.CR + BaseMessages.getString(PKG, "RepositoryExplorerDialog.Main.UnexpectedError.Message2") + Const.CR + BaseMessages.getString(PKG, "RepositoryExplorerDialog.Main.UnexpectedError.Message3"), e);
}
return lastOpened;
}
Aggregations