});
filter.setLayoutData(GridDataFactory.fillDefaults().grab(true, false)
.create());
topBar.setLayoutData(GridDataFactory.fillDefaults().grab(true, false)
.create());
final SashForm owner = new SashForm(parent, SWT.VERTICAL);
owner.setLayoutData(GridDataFactory.fillDefaults().grab(true, true)
.create());
Composite c = new Composite(owner, SWT.NONE);
c.setLayout(new FillLayout());
logViewer = new LogViewer(c);
logViewer.configure(new ViewerConfiguration("Message", "",
new LogViewerContentProvider(), new FilterMode[] {}, false,
false, LogViewColumn.getLogColumns()));
logViewer.getTreeViewer().addFilter(new ViewerFilter() {
public boolean select(Viewer viewer, Object parentElement, Object element) {
boolean cm = cm(element);
if (!cm){
if (element instanceof LogItem){
LogItem z=(LogItem) element;
ILogItem[] parts = z.getParts();
for (ILogItem m:parts){
if (cm(m)){
return true;
}
}
}
else{
if (cm(parentElement)){
return true;
}
}
}
return cm;
}
});
final TextConsole console = new TextConsole("console",
"javaStackTraceConsole", null, false) {
public String getType() {
return super.getType();
}
protected IConsoleDocumentPartitioner getPartitioner() {
return new MM(this);
}
};
final TextConsoleViewer sv = new TextConsoleViewer(owner, console);
ConsolePlugin.getDefault().getConsoleManager()
.createPatternMatchListeners(console);
IDocument document = console.getDocument();
document.setDocumentPartitioner(new MM(console));
logViewer.setFilter(new IFilter(){
public boolean accept(Object o) {
return true;
}
public Point match(String text) {
if (filterText!=null&&filterText.length()>0){
int indexOf = text.indexOf(filterText);
if (indexOf!=-1){
return new Point(indexOf,filterText.length());
}
}
return new Point(0,0);
}
});
sv.getTextWidget().setEditable(false);
// sv.setDocument(document);
// sv.getTextWidget().setFont(JFaceResources.getTextFont());
logViewer.getSelectionProvider().addSelectionChangedListener(
new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
if (!event.getSelection().isEmpty()) {
IStructuredSelection sm = (IStructuredSelection) event
.getSelection();
Object firstElement = sm.getFirstElement();
ILogItem item = (ILogItem) firstElement;
sv.getDocument().set(item.getMessage());
Display.getCurrent().asyncExec(new Runnable() {
public void run() {
sv.getTextWidget().redraw();
}
});
}
}
});
owner.setWeights(new int[] { 30, 50 });
IMenuManager menuManager = getViewSite().getActionBars()
.getMenuManager();
menuManager.add(new Action("Settings") {
public void run() {
final Binding bnd=new Binding(LogViewPart.this);
bnd.setAutoCommit(false);
bnd.setReadOnly(false);
Container r=new Container();
IContainerLayoutManager ca=new OneElementOnLineLayouter();
OneLineTextElement<Integer>str=new OneLineTextElement<Integer>(bnd.getBinding("days"));
ComboEnumeratedValueSelector<Integer>sev=new ComboEnumeratedValueSelector<Integer>();
sev.setOrdered(true);
sev.setBinding(bnd.getBinding("minSeverityToFetch"));
r.add(str);
r.add(sev);
Container buttons=new Container();
HorizontalLayouter horizontalLayouter = new HorizontalLayouter();
buttons.setLayoutManager(horizontalLayouter);
r.add(buttons);
final InputElementDialog inputElementDialog = new InputElementDialog(bnd,r,"Settings","you may configure settings here");
ButtonSelector bs=new ButtonSelector();
bs.setValue(new Runnable() {
public void run() {
bnd.commit();
inputElementDialog.close();
}
});
bs.setText("Apply");
buttons.add(bs);
ButtonSelector bs1=new ButtonSelector();
bs1.setValue(new Runnable() {
public void run() {
inputElementDialog.close();
}
});
//buttons.add(bs);
buttons.add(bs1);
bs1.setText("Cancel");
r.setLayoutManager(ca);
DisposeBindingListener.linkBindingLifeCycle(bnd, r);
inputElementDialog.open();
}
});
menuManager.update(true);
IToolBarManager toolBarManager = getViewSite().getActionBars()
.getToolBarManager();
toolBarManager.add(new Action("Export Log") {
{
setImageDescriptor(Activator.imageDescriptorFromPlugin(
Activator.PLUGIN_ID, "/icons/export_log.gif"));
}
public void run() {
FileDialog dlg = new FileDialog(Display.getCurrent()
.getActiveShell(), SWT.SAVE);
dlg.setText("Export log to:");
String open = dlg.open();
if (open != null) {
try {
FileOutputStream s = new FileOutputStream(open);
BufferedWriter bf = new BufferedWriter(
new OutputStreamWriter(s));
try {
bf.append(currentLogs);
bf.close();
} catch (Exception e) {
MessageDialog.openError(Display.getCurrent()
.getActiveShell(), "Error", e.getMessage());
}
} catch (FileNotFoundException e) {
MessageDialog.openError(Display.getCurrent()
.getActiveShell(), "Error", e.getMessage());
}
}
}
});
toolBarManager.add(new Action("Import Log") {
{
setImageDescriptor(Activator.imageDescriptorFromPlugin(
Activator.PLUGIN_ID, "/icons/import_log.gif"));
}
public void run() {
FileDialog dlg = new FileDialog(Display.getCurrent()
.getActiveShell(), SWT.OPEN);
dlg.setText("Open log from");
String open = dlg.open();
if (open != null) {
try {
FileInputStream s = new FileInputStream(open);
BufferedReader bf = new BufferedReader(
new InputStreamReader(s));
StringBuilder bld = new StringBuilder();
;
ArrayList<LogItem> result = new ArrayList<LogItem>();
try {
while (true) {
try {
String str = bf.readLine();
if (str == null) {
break;
}
try {
result.add(new LogItem(str));
} catch (Exception e) {
e.printStackTrace();
}
bld.append(str);
bld.append('\n');
} catch (IOException e) {
MessageDialog.openError(Display
.getCurrent().getActiveShell(),
"Error", e.getMessage());
}
}
logViewer.setInput(result
.toArray(new LogItem[result.size()]));
currentLogs = bld.toString();
} catch (Exception e) {
MessageDialog.openError(Display.getCurrent()
.getActiveShell(), "Error", e.getMessage());
}
} catch (FileNotFoundException e) {
MessageDialog.openError(Display.getCurrent()
.getActiveShell(), "Error", e.getMessage());
}
}
}
});
sync = new Action("Sync with Server") {
{
setImageDescriptor(Activator.imageDescriptorFromPlugin(
Activator.PLUGIN_ID, "/icons/refresh.gif"));
}
public void run() {
refreshLog(currentProject);
}
};
menuManager.add(new Separator());
Action action = new Action("Split horizontally",
IAction.AS_RADIO_BUTTON) {
{
setImageDescriptor(Activator.imageDescriptorFromPlugin(
Activator.PLUGIN_ID, "icons/horizontalOrientation.gif"));
}
public void run() {
owner.setOrientation(SWT.HORIZONTAL);
logViewer.getTreeViewer().getTree().layout(true, true);
}
};
action.setChecked(owner.getOrientation() == SWT.HORIZONTAL);
menuManager.add(action);
menuManager
.add(new Action("Split vertically", IAction.AS_RADIO_BUTTON) {
{
setImageDescriptor(Activator.imageDescriptorFromPlugin(
Activator.PLUGIN_ID,
"icons/verticalOrientation.gif"));
setChecked(owner.getOrientation() == SWT.VERTICAL);
}
public void run() {
owner.setOrientation(SWT.VERTICAL);
logViewer.getTreeViewer().getTree().layout(true, true);
}
});
sync.setEnabled(false);
toolBarManager.add(sync);