use of org.pentaho.di.core.gui.Point in project pentaho-kettle by pentaho.
the class AbstractMetaTest method testNotes.
@Test
public void testNotes() throws Exception {
assertNull(meta.getNotes());
// most note methods will NPE at this point, so call clear() to create an empty note list
meta.clear();
assertNotNull(meta.getNotes());
assertTrue(meta.getNotes().isEmpty());
// Can't get a note from an empty list (i.e. no indices)
Exception e = null;
try {
assertNull(meta.getNote(0));
} catch (IndexOutOfBoundsException ioobe) {
e = ioobe;
}
assertNotNull(e);
assertNull(meta.getNote(20, 20));
NotePadMeta note1 = mock(NotePadMeta.class);
meta.removeNote(0);
assertFalse(meta.hasChanged());
meta.addNote(note1);
assertTrue(meta.hasChanged());
NotePadMeta note2 = mock(NotePadMeta.class);
when(note2.getLocation()).thenReturn(new Point(0, 0));
when(note2.isSelected()).thenReturn(true);
meta.addNote(1, note2);
assertEquals(note2, meta.getNote(0, 0));
List<NotePadMeta> selectedNotes = meta.getSelectedNotes();
assertNotNull(selectedNotes);
assertEquals(1, selectedNotes.size());
assertEquals(note2, selectedNotes.get(0));
assertEquals(1, meta.indexOfNote(note2));
meta.removeNote(2);
assertEquals(2, meta.nrNotes());
meta.removeNote(1);
assertEquals(1, meta.nrNotes());
assertTrue(meta.haveNotesChanged());
meta.clearChanged();
assertFalse(meta.haveNotesChanged());
meta.addNote(1, note2);
meta.lowerNote(1);
assertTrue(meta.haveNotesChanged());
meta.clearChanged();
assertFalse(meta.haveNotesChanged());
meta.raiseNote(0);
assertTrue(meta.haveNotesChanged());
meta.clearChanged();
assertFalse(meta.haveNotesChanged());
int[] indexes = meta.getNoteIndexes(Arrays.asList(note1, note2));
assertNotNull(indexes);
assertEquals(2, indexes.length);
}
use of org.pentaho.di.core.gui.Point in project pentaho-kettle by pentaho.
the class GetJobStatusServlet method doGet.
/**
* <div id="mindtouch">
* <h1>/kettle/jobStatus</h1>
* <a name="GET"></a>
* <h2>GET</h2>
* <p>Retrieves status of the specified job.
* Status is returned as HTML or XML output depending on the input parameters.
* Status contains information about last execution of the job.</p>
*
* <p><b>Example Request:</b><br />
* <pre function="syntax.xml">
* GET /kettle/jobStatus/?name=dummy_job&xml=Y
* </pre>
*
* </p>
* <h3>Parameters</h3>
* <table class="pentaho-table">
* <tbody>
* <tr>
* <th>name</th>
* <th>description</th>
* <th>type</th>
* </tr>
* <tr>
* <td>name</td>
* <td>Name of the job to be used for status generation.</td>
* <td>query</td>
* </tr>
* <tr>
* <td>xml</td>
* <td>Boolean flag which defines output format <code>Y</code> forces XML output to be generated.
* HTML is returned otherwise.</td>
* <td>boolean, optional</td>
* </tr>
* <tr>
* <td>id</td>
* <td>Carte id of the job to be used for status generation.</td>
* <td>query, optional</td>
* </tr>
* <tr>
* <td>from</td>
* <td>Start line number of the execution log to be included into response.</td>
* <td>integer, optional</td>
* </tr>
* </tbody>
* </table>
*
* <h3>Response Body</h3>
* <table class="pentaho-table">
* <tbody>
* <tr>
* <td align="right">element:</td>
* <td>(custom)</td>
* </tr>
* <tr>
* <td align="right">media types:</td>
* <td>text/xml, text/html</td>
* </tr>
* </tbody>
* </table>
* <p>Response XML or HTML response containing details about the job specified.
* If an error occurs during method invocation <code>result</code> field of the response
* will contain <code>ERROR</code> status.</p>
*
* <p><b>Example Response:</b></p>
* <pre function="syntax.xml">
* <?xml version="1.0" encoding="UTF-8"?>
* <jobstatus>
* <jobname>dummy_job</jobname>
* <id>a4d54106-25db-41c5-b9f8-73afd42766a6</id>
* <status_desc>Finished</status_desc>
* <error_desc/>
* <logging_string><![CDATA[H4sIAAAAAAAAADMyMDTRNzTUNzRXMDC3MjS2MjJQ0FVIKc3NrYzPyk8CsoNLEotKFPLTFEDc1IrU5NKSzPw8Xi4j4nRm5qUrpOaVFFUqRLuE+vpGxhKj0y0zL7M4IzUFYieybgWNotTi0pwS2+iSotLUWE1iTPNCdrhCGtRsXi4AOMIbLPwAAAA=]]></logging_string>
* <first_log_line_nr>0</first_log_line_nr>
* <last_log_line_nr>20</last_log_line_nr>
* <result>
* <lines_input>0</lines_input>
* <lines_output>0</lines_output>
* <lines_read>0</lines_read>
* <lines_written>0</lines_written>
* <lines_updated>0</lines_updated>
* <lines_rejected>0</lines_rejected>
* <lines_deleted>0</lines_deleted>
* <nr_errors>0</nr_errors>
* <nr_files_retrieved>0</nr_files_retrieved>
* <entry_nr>0</entry_nr>
* <result>Y</result>
* <exit_status>0</exit_status>
* <is_stopped>N</is_stopped>
* <log_channel_id/>
* <log_text>null</log_text>
* <result-file></result-file>
* <result-rows></result-rows>
* </result>
* </jobstatus>
* </pre>
*
* <h3>Status Codes</h3>
* <table class="pentaho-table">
* <tbody>
* <tr>
* <th>code</th>
* <th>description</th>
* </tr>
* <tr>
* <td>200</td>
* <td>Request was processed.</td>
* </tr>
* <tr>
* <td>500</td>
* <td>Internal server error occurs during request processing.</td>
* </tr>
* </tbody>
* </table>
* </div>
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (isJettyMode() && !request.getContextPath().startsWith(CONTEXT_PATH)) {
return;
}
if (log.isDebug()) {
logDebug(BaseMessages.getString(PKG, "GetJobStatusServlet.Log.JobStatusRequested"));
}
String jobName = request.getParameter("name");
String id = request.getParameter("id");
boolean useXML = "Y".equalsIgnoreCase(request.getParameter("xml"));
int startLineNr = Const.toInt(request.getParameter("from"), 0);
response.setStatus(HttpServletResponse.SC_OK);
if (useXML) {
response.setContentType("text/xml");
response.setCharacterEncoding(Const.XML_ENCODING);
} else {
response.setContentType("text/html;charset=UTF-8");
}
// ID is optional...
//
Job job;
CarteObjectEntry entry;
if (Utils.isEmpty(id)) {
// get the first job that matches...
//
entry = getJobMap().getFirstCarteObjectEntry(jobName);
if (entry == null) {
job = null;
} else {
id = entry.getId();
job = getJobMap().getJob(entry);
}
} else {
//
if (Utils.isEmpty(jobName)) {
// Take the ID into account!
//
job = getJobMap().findJob(id);
} else {
entry = new CarteObjectEntry(jobName, id);
job = getJobMap().getJob(entry);
if (job != null) {
jobName = job.getJobname();
}
}
}
if (job != null) {
if (useXML) {
try {
OutputStream out = null;
byte[] data = null;
String logId = job.getLogChannelId();
boolean finishedOrStopped = job.isFinished() || job.isStopped();
if (finishedOrStopped && (data = cache.get(logId, startLineNr)) != null) {
response.setContentLength(XML_HEADER.length + data.length);
out = response.getOutputStream();
out.write(XML_HEADER);
out.write(data);
out.flush();
} else {
int lastLineNr = KettleLogStore.getLastBufferLineNr();
String logText = getLogText(job, startLineNr, lastLineNr);
response.setContentType("text/xml");
response.setCharacterEncoding(Const.XML_ENCODING);
SlaveServerJobStatus jobStatus = new SlaveServerJobStatus(jobName, id, job.getStatus());
jobStatus.setFirstLoggingLineNr(startLineNr);
jobStatus.setLastLoggingLineNr(lastLineNr);
jobStatus.setLogDate(job.getLogDate());
// The log can be quite large at times, we are going to putIfAbsent a base64 encoding around a compressed
// stream
// of bytes to handle this one.
String loggingString = HttpUtil.encodeBase64ZippedString(logText);
jobStatus.setLoggingString(loggingString);
// Also set the result object...
//
// might be null
jobStatus.setResult(job.getResult());
String xml = jobStatus.getXML();
data = xml.getBytes(Charset.forName(Const.XML_ENCODING));
out = response.getOutputStream();
response.setContentLength(XML_HEADER.length + data.length);
out.write(XML_HEADER);
out.write(data);
out.flush();
if (finishedOrStopped && logId != null) {
cache.put(logId, xml, startLineNr);
}
}
response.flushBuffer();
} catch (KettleException e) {
throw new ServletException("Unable to get the job status in XML format", e);
}
} else {
PrintWriter out = response.getWriter();
int lastLineNr = KettleLogStore.getLastBufferLineNr();
response.setContentType("text/html");
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>" + BaseMessages.getString(PKG, "GetJobStatusServlet.KettleJobStatus") + "</TITLE>");
if (EnvUtil.getSystemProperty(Const.KETTLE_CARTE_REFRESH_STATUS, "N").equalsIgnoreCase("Y")) {
out.println("<META http-equiv=\"Refresh\" content=\"10;url=" + convertContextPath(GetJobStatusServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(Const.NVL(jobName, ""), "UTF-8") + "&id=" + URLEncoder.encode(id, "UTF-8") + "\">");
}
out.println("<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
out.println("</HEAD>");
out.println("<BODY>");
out.println("<H1>" + BaseMessages.getString(PKG, "GetJobStatusServlet.JobStatus") + "</H1>");
try {
out.println("<table border=\"1\">");
out.print("<tr> <th>" + BaseMessages.getString(PKG, "GetJobStatusServlet.Jobname") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.TransStatus") + "</th> </tr>");
out.print("<tr>");
out.print("<td>" + Const.NVL(Encode.forHtml(jobName), "") + "</td>");
out.print("<td>" + job.getStatus() + "</td>");
out.print("</tr>");
out.print("</table>");
out.print("<p>");
// Show job image?
//
Point max = job.getJobMeta().getMaximum();
max.x += 20;
max.y += 20;
out.print("<iframe height=\"" + max.y + "\" width=\"" + max.x + "\" seamless src=\"" + convertContextPath(GetJobImageServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(jobName, "UTF-8") + "&id=" + URLEncoder.encode(id, "UTF-8") + "\"></iframe>");
out.print("<p>");
if (job.isFinished()) {
out.print("<a href=\"" + convertContextPath(StartJobServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(Const.NVL(jobName, ""), "UTF-8") + "&id=" + URLEncoder.encode(id, "UTF-8") + "\">" + BaseMessages.getString(PKG, "GetJobStatusServlet.StartJob") + "</a>");
out.print("<p>");
} else {
out.print("<a href=\"" + convertContextPath(StopJobServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(Const.NVL(jobName, ""), "UTF-8") + "&id=" + URLEncoder.encode(id, "UTF-8") + "\">" + BaseMessages.getString(PKG, "GetJobStatusServlet.StopJob") + "</a>");
out.print("<p>");
}
out.println("<p>");
out.print("<a href=\"" + convertContextPath(GetJobStatusServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(Const.NVL(jobName, ""), "UTF-8") + "&xml=y&id=" + URLEncoder.encode(id, "UTF-8") + "\">" + BaseMessages.getString(PKG, "TransStatusServlet.ShowAsXml") + "</a><br>");
out.print("<a href=\"" + convertContextPath(GetStatusServlet.CONTEXT_PATH) + "\">" + BaseMessages.getString(PKG, "TransStatusServlet.BackToStatusPage") + "</a><br>");
out.print("<p><a href=\"" + convertContextPath(GetJobStatusServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(Const.NVL(jobName, ""), "UTF-8") + "&id=" + URLEncoder.encode(id, "UTF-8") + "\">" + BaseMessages.getString(PKG, "TransStatusServlet.Refresh") + "</a>");
// Put the logging below that.
out.println("<p>");
out.println("<textarea id=\"joblog\" cols=\"120\" rows=\"20\" wrap=\"off\" " + "name=\"Job log\" readonly=\"readonly\">" + Encode.forHtml(getLogText(job, startLineNr, lastLineNr)) + "</textarea>");
out.println("<script type=\"text/javascript\"> ");
out.println(" joblog.scrollTop=joblog.scrollHeight; ");
out.println("</script> ");
out.println("<p>");
} catch (Exception ex) {
out.println("<p>");
out.println("<pre>");
out.println(Encode.forHtml(Const.getStackTracker(ex)));
out.println("</pre>");
}
out.println("<p>");
out.println("</BODY>");
out.println("</HTML>");
}
} else {
PrintWriter out = response.getWriter();
if (useXML) {
out.println(new WebResult(WebResult.STRING_ERROR, BaseMessages.getString(PKG, "StartJobServlet.Log.SpecifiedJobNotFound", jobName, id)));
} else {
out.println("<H1>Job " + Encode.forHtml("\'" + jobName + "\'") + " could not be found.</H1>");
out.println("<a href=\"" + convertContextPath(GetStatusServlet.CONTEXT_PATH) + "\">" + BaseMessages.getString(PKG, "TransStatusServlet.BackToStatusPage") + "</a><p>");
}
}
}
use of org.pentaho.di.core.gui.Point in project pentaho-kettle by pentaho.
the class GetTransImageServlet method generateTransformationImage.
private BufferedImage generateTransformationImage(TransMeta transMeta) throws Exception {
float magnification = 1.0f;
Point maximum = transMeta.getMaximum();
maximum.multiply(magnification);
SwingGC gc = new SwingGC(null, maximum, 32, 0, 0);
TransPainter transPainter = new TransPainter(gc, transMeta, maximum, null, null, null, null, null, new ArrayList<AreaOwner>(), new ArrayList<StepMeta>(), 32, 1, 0, 0, true, "Arial", 10);
transPainter.setMagnification(magnification);
transPainter.buildTransformationImage();
return (BufferedImage) gc.getImage();
}
use of org.pentaho.di.core.gui.Point in project pentaho-kettle by pentaho.
the class Spoon method handleStartOptions.
public void handleStartOptions(CommandLineOption[] options) {
// note that at this point the rep object is populated by previous calls
StringBuilder optionRepname = getCommandLineOption(options, "rep").getArgument();
StringBuilder optionFilename = getCommandLineOption(options, "file").getArgument();
StringBuilder optionDirname = getCommandLineOption(options, "dir").getArgument();
StringBuilder optionTransname = getCommandLineOption(options, "trans").getArgument();
StringBuilder optionJobname = getCommandLineOption(options, "job").getArgument();
try {
// Read kettle transformation specified on command-line?
if (!Utils.isEmpty(optionRepname) || !Utils.isEmpty(optionFilename)) {
if (!Utils.isEmpty(optionRepname)) {
if (rep != null) {
if (Utils.isEmpty(optionDirname)) {
optionDirname = new StringBuilder(RepositoryDirectory.DIRECTORY_SEPARATOR);
}
// Options /file, /job and /trans are mutually
// exclusive
int t = (Utils.isEmpty(optionFilename) ? 0 : 1) + (Utils.isEmpty(optionJobname) ? 0 : 1) + (Utils.isEmpty(optionTransname) ? 0 : 1);
if (t > 1) {
// "More then one mutually exclusive options /file, /job and /trans are specified."
log.logError(BaseMessages.getString(PKG, "Spoon.Log.MutuallyExcusive"));
} else if (t == 1) {
if (!Utils.isEmpty(optionFilename)) {
openFile(optionFilename.toString(), false);
} else {
// OK, if we have a specified job or
// transformation, try to load it...
// If not, keep the repository logged
// in.
RepositoryDirectoryInterface rdi = rep.findDirectory(optionDirname.toString());
if (rdi == null) {
log.logError(BaseMessages.getString(PKG, "Spoon.Log.UnableFindDirectory", optionDirname.toString()));
} else {
if (!Utils.isEmpty(optionTransname)) {
TransMeta transMeta = // reads
rep.loadTransformation(optionTransname.toString(), rdi, null, true, null);
// last
// version
transMeta.clearChanged();
transMeta.setInternalKettleVariables();
addTransGraph(transMeta);
} else {
// Try to load a specified job
// if any
// reads
JobMeta jobMeta = rep.loadJob(optionJobname.toString(), rdi, null, null);
// last
// version
jobMeta.clearChanged();
jobMeta.setInternalKettleVariables();
addJobGraph(jobMeta);
}
}
}
}
} else {
// "No repositories defined on this system."
log.logError(BaseMessages.getString(PKG, "Spoon.Log.NoRepositoriesDefined"));
}
} else if (!Utils.isEmpty(optionFilename)) {
openFile(optionFilename.toString(), false);
}
}
} catch (KettleException ke) {
hideSplash();
log.logError(BaseMessages.getString(PKG, "Spoon.Log.ErrorOccurred") + Const.CR + ke.getMessage());
log.logError(Const.getStackTracker(ke));
// do not just eat the exception
new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.Log.ErrorOccurred"), BaseMessages.getString(PKG, "Spoon.Log.ErrorOccurred") + Const.CR + ke.getMessage(), ke);
rep = null;
}
}
use of org.pentaho.di.core.gui.Point in project pentaho-kettle by pentaho.
the class Spoon method addTabs.
private void addTabs() {
if (tabComp != null) {
tabComp.dispose();
}
tabComp = new Composite(sashform, SWT.BORDER);
props.setLook(tabComp);
tabComp.setLayout(new FillLayout());
tabfolder = new TabSet(tabComp);
tabfolder.setChangedFont(GUIResource.getInstance().getFontBold());
final CTabFolder cTabFolder = tabfolder.getSwtTabset();
props.setLook(cTabFolder, Props.WIDGET_STYLE_TAB);
cTabFolder.addMenuDetectListener(new MenuDetectListener() {
@Override
public void menuDetected(MenuDetectEvent event) {
org.eclipse.swt.graphics.Point real = new org.eclipse.swt.graphics.Point(event.x, event.y);
org.eclipse.swt.graphics.Point point = display.map(null, cTabFolder, real);
final CTabItem item = cTabFolder.getItem(point);
if (item != null) {
Menu menu = new Menu(cTabFolder);
MenuItem closeItem = new MenuItem(menu, SWT.NONE);
closeItem.setText(BaseMessages.getString(PKG, "Spoon.Tab.Close"));
closeItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
int index = tabfolder.getSwtTabset().indexOf(item);
if (index >= 0) {
TabMapEntry entry = delegates.tabs.getTabs().get(index);
tabClose(entry.getTabItem());
}
}
});
MenuItem closeAllItems = new MenuItem(menu, SWT.NONE);
closeAllItems.setText(BaseMessages.getString(PKG, "Spoon.Tab.CloseAll"));
closeAllItems.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
for (TabMapEntry entry : delegates.tabs.getTabs()) {
tabClose(entry.getTabItem());
}
}
});
MenuItem closeOtherItems = new MenuItem(menu, SWT.NONE);
closeOtherItems.setText(BaseMessages.getString(PKG, "Spoon.Tab.CloseOthers"));
closeOtherItems.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
int index = tabfolder.getSwtTabset().indexOf(item);
if (index >= 0) {
TabMapEntry entry = delegates.tabs.getTabs().get(index);
for (TabMapEntry closeEntry : delegates.tabs.getTabs()) {
if (!closeEntry.equals(entry)) {
tabClose(closeEntry.getTabItem());
}
}
}
}
});
menu.setLocation(real);
menu.setVisible(true);
}
}
});
int[] weights = props.getSashWeights();
sashform.setWeights(weights);
sashform.setVisible(true);
// Set a minimum width on the sash so that the view and design buttons
// on the left panel are always visible.
//
Control[] comps = sashform.getChildren();
for (Control comp : comps) {
if (comp instanceof Sash) {
int limit = 10;
final int SASH_LIMIT = Const.isOSX() ? 150 : limit;
final Sash sash = (Sash) comp;
sash.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
Rectangle rect = sash.getParent().getClientArea();
event.x = Math.min(Math.max(event.x, SASH_LIMIT), rect.width - SASH_LIMIT);
if (event.detail != SWT.DRAG) {
sash.setBounds(event.x, event.y, event.width, event.height);
sashform.layout();
}
}
});
}
}
// methods: tabDeselected, tabClose,
tabfolder.addListener(this);
// tabSelected
}
Aggregations