Skip to main content
summaryrefslogtreecommitdiffstats
blob: 08664b669c62ba72c9d9acfcb26496d9ce9bc764 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.ui.skynet.panels;

import static org.eclipse.osee.framework.core.enums.CoreBranches.COMMON;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.osee.framework.core.data.BranchId;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.ui.skynet.ArtifactLabelProvider;
import org.eclipse.osee.framework.ui.skynet.FrameworkImage;
import org.eclipse.osee.framework.ui.skynet.dialogs.ArtifactSelectionDialog;
import org.eclipse.osee.framework.ui.skynet.internal.Activator;
import org.eclipse.osee.framework.ui.swt.ImageManager;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;

/**
 * @author Roberto E. Escobar
 */
public class ArtifactSelectPanel extends AbstractItemSelectPanel<Artifact> {

   private String title;
   private String message;

   public ArtifactSelectPanel() {
      super(new ArtifactLabelProvider(), new ArrayContentProvider());
      this.title = "";
      this.message = "";
   }

   public void setDialogTitle(String title) {
      this.title = title;
   }

   public void setDialogMessage(String message) {
      this.message = message;
   }

   @Override
   protected Dialog createSelectDialog(Shell shell, Artifact lastSelected)  {
      ArtifactSelectionDialog dialog = new ArtifactSelectionDialog(shell);
      dialog.setTitle(title);
      dialog.setMessage(message);
      dialog.setImage(ImageManager.getImage(FrameworkImage.ARTIFACT_EXPLORER));
      dialog.setValidator(new SingleSelectionStatusValidator());
      BranchId branch = lastSelected != null ? lastSelected.getBranch() : COMMON;
      dialog.setInput(branch);
      if (lastSelected != null) {
         dialog.setInitialSelections(new Object[] {lastSelected});
      }
      return dialog;
   }

   @Override
   protected boolean updateFromDialogResult(Dialog dialog) {
      boolean wasUpdated = false;
      ArtifactSelectionDialog castedDialog = (ArtifactSelectionDialog) dialog;
      Artifact artifact = castedDialog.getFirstResult();
      if (artifact != null) {
         setSelected(artifact);
         wasUpdated = true;
      }
      return wasUpdated;
   }

   private final class SingleSelectionStatusValidator implements ISelectionStatusValidator {

      @Override
      public IStatus validate(Object[] selection) {
         IStatus status;
         if (selection == null || selection.length != 1) {
            status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, "Must select 1 item", null);
         } else {
            status = new Status(IStatus.OK, Activator.PLUGIN_ID, 0, "", null);
         }
         return status;
      }
   }
}

Back to the top