2 import java
.awt
.event
.ActionEvent
;
3 import java
.awt
.event
.ActionListener
;
4 import java
.util
.Observable
;
5 import java
.util
.Observer
;
7 import javax
.swing
.JFrame
;
8 import javax
.swing
.UnsupportedLookAndFeelException
;
10 public class ConsoleController
implements ActionListener
, Observer
{
12 private ConsoleView console_view
;
13 private ConsoleModel console_model
;
14 public String startup_message
= "Enter 1 if you want to set permissions<br/>> Enter 2 if you want to remove permissions:<br/>";
15 public int setting_state
= -1;
17 public ConsoleController(){}
19 private String
[] permission_levels
= {"Organizer","Owner","writer","commenter","reader"};
21 public void initialize(){
23 this.console_view
= new ConsoleView();
24 console_view
.getExitMenu().addActionListener(this);
25 //https://stackoverflow.com/questions/9093448/do-something-when-the-close-button-is-clicked-on-a-jframe
26 console_view
.getFrame().setDefaultCloseOperation(JFrame
.DO_NOTHING_ON_CLOSE
);
27 console_view
.getFrame().addWindowListener(new java
.awt
.event
.WindowAdapter() {
29 public void windowClosing(java
.awt
.event
.WindowEvent windowEvent
) {
30 console_view
.closeDialog();
34 console_view
.getConsoleInput().addActionListener(this);
36 this.console_model
= new ConsoleModel();
37 this.console_model
.attatch(this);
39 this.console_view
.updateConsoleText("Logging into service...");
40 this.console_view
.updateConsoleText(console_model
.loggin());
41 this.console_view
.updateConsoleText(startup_message
);
44 } catch (ClassNotFoundException e
) {
45 // TODO Auto-generated catch block
47 this.console_view
.updateConsoleText("ClassNotFoundException: " + e
.getMessage());
48 } catch (InstantiationException e
) {
49 // TODO Auto-generated catch block
51 this.console_view
.updateConsoleText("InstantiationException: " + e
.getMessage());
52 } catch (IllegalAccessException e
) {
53 // TODO Auto-generated catch block
55 this.console_view
.updateConsoleText("IllegalAccessException: " + e
.getMessage());
56 } catch (UnsupportedLookAndFeelException e
) {
57 // TODO Auto-generated catch block
59 this.console_view
.updateConsoleText("UnsupportedLookAndFeelException: " + e
.getMessage());
64 public void actionPerformed(ActionEvent arg0
) {
65 // TODO Auto-generated method stub
66 if(arg0
.getActionCommand() == "Exit"){
67 console_view
.closeDialog();
70 if(setting_state
== 1){
73 else if(setting_state
== 2){
76 else if (console_view
.getConsoleInput().getText().equals("1")){
77 console_view
.updateConsoleText("Enter ID of the lowest directory you wish to SET permissions for(Root directory ID must be obtained manually for saftey precautions): <br>"
78 + "For example in the URL drive/u/0/folders/1BIsA5ys1YHc7oKY_znJMu8-g2rOjr9p- the ID code "
79 + " 1BIsA5ys1YHc7oKY_znJMu8-g2rOjr9p- is what you will enter:<br/>");
82 else if (console_view
.getConsoleInput().getText().equals("2")){
83 console_view
.updateConsoleText("Enter ID of the lowest directory you wish to REMOVE permissions for(Root directory ID must be obtained manually for saftey precautions): <br>"
84 + "For example in the URL drive/u/0/folders/1BIsA5ys1YHc7oKY_znJMu8-g2rOjr9p- the ID code "
85 + " 1BIsA5ys1YHc7oKY_znJMu8-g2rOjr9p- is what you will enter<br/>"
86 + "Permissions will propogate upwards:<br/>");
90 console_view
.updateConsoleText("err: input - " + console_view
.getConsoleInput().getText() + "<br/>State: " + setting_state
);
93 console_view
.getConsoleInput().setText("");
96 public void setPermissions(){
97 if(console_model
.parent
== null){
98 if(console_view
.getConsoleInput().getText().length() == 0){
99 console_view
.updateConsoleText("This is not a valid ID length<br/>");
102 console_model
.parent
= console_view
.getConsoleInput().getText();
103 console_view
.updateConsoleText("Parent ID: " + console_model
.parent
+ "<br>");
105 console_view
.updateConsoleText("Type in file/folder you wish to change permissions of. Case insensitive");
108 else if(console_model
.folder_to_set
== null){
109 //check if invalid format
110 if(console_view
.getConsoleInput().getText().length() == 0){
111 console_view
.updateConsoleText("Invalid input<br/>");
114 console_model
.folder_to_set
= console_view
.getConsoleInput().getText();
115 console_view
.updateConsoleText("Location: " + console_model
.folder_to_set
+ "<br>");
117 console_view
.updateConsoleText("Set the permission level:"
118 // + "<br> > Organizer,"
119 // + "<br> > Owner, "
120 + "<br> > Enter 1 for Add/Edit"
121 // + "<br> > Commenter, "
122 + "<br> > Enter 2 for View Only <br>");
125 else if(console_model
.role_level
== null){
126 boolean safe
= false;
127 for (String permision
: permission_levels
){
128 if(console_view
.getConsoleInput().getText().equalsIgnoreCase(permision
)){
131 else if(console_view
.getConsoleInput().getText().equalsIgnoreCase("1")){
133 console_view
.getConsoleInput().setText("writer");
135 else if(console_view
.getConsoleInput().getText().equalsIgnoreCase("2")){
137 console_view
.getConsoleInput().setText("reader");
141 console_model
.role_level
= console_view
.getConsoleInput().getText();
142 console_view
.updateConsoleText("Level: " +console_model
.role_level
+ "<br>");
144 console_view
.updateConsoleText("Set who it aplies to:"
145 + "<br> > Enter 1 for User"
146 + "<br> > Enter 2 for Anyone<br>");
149 console_view
.updateConsoleText("Invalid Input<br/>");
152 else if(console_model
.type_of_permission
== null){
153 if(console_view
.getConsoleInput().getText().equalsIgnoreCase("1")){
154 console_model
.type_of_permission
= "user";
155 console_view
.updateConsoleText("Applies: " + console_model
.type_of_permission
+ "<br>");
156 console_view
.updateConsoleText("Enter the email-address of the user to which the permission effects:" + "<br>");
158 else if(console_view
.getConsoleInput().getText().equalsIgnoreCase("2")) {
159 console_model
.type_of_permission
= "anyone";
160 console_view
.updateConsoleText("Applies: " + console_model
.type_of_permission
+ "<br>");
161 console_view
.updateConsoleText("Permissions are being set." + "<br>");
163 //console_view.createLoadDialog();
164 console_view
.updateConsoleText(console_model
.setPermissions());
167 else if(console_model
.email_of_permission
== null){
168 console_model
.email_of_permission
= console_view
.getConsoleInput().getText();
169 console_view
.updateConsoleText("EMail: " +console_model
.email_of_permission
+ "<br>");
171 console_view
.updateConsoleText("Send notification message?"
172 + "<br> > Enter 1 for message"
173 + "<br> > Enter 2 for no message<br>");
176 else if(console_model
.notification_email
== 0){
177 if(console_view
.getConsoleInput().getText().equalsIgnoreCase("1")){
178 console_model
.notification_email
= 1;
179 console_view
.updateConsoleText("What is your message: <br>");
182 else if(console_view
.getConsoleInput().getText().equalsIgnoreCase("2")){
183 console_model
.notification_email
= 2;
184 console_view
.updateConsoleText("No message will be sent. <br>");
186 console_view
.updateConsoleText("Permissions are being set");
187 //console_view.createLoadDialog();
188 console_view
.updateConsoleText(console_model
.setPermissions());
192 console_model
.notification_message
= console_view
.getConsoleInput().getText();
193 console_view
.updateConsoleText("Permissions are being set. <strike>Notification when finished</strike>");
194 //console_view.createLoadDialog();
195 console_view
.updateConsoleText(console_model
.setPermissions());
202 public void clearPermissions(){
203 if(console_model
.parent
== null){
204 if(console_view
.getConsoleInput().getText().length() == 0){
205 console_view
.updateConsoleText("This is not a valid ID length<br/>");
208 console_model
.parent
= console_view
.getConsoleInput().getText();
209 console_view
.updateConsoleText("Parent ID: " + console_model
.parent
+ "<br>");
211 console_view
.updateConsoleText("Type in 1 to delete all permissions under: " + console_model
.parent
);
214 else if(console_view
.getConsoleInput().getText().equals("1")){
215 console_view
.updateConsoleText(console_model
.deletePermissions());
222 public void reinitialize(){
223 console_view
.updateConsoleText(startup_message
);
224 console_model
.email_of_permission
= null;
225 console_model
.role_level
= null;
226 console_model
.type_of_permission
= null;
227 console_model
.folder_to_set
= null;
228 console_model
.parent
= null;
232 public void update(Observable o
, Object arg
) {
233 String
[] args
= (String
[]) arg
;
234 if(((String
)args
[1]) == "c")
235 console_view
.updateConsoleText((String
)args
[0]);
236 if(((String
)args
[1]) == "l")
237 console_view
.setBottomText((String
)args
[0]);
238 if(((String
)args
[1]) == "r"){
239 console_view
.updateConsoleText((String
)args
[0]);