defProblemAction = new Action()
{
@Override
public void run()
{
InputDialog dialog = new InputDialog( parent.getShell(), Type.PROBLEM,
parent.getDisplay().getCursorLocation() );
dialog.open();
if( dialog.getReturnCode() == Window.OK ) {
// parse problem description and get back the problem context
// String problemContextXML = embetClient.submitProblem( null, dialog.getText(), userID );
getEmbetClient().searchUserContext(userID, dialog.getText());
// System.out.println( "problemContextXML = " + problemContextXML );
// ContextSelectionDialog cDialog = new ContextSelectionDialog( parent.getShell(), ContextSelectionDialog.Type.Problem,new StringReader( problemContextXML ) );
// cDialog.open();
// System.out.println( "Selected = " + cDialog.getSelectedIDs() );
// embetClient.submitUserContext( userID, cDialog.getSelectedIDs() );
try {
Thread.sleep(500);
} catch (InterruptedException e) {}
reloadContent();
}
}
};
defProblemAction.setText( "Define problem" );
defProblemAction.setToolTipText( "Define a problem using free text" );
defProblemAction.setImageDescriptor( ImageDescriptor.createFromImage( defProblemImg ) );
///////////////
// Add knowledge
addKnowledgeAction = new Action()
{
@Override
public void run()
{
InputDialog dialog = new InputDialog( parent.getShell(), Type.NOTE,
parent.getDisplay().getCursorLocation() );
dialog.open();
if( dialog.getReturnCode() == Window.OK ) {
String fileName = dialog.getFileName();
String url = null;
if( fileName != null && fileName.length() > 0 ) {
// vlastne poslanie
File file = new File(fileName);
long fileLen = file.length();
if( fileLen > 1024*1024 ) {
showWarning("Maximum allowed file size is 1 MB.");
return;
}
try {
byte[] content = new byte[(int)fileLen];
FileInputStream fs = new FileInputStream(file);
fs.read(content);
fs.close();
System.out.println( "===== Post =====" );
String repoUrl = preferences.getString(PreferenceConstants.P_REPOSITORY_URL);
if( !repoUrl.endsWith("/") ) repoUrl += "/";
url = RepositoryClientUtility.post( repoUrl, content );
System.out.println( "Returned ID: " + url );
String ext = file.getName().replaceAll( ".+\\.(?=[a-zA-Z0-9]+)", "" ); // extract extension
String schema;
if( ext.toLowerCase().equals( "dispel" ) ) schema = "repo+dispel";
else schema = "repo";
url = schema + "://" + url;
} catch (FileNotFoundException e) {
showWarning("File was not found: " + fileName);
return;
} catch (IOException e) {
showWarning("An error occured during file transfer or registration: " + e.getMessage());
e.printStackTrace();
return;
}
}
else
url = dialog.getURL(); // will be null or empty or contain URL
// parse the note description and get back the note context
String noteContextXML = getEmbetClient().submitNote( null, dialog.getText(), userID, url );
ContextSelectionDialog cDialog = new ContextSelectionDialog( parent.getShell(),
ContextSelectionDialog.Type.Note,
new StringReader( noteContextXML ) );
cDialog.open();