Search in sources :

Example 1 with FilterPattern

use of org.eclipse.titan.log.viewer.models.FilterPattern in project titan.EclipsePlug-ins by eclipse.

the class FilterAction method run.

@Override
public void run() {
    if (isFilterRunning) {
        MessageBox msgBox = new MessageBox(textTableView.getSite().getShell());
        msgBox.setMessage("The filter is already running!");
        msgBox.setText("Filter");
        msgBox.open();
        return;
    }
    isFilterRunning = true;
    if (textTableView.getFilterPattern() == null) {
        textTableView.setFilterPattern(new FilterPattern(new TimeInterval("", "", textTableView.getLogFileMetaData().getTimeStampFormat())));
        SortedMap<String, Boolean> eventsToFilter = new TreeMap<String, Boolean>();
        for (Map.Entry<String, String[]> entry : Constants.EVENT_CATEGORIES.entrySet()) {
            eventsToFilter.put(entry.getKey(), true);
        }
        textTableView.getFilterPattern().setEventsToFilter(eventsToFilter, true, false);
    }
    MSCFilterDialog dialog = new MSCFilterDialog(textTableView.getSite().getShell(), textTableView.getFilterPattern());
    if (dialog.open() == 0 && dialog.getChanged() && !dialog.getFilterPattern().equals(textTableView.getFilterPattern())) {
        final FilterPattern tmpFilterPattern = dialog.getFilterPattern();
        WorkspaceJob op = new WorkspaceJob("Filtering") {

            @Override
            public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
                try {
                    textTableView.getFilteredLogReader().runFilter(tmpFilterPattern, monitor);
                } catch (IOException e) {
                    ErrorReporter.logExceptionStackTrace(e);
                    // $NON-NLS-1$
                    TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("TextTableModel.6") + e.getMessage()));
                    monitor.setCanceled(true);
                } catch (ParseException e) {
                    ErrorReporter.logExceptionStackTrace(e);
                    // $NON-NLS-1$
                    TitanLogExceptionHandler.handleException(new TechnicalException(Messages.getString("TextTableModel.7") + e.getMessage()));
                    monitor.setCanceled(true);
                }
                if (monitor.isCanceled()) {
                    monitor.done();
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            isFilterRunning = false;
                            textTableView.getTable().setEnabled(true);
                        }
                    });
                    monitor.done();
                    return Status.CANCEL_STATUS;
                }
                monitor.done();
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        textTableView.setFilterPattern(tmpFilterPattern);
                        textTableView.refreshTable();
                        isFilterRunning = false;
                        textTableView.getTable().setEnabled(true);
                    }
                });
                return Status.OK_STATUS;
            }
        };
        op.setPriority(Job.LONG);
        op.setSystem(false);
        op.setUser(true);
        op.setRule(ResourcesPlugin.getWorkspace().getRoot());
        op.setProperty(IProgressConstants.ICON_PROPERTY, Activator.getImageDescriptor("titan.gif"));
        textTableView.getTable().setEnabled(false);
        op.schedule();
    } else {
        isFilterRunning = false;
    }
}
Also used : TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) TimeInterval(org.eclipse.titan.log.viewer.models.TimeInterval) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IOException(java.io.IOException) TreeMap(java.util.TreeMap) MessageBox(org.eclipse.swt.widgets.MessageBox) MSCFilterDialog(org.eclipse.titan.log.viewer.views.MSCFilterDialog) FilterPattern(org.eclipse.titan.log.viewer.models.FilterPattern) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ParseException(java.text.ParseException) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 2 with FilterPattern

use of org.eclipse.titan.log.viewer.models.FilterPattern in project titan.EclipsePlug-ins by eclipse.

the class SearchPattern method create.

public static SearchPattern create(final IDialogSettings settings) {
    String loadedSearchString = settings.get("searchString");
    boolean loadedIsCaseSensitive = settings.getBoolean("isCaseSensitive");
    boolean loadedIsRegularExpression = settings.getBoolean("isRegularExpression");
    SortedMap<String, Boolean> loadedEvents = new TreeMap<String, Boolean>();
    for (String entry : Constants.EVENT_CATEGORIES.keySet()) {
        loadedEvents.put(entry, settings.getBoolean(entry));
    }
    Map<Field, Boolean> loadedLimitTo = new HashMap<Field, Boolean>();
    loadedLimitTo.put(Field.SOURCE_INFO, settings.getBoolean(Field.SOURCE_INFO.toString()));
    loadedLimitTo.put(Field.MESSAGE, settings.getBoolean(Field.MESSAGE.toString()));
    FilterPattern loadedFilterPattern = new FilterPattern(loadedSearchString, loadedLimitTo, loadedIsCaseSensitive, loadedIsRegularExpression);
    loadedFilterPattern.setEventsToFilter(loadedEvents, true, false);
    // $NON-NLS-1$
    String[] wsIds = settings.getArray("workingSets");
    IWorkingSet[] workingSets = null;
    if (wsIds != null && wsIds.length > 0) {
        IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
        workingSets = new IWorkingSet[wsIds.length];
        for (int i = 0; workingSets != null && i < wsIds.length; i++) {
            workingSets[i] = workingSetManager.getWorkingSet(wsIds[i]);
            if (workingSets[i] == null) {
                workingSets = null;
            }
        }
    }
    return new SearchPattern(loadedFilterPattern, settings.getInt("scope"), workingSets);
}
Also used : HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Field(org.eclipse.titan.log.viewer.models.FilterPattern.Field) FilterPattern(org.eclipse.titan.log.viewer.models.FilterPattern) IWorkingSetManager(org.eclipse.ui.IWorkingSetManager) IWorkingSet(org.eclipse.ui.IWorkingSet)

Aggregations

TreeMap (java.util.TreeMap)2 FilterPattern (org.eclipse.titan.log.viewer.models.FilterPattern)2 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 TechnicalException (org.eclipse.titan.log.viewer.exceptions.TechnicalException)1 Field (org.eclipse.titan.log.viewer.models.FilterPattern.Field)1 TimeInterval (org.eclipse.titan.log.viewer.models.TimeInterval)1 MSCFilterDialog (org.eclipse.titan.log.viewer.views.MSCFilterDialog)1 IWorkingSet (org.eclipse.ui.IWorkingSet)1 IWorkingSetManager (org.eclipse.ui.IWorkingSetManager)1