Issue #2583 - Procedure dialog fixes and clean up.
Change-Id: I9255d9bb21bc8794aacddffe571e62149dd08c10 Former-commit-id:d6eb7534f5
[formerlyaa0e9121f8
] [formerlyd6eb7534f5
[formerlyaa0e9121f8
] [formerly7ee6053c22
[formerly c88681909d99025be43e5d77dd2a89bbc6e929e2]]] Former-commit-id:7ee6053c22
Former-commit-id:d05d650430
[formerlyf3c8b69e2e
] Former-commit-id:b7d5aa748a
This commit is contained in:
parent
d357b534c4
commit
b95b380eb2
2 changed files with 364 additions and 199 deletions
|
@ -25,7 +25,6 @@ import java.util.HashSet;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jface.viewers.TreeViewer;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import com.raytheon.uf.common.localization.IPathManager;
|
||||
|
@ -37,7 +36,7 @@ import com.raytheon.uf.common.localization.LocalizationUtil;
|
|||
import com.raytheon.uf.common.localization.PathManagerFactory;
|
||||
|
||||
/**
|
||||
* TODO Add Description
|
||||
* This dialog will allow users to open existing procedures.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
|
@ -46,6 +45,8 @@ import com.raytheon.uf.common.localization.PathManagerFactory;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Mar 16, 2011 mschenke Initial creation
|
||||
* 11 Dec 2013 #2583 lvenable Added a check to determine if current user,
|
||||
* all users or all procedures should be requested.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -56,16 +57,18 @@ import com.raytheon.uf.common.localization.PathManagerFactory;
|
|||
public class OpenProcedureListDlg extends ProcedureListDlg {
|
||||
|
||||
/**
|
||||
* @param title
|
||||
* Constructor.
|
||||
*
|
||||
* @param parent
|
||||
* @param mode
|
||||
* Parent shell.
|
||||
*/
|
||||
public OpenProcedureListDlg(Shell parent) {
|
||||
super("Open Procedure", parent, Mode.OPEN);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ProcedureTree populateDataList(TreeViewer treeViewer) {
|
||||
protected ProcedureTree populateDataList() {
|
||||
|
||||
ProcedureTree root = new ProcedureTree("root", null);
|
||||
IPathManager pm = PathManagerFactory.getPathManager();
|
||||
Set<LocalizationContext> searchContexts = new HashSet<LocalizationContext>();
|
||||
|
@ -73,11 +76,22 @@ public class OpenProcedureListDlg extends ProcedureListDlg {
|
|||
searchContexts.addAll(Arrays.asList(pm
|
||||
.getLocalSearchHierarchy(LocalizationType.CAVE_STATIC)));
|
||||
|
||||
// Use of LocalizationLevels.values() in this case should be okay since
|
||||
// we are requesting all possible context names for the level, doesn't
|
||||
// matter if our local context for the level is set
|
||||
// If the show type is not the current user then look at loading the
|
||||
// remaining procedures.
|
||||
if (selectedShowType != ShowType.MINE) {
|
||||
// Use of LocalizationLevels.values() in this case should be okay
|
||||
// since we are requesting all possible context names for the level,
|
||||
// doesn't matter if our local context for the level is set
|
||||
LocalizationLevel[] levels = pm.getAvailableLevels();
|
||||
for (LocalizationLevel level : levels) {
|
||||
|
||||
// If the show type is all users and the localization is USER or
|
||||
// show type is ALL then load the procedure. This will either
|
||||
// load all of the procedures or only the ones at the user
|
||||
// level.
|
||||
if ((selectedShowType == ShowType.ALL_USERS && level == LocalizationLevel.USER)
|
||||
|| selectedShowType == ShowType.ALL) {
|
||||
|
||||
if (level.isSystemLevel() == false) {
|
||||
String[] available = pm.getContextList(level);
|
||||
for (String s : available) {
|
||||
|
@ -88,6 +102,8 @@ public class OpenProcedureListDlg extends ProcedureListDlg {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LocalizationFile[] files = pm.listFiles(searchContexts
|
||||
.toArray(new LocalizationContext[searchContexts.size()]),
|
||||
|
|
|
@ -19,23 +19,18 @@
|
|||
**/
|
||||
package com.raytheon.uf.viz.d2d.ui.dialogs.procedures;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.action.IMenuListener;
|
||||
import org.eclipse.jface.action.IMenuManager;
|
||||
import org.eclipse.jface.action.MenuManager;
|
||||
import org.eclipse.jface.action.Separator;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.viewers.TreeViewer;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.MouseAdapter;
|
||||
import org.eclipse.swt.events.MouseEvent;
|
||||
import org.eclipse.swt.events.MouseListener;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.events.SelectionListener;
|
||||
import org.eclipse.swt.graphics.Cursor;
|
||||
import org.eclipse.swt.graphics.Font;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.layout.RowData;
|
||||
|
@ -43,11 +38,10 @@ import org.eclipse.swt.layout.RowLayout;
|
|||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.swt.widgets.MessageBox;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
import org.eclipse.swt.widgets.TreeItem;
|
||||
import org.eclipse.ui.IWorkbenchActionConstants;
|
||||
|
||||
import com.raytheon.uf.common.localization.IPathManager;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext;
|
||||
|
@ -74,6 +68,12 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
|
|||
* 07/31/2012 DR 15036 D. Friedman Ensure current user's procedures
|
||||
* are visible.
|
||||
* 10/16/2012 1229 rferrel Made dialog non-blocking.
|
||||
* 11 Dec 2013 #2583 lvenable Added show mine, show all users, and show
|
||||
* all radio buttons, fixed a widget disposed
|
||||
* error, cleaned up code to prevent buttons
|
||||
* from magically appearing, removed dead code,
|
||||
* and other code clean up.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author unknown
|
||||
|
@ -81,32 +81,85 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
|
|||
*/
|
||||
public class ProcedureListDlg extends CaveSWTDialog {
|
||||
|
||||
/** Flag indicating the data will only be at the root level. */
|
||||
protected boolean oneLevel = true;
|
||||
|
||||
private Font font;
|
||||
|
||||
/** Text control that contains a selected procedure from the tree viewer. */
|
||||
private Text procedureTF;
|
||||
|
||||
/** Tree that holds the procedure data. */
|
||||
private TreeViewer treeViewer;
|
||||
|
||||
/** OK button. */
|
||||
private Button okBtn;
|
||||
|
||||
/** Cancel button. */
|
||||
private Button cancelBtn;
|
||||
|
||||
private Button frozenBtn;
|
||||
/** Frozen check box. */
|
||||
private Button frozenChk;
|
||||
|
||||
/** Frozen flag. */
|
||||
private boolean frozen = false;
|
||||
|
||||
String fileName;
|
||||
/** Selected filename. */
|
||||
private String fileName;
|
||||
|
||||
private ProcedureTree fileTree = new ProcedureTree(null, null);
|
||||
|
||||
/** Flag indicating if all users should be displayed. */
|
||||
private boolean showAllUsersFlag = false;
|
||||
|
||||
/** Expand button. */
|
||||
private Button expandButton;
|
||||
|
||||
/** Collapse button. */
|
||||
private Button collapseButton;
|
||||
|
||||
/** Show current user procedures. */
|
||||
private Button showMineRdo = null;
|
||||
|
||||
/** Show all user procedures. */
|
||||
private Button showAllUsersRdo = null;
|
||||
|
||||
/** Show all procedures. */
|
||||
private Button showAllProceduresRdo = null;
|
||||
|
||||
/** List of buttons that will be enabled or disabled. */
|
||||
private List<Button> enableBtnArray = new ArrayList<Button>();
|
||||
|
||||
/**
|
||||
* Dialog mode. This determines what functionality the dialog will be able
|
||||
* to do.
|
||||
*/
|
||||
public static enum Mode {
|
||||
SAVE, OPEN, DELETE
|
||||
};
|
||||
|
||||
/**
|
||||
* Enumeration to determine what procedures should be shown.
|
||||
*/
|
||||
public static enum ShowType {
|
||||
MINE, ALL_USERS, ALL
|
||||
};
|
||||
|
||||
protected ShowType selectedShowType = ShowType.MINE;
|
||||
|
||||
/**
|
||||
* Dialog mode.
|
||||
*/
|
||||
private final Mode mode;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param title
|
||||
* Dialog title.
|
||||
* @param parent
|
||||
* Parent shell.
|
||||
* @param mode
|
||||
* Mode of the dialog.
|
||||
*/
|
||||
public ProcedureListDlg(String title, Shell parent, Mode mode) {
|
||||
super(parent, SWT.DIALOG_TRIM | SWT.RESIZE, CAVE.DO_NOT_BLOCK); // Win32
|
||||
setText(title);
|
||||
|
@ -115,133 +168,226 @@ public class ProcedureListDlg extends CaveSWTDialog {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void disposed() {
|
||||
font.dispose();
|
||||
protected void opened() {
|
||||
// Set the minimum size on the dialog so that it cannot be resized to
|
||||
// hide the controls.
|
||||
shell.setMinimumSize(shell.getBounds().width, shell.getBounds().height);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initializeComponents(Shell shell) {
|
||||
font = new Font(shell.getDisplay(), "Courier", 11, SWT.BOLD);
|
||||
|
||||
Composite mainComp = new Composite(shell, SWT.NONE);
|
||||
mainComp.setLayout(new GridLayout(2, false));
|
||||
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
|
||||
gd.widthHint = 400;
|
||||
mainComp.setLayoutData(gd);
|
||||
|
||||
createTextComp(mainComp);
|
||||
createButtonComp(mainComp);
|
||||
}
|
||||
|
||||
protected void createExpandComp(Composite parent) {
|
||||
/**
|
||||
* Create a composite with the Expand and Collapse buttons.
|
||||
*
|
||||
* @param parent
|
||||
* Parent composite.
|
||||
*/
|
||||
private void createExpandComp(Composite parent) {
|
||||
|
||||
Composite expandComp = new Composite(parent, SWT.NONE);
|
||||
expandComp.setLayout(new RowLayout(SWT.HORIZONTAL));
|
||||
GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false);
|
||||
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
|
||||
gd.widthHint = 25;
|
||||
expandComp.setLayoutData(gd);
|
||||
|
||||
if (this.mode == Mode.DELETE) {
|
||||
gd.exclude = true;
|
||||
}
|
||||
|
||||
RowData rd = new RowData();
|
||||
Button expandButton = new Button(expandComp, SWT.PUSH);
|
||||
expandButton = new Button(expandComp, SWT.PUSH);
|
||||
expandButton.setText("Expand All");
|
||||
expandButton.setLayoutData(rd);
|
||||
enableBtnArray.add(expandButton);
|
||||
expandButton.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent event) {
|
||||
expandAll();
|
||||
treeViewer.expandAll();
|
||||
}
|
||||
});
|
||||
|
||||
rd = new RowData();
|
||||
Button collapseButton = new Button(expandComp, SWT.PUSH);
|
||||
collapseButton = new Button(expandComp, SWT.PUSH);
|
||||
collapseButton.setText("Collapse All");
|
||||
collapseButton.setLayoutData(rd);
|
||||
enableBtnArray.add(collapseButton);
|
||||
collapseButton.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent event) {
|
||||
collapseAll();
|
||||
treeViewer.collapseAll();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void expandAll() {
|
||||
treeViewer.expandAll();
|
||||
}
|
||||
|
||||
private void collapseAll() {
|
||||
treeViewer.collapseAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the text and tree viewer controls.
|
||||
*
|
||||
* @param mainComp
|
||||
* Parent composite.
|
||||
*/
|
||||
protected void createTextComp(Composite mainComp) {
|
||||
final Cursor cursor = getShell().getCursor();
|
||||
getShell().setCursor(
|
||||
Display.getCurrent().getSystemCursor(SWT.CURSOR_WAIT));
|
||||
final Composite textComp = new Composite(mainComp, SWT.NONE);
|
||||
textComp.setLayout(new GridLayout(1, true));
|
||||
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
|
||||
gd.widthHint = 150;
|
||||
textComp.setLayoutData(gd);
|
||||
|
||||
/*
|
||||
* Add a text control to the dialog if it isn't in delete mode.
|
||||
*/
|
||||
if (this.mode != Mode.DELETE) {
|
||||
procedureTF = new Text(textComp, SWT.BORDER);
|
||||
gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
|
||||
gd.widthHint = 150;
|
||||
if (this.mode == Mode.DELETE) {
|
||||
gd.exclude = true;
|
||||
}
|
||||
// gd.widthHint = 150;
|
||||
procedureTF.setLayoutData(gd);
|
||||
|
||||
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
|
||||
gd.widthHint = 250;
|
||||
gd.heightHint = 175;
|
||||
treeViewer = new TreeViewer(textComp, SWT.SINGLE | SWT.BORDER
|
||||
| SWT.FILL);
|
||||
treeViewer.getTree().setLayoutData(gd);
|
||||
treeViewer.getTree().addSelectionListener(new SelectionListener() {
|
||||
|
||||
@Override
|
||||
public void widgetDefaultSelected(SelectionEvent arg0) {
|
||||
|
||||
/*
|
||||
* If this is the open dialog, make the text control uneditable. The
|
||||
* reason for this is that currently this dialog doesn't do anything
|
||||
* with the text that the user could enter into the box. In AWIPS I,
|
||||
* entering in a name that doesn't exist will bring up the
|
||||
* procedures dialog with the entered name but no products. In AWIPS
|
||||
* II, the dialog just closes. Until this gets addressed the text
|
||||
* control should be uneditable.
|
||||
*/
|
||||
if (this.mode == Mode.OPEN) {
|
||||
procedureTF.setEditable(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.mode == Mode.OPEN) {
|
||||
|
||||
Composite showComp = new Composite(textComp, SWT.NONE);
|
||||
showComp.setLayout(new GridLayout(3, false));
|
||||
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
|
||||
showComp.setLayoutData(gd);
|
||||
|
||||
showMineRdo = new Button(showComp, SWT.RADIO);
|
||||
showMineRdo.setText("Show Mine");
|
||||
showMineRdo.setSelection(true);
|
||||
enableBtnArray.add(showMineRdo);
|
||||
showMineRdo.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
if (showMineRdo.getSelection()
|
||||
&& selectedShowType != ShowType.MINE) {
|
||||
showProcedureAction(ShowType.MINE);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
gd = new GridData();
|
||||
gd.horizontalIndent = 10;
|
||||
showAllUsersRdo = new Button(showComp, SWT.RADIO);
|
||||
showAllUsersRdo.setText("Show All Users");
|
||||
showAllUsersRdo.setLayoutData(gd);
|
||||
enableBtnArray.add(showAllUsersRdo);
|
||||
showAllUsersRdo.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
if (showAllUsersRdo.getSelection()
|
||||
&& selectedShowType != ShowType.ALL_USERS) {
|
||||
showProcedureAction(ShowType.ALL_USERS);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
gd = new GridData();
|
||||
gd.horizontalIndent = 10;
|
||||
showAllProceduresRdo = new Button(showComp, SWT.RADIO);
|
||||
showAllProceduresRdo.setText("Show All");
|
||||
showAllProceduresRdo.setLayoutData(gd);
|
||||
enableBtnArray.add(showAllProceduresRdo);
|
||||
showAllProceduresRdo.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
if (showAllProceduresRdo.getSelection()
|
||||
&& selectedShowType != ShowType.ALL) {
|
||||
showProcedureAction(ShowType.ALL);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
|
||||
gd.widthHint = 325;
|
||||
gd.heightHint = 170;
|
||||
|
||||
treeViewer = new TreeViewer(textComp, SWT.SINGLE | SWT.BORDER);
|
||||
treeViewer.getTree().setLayoutData(gd);
|
||||
treeViewer.getTree().addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent arg0) {
|
||||
if (!treeViewer.getTree().isDisposed()
|
||||
&& treeViewer.getTree().getSelection().length > 0) {
|
||||
procedureTF.setText(treeViewer.getTree().getSelection()[0]
|
||||
if (procedureTF != null && !procedureTF.isDisposed()) {
|
||||
procedureTF
|
||||
.setText(treeViewer.getTree().getSelection()[0]
|
||||
.getText());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
treeViewer.getTree().addMouseListener(new MouseListener() {
|
||||
@Override
|
||||
public void mouseUp(MouseEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDown(MouseEvent e) {
|
||||
}
|
||||
|
||||
treeViewer.getTree().addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseDoubleClick(MouseEvent e) {
|
||||
selectAction(true);
|
||||
// Check to see if the selected item has child nodes. If it
|
||||
// doesn't then call selectAction.
|
||||
if (!checkSelectionToggle(getSelectedTreeItem())) {
|
||||
selectAction();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
updateTreeViewerData();
|
||||
|
||||
// If not in delete mode then add the expand/collapse controls.
|
||||
if (this.mode != Mode.DELETE) {
|
||||
createExpandComp(textComp);
|
||||
}
|
||||
}
|
||||
|
||||
private void showProcedureAction(ShowType showType) {
|
||||
this.selectedShowType = showType;
|
||||
|
||||
treeViewer.getTree().removeAll();
|
||||
treeViewer.getTree().clearAll(true);
|
||||
procedureTF.setText("");
|
||||
updateTreeViewerData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the tree viewer with data.
|
||||
*/
|
||||
private void updateTreeViewerData() {
|
||||
|
||||
// Set the cursor to a wait cursor. Also set the main composite to not
|
||||
// be editable while the data is being retrieved.
|
||||
getShell().setCursor(
|
||||
Display.getCurrent().getSystemCursor(SWT.CURSOR_WAIT));
|
||||
enableControls(false);
|
||||
|
||||
Job job = new Job("Populating procedures...") {
|
||||
protected org.eclipse.core.runtime.IStatus run(
|
||||
org.eclipse.core.runtime.IProgressMonitor monitor) {
|
||||
fileTree = populateDataList(treeViewer);
|
||||
fileTree = populateDataList();
|
||||
VizApp.runAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
// If the treeViewer is null or has been disposed then
|
||||
// return as the dialog has been shutdown.
|
||||
if (treeViewer == null
|
||||
|| treeViewer.getTree().isDisposed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
treeViewer
|
||||
.setContentProvider(new ProcedureTreeContentProvider(
|
||||
fileTree));
|
||||
|
@ -249,21 +395,16 @@ public class ProcedureListDlg extends CaveSWTDialog {
|
|||
.setLabelProvider(new ProcedureTreeLabelProvider());
|
||||
treeViewer.setSorter(new ProcedureTreeSorter());
|
||||
|
||||
// uncomment following function call to enable the right
|
||||
// click
|
||||
// context
|
||||
// menu
|
||||
// createContextMenu();
|
||||
|
||||
// it didn't seem to start with null, the string doesn't
|
||||
// actually mean
|
||||
// anything in this case
|
||||
// actually mean anything in this case
|
||||
treeViewer.setInput("kickstart");
|
||||
|
||||
openUserInTreeViewer();
|
||||
|
||||
createExpandComp(textComp);
|
||||
getShell().setCursor(cursor);
|
||||
// Set the cursor to a normal cursor. Also, reenable the
|
||||
// main composite to be editable.
|
||||
enableControls(true);
|
||||
getShell().setCursor(null);
|
||||
}
|
||||
});
|
||||
return Status.OK_STATUS;
|
||||
|
@ -272,85 +413,23 @@ public class ProcedureListDlg extends CaveSWTDialog {
|
|||
job.schedule();
|
||||
}
|
||||
|
||||
private void createContextMenu() {
|
||||
MenuManager menuMgr = new MenuManager();
|
||||
menuMgr.setRemoveAllWhenShown(true);
|
||||
menuMgr.addMenuListener(new IMenuListener() {
|
||||
public void menuAboutToShow(IMenuManager mgr) {
|
||||
fillContextMenu(mgr);
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Enable or disable controls based on the flag passed in.
|
||||
*
|
||||
* @param enableFlag
|
||||
* True to enable controls, false to disable.
|
||||
*/
|
||||
private void enableControls(boolean enableFlag) {
|
||||
|
||||
Menu menu = menuMgr.createContextMenu(treeViewer.getControl());
|
||||
treeViewer.getControl().setMenu(menu);
|
||||
for (Button btn : enableBtnArray) {
|
||||
if (btn != null && !btn.isDisposed()) {
|
||||
btn.setEnabled(enableFlag);
|
||||
}
|
||||
|
||||
protected void fillContextMenu(IMenuManager mgr) {
|
||||
if (treeViewer.getSelection().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
final Object tmp = treeViewer.getTree().getSelection()[0].getData();
|
||||
if (tmp instanceof ProcedureTree) {
|
||||
ProcedureTree sel = (ProcedureTree) tmp;
|
||||
|
||||
// if there is a valid file add load option
|
||||
if (sel.getFile() != null) {
|
||||
String text = "";
|
||||
if (this.mode == ProcedureListDlg.Mode.DELETE) {
|
||||
text = "Delete this";
|
||||
} else if (this.mode == ProcedureListDlg.Mode.OPEN) {
|
||||
text = "Open this";
|
||||
} else if (this.mode == ProcedureListDlg.Mode.SAVE) {
|
||||
text = "Save as this";
|
||||
} else {
|
||||
text = "Action";
|
||||
}
|
||||
mgr.add(new Action(text) {
|
||||
public void run() {
|
||||
selectAction(false);
|
||||
}
|
||||
});
|
||||
|
||||
// add separator
|
||||
mgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
|
||||
} else {
|
||||
// add expand this option
|
||||
String text = "";
|
||||
final boolean state = treeViewer.getExpandedState(tmp);
|
||||
if (state) {
|
||||
text = "Collapse";
|
||||
} else {
|
||||
text = "Expand";
|
||||
}
|
||||
|
||||
mgr.add(new Action(text) {
|
||||
public void run() {
|
||||
treeViewer.setExpandedState(tmp, !state);
|
||||
}
|
||||
});
|
||||
|
||||
// add separator
|
||||
mgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
|
||||
}
|
||||
|
||||
// add expand/collapse options
|
||||
mgr.add(new Action("Expand All") {
|
||||
public void run() {
|
||||
expandAll();
|
||||
}
|
||||
});
|
||||
mgr.add(new Action("Collapse All") {
|
||||
public void run() {
|
||||
collapseAll();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected void openUserInTreeViewer() {
|
||||
if (this.oneLevel) {
|
||||
// do nothing for single level
|
||||
} else {
|
||||
private void openUserInTreeViewer() {
|
||||
if (!oneLevel) {
|
||||
IPathManager mgr = PathManagerFactory.getPathManager();
|
||||
LocalizationContext ctx = mgr.getContext(
|
||||
LocalizationType.CAVE_STATIC, LocalizationLevel.USER);
|
||||
|
@ -381,14 +460,13 @@ public class ProcedureListDlg extends CaveSWTDialog {
|
|||
/**
|
||||
* populate the data list
|
||||
*/
|
||||
protected ProcedureTree populateDataList(TreeViewer treeViewer) {
|
||||
protected ProcedureTree populateDataList() {
|
||||
ProcedureTree root = new ProcedureTree("root", null);
|
||||
IPathManager mgr = PathManagerFactory.getPathManager();
|
||||
LocalizationContext ctx = mgr.getContext(LocalizationType.CAVE_STATIC,
|
||||
LocalizationLevel.USER);
|
||||
LocalizationFile[] files = mgr.listFiles(ctx,
|
||||
ProcedureDlg.PROCEDURES_DIR, null, true, true);
|
||||
|
||||
String[] strings = new String[files.length];
|
||||
for (int i = 0; i < strings.length; i++) {
|
||||
strings[i] = LocalizationUtil.extractName(files[i].getName());
|
||||
|
@ -399,7 +477,10 @@ public class ProcedureListDlg extends CaveSWTDialog {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create the OK and Cancel buttons.
|
||||
*
|
||||
* @param mainComp
|
||||
* Parent composite.
|
||||
*/
|
||||
private void createButtonComp(Composite mainComp) {
|
||||
// Add buttom comp
|
||||
|
@ -413,10 +494,11 @@ public class ProcedureListDlg extends CaveSWTDialog {
|
|||
okBtn = new Button(buttonComp, SWT.PUSH);
|
||||
okBtn.setText("Ok");
|
||||
okBtn.setLayoutData(rd);
|
||||
enableBtnArray.add(okBtn);
|
||||
okBtn.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent event) {
|
||||
selectAction(false);
|
||||
selectAction();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -433,11 +515,11 @@ public class ProcedureListDlg extends CaveSWTDialog {
|
|||
|
||||
if (mode == Mode.SAVE) {
|
||||
rd = new RowData(100, SWT.DEFAULT);
|
||||
frozenBtn = new Button(buttonComp, SWT.CHECK);
|
||||
frozenBtn.setText("Freeze time");
|
||||
frozenBtn.setLayoutData(rd);
|
||||
frozenBtn.setSelection(frozen);
|
||||
frozenBtn.addSelectionListener(new SelectionAdapter() {
|
||||
frozenChk = new Button(buttonComp, SWT.CHECK);
|
||||
frozenChk.setText("Freeze time");
|
||||
frozenChk.setLayoutData(rd);
|
||||
frozenChk.setSelection(frozen);
|
||||
frozenChk.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
frozen = !frozen;
|
||||
|
@ -453,38 +535,62 @@ public class ProcedureListDlg extends CaveSWTDialog {
|
|||
return fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method call to determine if frozen is selected.
|
||||
*
|
||||
* @return True if frozen, false otherwise.
|
||||
*/
|
||||
public boolean isFrozen() {
|
||||
return frozen;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns true if the item was toggled, toggles if the item has children
|
||||
* returns true if the item was toggled, toggles (expands/collapses ) if the
|
||||
* item has children
|
||||
*
|
||||
* @param obj
|
||||
* @return
|
||||
* basically this method check to see if the node in the tree has children.
|
||||
* if the node has children it will expand the tree to show the children.
|
||||
*
|
||||
* @param procedureTree
|
||||
* The procedure tree.
|
||||
* @return True if there are children of the selection.
|
||||
*/
|
||||
private boolean checkSelectionToggle(Object obj) {
|
||||
if (obj instanceof ProcedureTree) {
|
||||
ProcedureTree item = (ProcedureTree) obj;
|
||||
if (item.hasChildren()) {
|
||||
private boolean checkSelectionToggle(ProcedureTree procedureTree) {
|
||||
|
||||
if (procedureTree.hasChildren()) {
|
||||
// toggle and return true
|
||||
boolean expanded = treeViewer.getExpandedState(obj);
|
||||
treeViewer.setExpandedState(obj, !expanded);
|
||||
boolean expanded = treeViewer.getExpandedState(procedureTree);
|
||||
treeViewer.setExpandedState(procedureTree, !expanded);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void selectAction(boolean fromDblClick) {
|
||||
/**
|
||||
* Get the procedure tree object from the selected item in the tree viewer.
|
||||
*
|
||||
* @return The procedure tree.
|
||||
*/
|
||||
private ProcedureTree getSelectedTreeItem() {
|
||||
Object tmp = null;
|
||||
if (!treeViewer.getSelection().isEmpty()) {
|
||||
tmp = treeViewer.getTree().getSelection()[0].getData();
|
||||
}
|
||||
if (fromDblClick && checkSelectionToggle(tmp)) {
|
||||
return;
|
||||
|
||||
if (tmp instanceof ProcedureTree) {
|
||||
return (ProcedureTree) tmp;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Action method that determines what mode the dialog is in. Action from the
|
||||
* OK button or double-clicking the item in the tree viewer.
|
||||
*/
|
||||
private void selectAction() {
|
||||
|
||||
if (mode == Mode.SAVE) {
|
||||
if (procedureTF.getText() == null)
|
||||
return;
|
||||
|
@ -520,12 +626,22 @@ public class ProcedureListDlg extends CaveSWTDialog {
|
|||
}
|
||||
} else if (mode == Mode.OPEN) {
|
||||
fileName = procedureTF.getText();
|
||||
if (tmp instanceof ProcedureTree) {
|
||||
ProcedureTree tmp = getSelectedTreeItem();
|
||||
if (tmp != null) {
|
||||
// it must be a procedure tree, that is what the content
|
||||
// provider uses internally
|
||||
LocalizationFile selectedFile = ((ProcedureTree) tmp).getFile();
|
||||
setReturnValue(selectedFile);
|
||||
|
||||
if (selectedFile == null) {
|
||||
displayOpenErrorDialog();
|
||||
return;
|
||||
}
|
||||
setReturnValue(selectedFile);
|
||||
} else {
|
||||
displayOpenErrorDialog();
|
||||
return;
|
||||
}
|
||||
|
||||
close();
|
||||
} else if (mode == Mode.DELETE) {
|
||||
|
||||
|
@ -537,7 +653,8 @@ public class ProcedureListDlg extends CaveSWTDialog {
|
|||
+ selection[0].getText() + "\"");
|
||||
if (result == true) {
|
||||
fileName = selection[0].getText();
|
||||
if (tmp instanceof ProcedureTree) {
|
||||
ProcedureTree tmp = getSelectedTreeItem();
|
||||
if (tmp != null) {
|
||||
// it must be a procedure tree, that is what the content
|
||||
// provider uses internally
|
||||
LocalizationFile selectedFile = ((ProcedureTree) tmp)
|
||||
|
@ -546,10 +663,33 @@ public class ProcedureListDlg extends CaveSWTDialog {
|
|||
}
|
||||
close();
|
||||
}
|
||||
} else {
|
||||
MessageBox mb = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
|
||||
mb.setText("Selection Error");
|
||||
mb.setMessage("You must select an item to delete it.");
|
||||
mb.open();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a dialog letting the user know they have to select a file to open
|
||||
* it.
|
||||
*/
|
||||
private void displayOpenErrorDialog() {
|
||||
MessageBox mb = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
|
||||
mb.setText("Selection Error");
|
||||
mb.setMessage("You must select a file to open it.");
|
||||
mb.open();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the data list contains the specified filename.
|
||||
*
|
||||
* @param fileName
|
||||
* Filename.
|
||||
* @return True if the data list contains the filename, false otherwise.
|
||||
*/
|
||||
private boolean dataListContains(String fileName) {
|
||||
TreeItem[] items = treeViewer.getTree().getItems();
|
||||
for (TreeItem item : items) {
|
||||
|
@ -559,4 +699,13 @@ public class ProcedureListDlg extends CaveSWTDialog {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method call to determine if all users should be shown.
|
||||
*
|
||||
* @return True if all users should be shown, false otherwise.
|
||||
*/
|
||||
protected boolean showAllUsers() {
|
||||
return showAllUsersFlag;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue